Openlayers 3 WMS custom projection wrong extent

Openlayers 3 WMS custom projection wrong extent

I'm using OpenLayers 3 to view a WMS layer from a server in EPSG:3006, see the code:


Proj4js.defs["EPSG:3006"] = "+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";


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

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.

You should leave your map in the default google coordinate EPSG: 3857 :

map = new ol.Map({ loadTilesWhileAnimating: true, // adds default controls controls: ol.control.defaults().extend([ //adds a scalebar new ol.control.ScaleLine({ // units: ol.control.ScaleLineUnits.METRIC }), new ol.control.ZoomSlider({ }) ]), //rendering params target: dom_id, //Ext.get(idDiv), layers: baseLayers, renderer: 'canvas', view: new ol.View({ projection: ol.proj.get('EPSG:3857'), }) });

And param your WMS tile with its correct projection

// Aerial Tile Layer var aerialLayer = new ol.layer.Tile({ title: "Aerial", source: new ol.source.TileWMS({ url: 'http://server01:8080/geoserver/sf/wms', params: { 'LAYERS': 'sf:TEST01', 'STYLES':"}, serverType: 'geoserver', projection: ol.proj.get('EPSG:3006'), }) });

That should work !

From what I have learnt EPSG:3006 (SWEREF99 TM) has axis order north, east. That means that you need to have a recent proj4js - I have used:

And you need to specify+axis=neuin your proj.4 definition:

proj4.defs('EPSG:3006', '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +axis=neu +no_defs'); does for some reason not include+axis=neu, so you can not use

to get the definition.

For some reason, you have to use axis order east, north for the ol.viewcentercoordinates (as you have done).

center: [617000, 6728500],

Using this setup, and a Norwegian WMS service that support 3006, the centre of the map ended up in Gävle, Sweden.

Watch the video: Create Maps with Vector Tiles. OpenLayers. Mapbox GL JS