I'm using OpenLayers 3 to view a WMS layer from a server in EPSG:3006, see the code:
Proj4js:
Proj4js.defs["EPSG:3006"] = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";
ol.js:
var map;
var projection = ol.proj.get('EPSG:3006');
function init(){
map = new ol.Map({
target:'map',
renderer:'canvas',
view: new ol.View({
projection: projection,
center:[617000,6728500],
zoom:3
})
});
var topolayer = new ol.layer.Image({
source: new ol.source.ImageWMS({
preload: Infinity,
url: 'URLgoesHere',
params:{
'LAYERS':"layernameGoesHere"
}
})
});
map.addLayer(topolayer);
The result is a map centered over Sweden/Denmark, but it should result in a map centered over middle part of Sweden. I also added a button which calls a function to print the current extent of the ol.View (got help from a friend with this function, believe its from this post https://stackoverflow.com/questions/28166471/openlayer3-how-to-get-coordinates-of-viewport):
function extentCoords() {
var x=map.getView().calculateExtent(map.getSize());
alert(x);
}
For now it is in an alert() call just for experimenting and troubleshooting. When this function is called it returns values that are far away or totally wrong from the actual boundaries of the projection, for example when zoomed in over a small city in the mid part of Sweden it returns the following extent:
1905097,691, 8549623.590, 1910591.602, 8554759.203
The result should have X-values in the six figure range, rather than the seven figure range like now. The returned Y-values are in the seven figure range as expected, but not within the right values.
Also when changing the Center value, the map doesn't react to the new values.
The reason to why I need to extract these coordinates is because they are used to call a WCS through another function and download data within the same area/extent.
Is there something that I'm missing when using this custom projection, something needed to be transformed or maybe added in the ol.View part? Something wrong with the extent-function?
Sidenote: I'm kind of new to using OpenLayers, especially with WMS layers and custom projections. Also, I've got no control over the server as it is not mine.
Best Answer
You should leave your map in the default google coordinate EPSG: 3857 :
And param your WMS tile with its correct projection
That should work !