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({
        view: new ol.View({
            projection: projection,

var topolayer = new ol.layer.Image({
    source: new ol.source.ImageWMS({
        preload: Infinity,
        url: 'URLgoesHere',


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());

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.

  • Please try with Proj4JS v2.2+ and with the following definition: proj4.defs('EPSG:3006', '+proj=utm +zone=33 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); Commented Apr 24, 2015 at 12:24
  • Thank you, but are already using the latest version of Proj4js and said definition.
    – benkftw
    Commented Apr 27, 2015 at 7:59

2 Answers 2


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 !

  • Thanks for your suggestion. Now the map looks like expected, but are zoomed out and looks a bit different. But when zooming in to the next zoom-level using the OL zoom buttons the map disappears upon loading. Also tried to change the projection for the ol.map to 3006, with the same result. Both times im also getting rather odd coordinates for the viewport upon calling the function. Do I need to make some transformations in the function for viewport coordinates? Are there something missing in the setup of ol.view like resolution, zoom-levels etc?
    – benkftw
    Commented Apr 27, 2015 at 8:14
  • What do you call odd coordinates?! The map that disappears could be because you've indicated a max/min Extent level? Do you have a screen shot of your problem? =) Commented Apr 27, 2015 at 8:37
  • With odd I meant like described in the original question, they are way off for the EPSG:3006 boundaries. But now, after some more testing and tweaking, the map shows up in the expected projection and the problem with disappering map on next zoom-level is gone. Though the coordinates are still off, see image imgur.com/hgk8KTQ and the area that is actually showing: imgur.com/sNs5kUn
    – benkftw
    Commented Apr 27, 2015 at 10:29
  • So in short, everything is fine, except for the bounding box/extent of the viewport that are returning coordinates in, what i guess is, some other system.
    – benkftw
    Commented Apr 27, 2015 at 11:03
  • The coordinates givin by map.getView().calculateExtent(map.getSize()) will be in the map projection 3857. So if you want the extent en lat lon, use ol.transform to get them Commented Apr 27, 2015 at 12:18

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:

<script src="http://cdnjs.cloudflare.com/ajax/libs/proj4js/2.2.1/proj4.js" type="text/javascript"></script>

And you need to specify +axis=neu in 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');

http://epsg.io/3006.js does for some reason not include +axis=neu, so you can not use

<script src="http://epsg.io/3006.js" type="text/javascript"></script>

to get the definition.

For some reason, you have to use axis order east, north for the ol.view center coordinates (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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.