How can openlayers 3 be told to use and work with a custom SRS-definition which has no EPSG-code?
May i don't understand it but it seems like ol3 needs an EPSG- or ESRI-code
to work.
I found some examples about how to use WKT- and proj4- definitions unsing Prof4js.defs, but it didn't work for me:
Proj4: https://stackoverflow.com/questions/29027295/how-to-use-openlayers-3-with-proj4js
OpenLayers 3 transform coordinates to custom projection
https://stackoverflow.com/questions/29302770/parsing-projection-wkt-in-openlayers-3
I had several errors caused by the line with the definition (proj4.defs
) saying the projection is undefined. I used a WKT and a proj4 declaration in there – both were creating the same Error.
I have a WKT- and a simple proj4-definition for the needed reference body, but i don't understand how to combine it to make it work in ol3.
The simplified js I use:
var baseLayers = new ol.layer.Group({
title: 'Base Layers',
openInLayerSwitcher: true,
layers:
[ new ol.layer.Tile({
title: "testLayer1",
baseLayer: true,
source: new ol.source.OSM({
url: 'tiled_layer1/{z}/{x}/{-y}.png'
})
}),
new ol.layer.Tile({
title: "mos_final_14_02_13.map",
baseLayer: true,
visible: false,
source: new ol.source.OSM({
url: 'tiled_layer2/{z}/{x}/{-y}.png'
})
})
]
});
var overlays = new ol.layer.Group({
title: 'moasaic single frames',
openInLayerSwitcher: true,
layers:
[ new ol.layer.Tile({
title: "overlay1",
baseLayer: false,
source: new ol.source.OSM({
url: 'tiled_overlay/{z}/{x}/{-y}.png'
})
}),
new ol.layer.Tile({
title: "overlay2,
baseLayer: false,
visible: false,
source: new ol.source.OSM({
url: 'tiled_overlay2/{z}/{x}/{-y}.png'
})
})
]
});
var map = new ol.Map({
target: 'map',
view: new ol.View({
center: ol.proj.transform([0, 0], 'EPSG:4326', 'EPSG:3857'),
zoom: 3,
minZoom: 0,
maxZoom: 9
}),
controls: ol.control.defaults().extend([
new ol.control.LayerSwitcher()
]),
layers: [baseLayers, overlays]
});
OpenLayers 3 Examples showing this: http://openlayers.org/en/v3.3.0/examples/wms-image-custom-proj.html
They use a JS-file telling the Definition for the Projection – but i didn't find the place where they use it – its just standing in thier souce-code.
Best Answer
They use it in this file http://openlayers.org/en/v3.3.0/examples/wms-image-custom-proj.js
You have to add your custom projection
proj4.defs("EPSG:21781","+proj=somerc +lat_0=46.95240555555556 +lon_0=7.439583333333333 +k_0=1 +x_0=600000 +y_0=200000 +ellps=bessel +towgs84=660.077,13.551,369.344,2.484,1.783,2.939,5.66 +units=m +no_defs");
Then use it for your view, as in wms-image-custom-proj.js