Openlayers with proj4.js and custom Projection
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.3/proj4.js "></script>
Openlayers with proj4.js and custom Projection
<div id="map"></div>
Mark to myself:
SCHROTT / LOESCHEN
CRAP // DELETE jsfiddle
CSS
#map
{
width:500px;
height: 500px;
}
JavaScript
window.Proj4js = {
Proj: function(code) {
return proj4(Proj4js.defs[code]);
},
defs: proj4.defs,
transform: proj4
};
// Definition comes from http://epsg.io/31466/
proj4.defs["EPSG:31466"] = "+proj=tmerc +lat_0=0 +lon_0=6 +k=1 +x_0=2500000 +y_0=0 +ellps=bessel +towgs84=598.1,73.7,418.2,0.202,0.045,-2.455,6.7 +units=m +no_defs";
console.log(Proj4js.defs["EPSG:31466"]);
var proj_wgs84 = new OpenLayers.Projection("EPSG:4326");
var projection = new OpenLayers.Projection("EPSG:31466");
// Center for projection EPSG:31466
var point = new OpenLayers.LonLat(2769212.70, 5678724.61);
var new_point= point.transform(projection, proj_wgs84);
console.log(new_point.lat, new_point.lon);
var bounds = new OpenLayers.Bounds(
370753.1145, 6382922.7769, 739245.6000, 6624811.0577
);
var options = {
maxExtent: bounds,
maxResolution: 2601.4538070271437,
projection:projection,
units: 'm'
};
map = new OpenLayers.Map('map', options);
var base = new OpenLayers.Layer.WMS("Regierungsbezirk",
"http://sg.geodatenzentrum.de/wms_dgm200?",{layers: 'DGM200',
version: '1.3.0', srs:projection});
map.addLayer(base);
map.setCenter(point,2);