Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get the EPSG code from openlayers 3 layer

Tags:

openlayers-3

This is my OSM layer in openlayers 3.9.0.

var layer = new ol.layer.Tile({
    source: new ol.source.OSM(

        {
        attributions: [
          new ol.Attribution({
            html: 'All maps © ' +
                '<a href="http://www.opencyclemap.org/">OpenCycleMap</a>'
          })
        ]
      }             

    ),
    opacity: 0.8,
    brightness: 0.8
});

And now I want to get the EPSG code of the layer to check it so I do like

var a = layer.getProjection().getCode();
alert(a);

and I get the error layer.getProjection is not a function.

What am I missing?

Please help me

like image 1000
user2860857 Avatar asked Sep 24 '15 16:09

user2860857


1 Answers

You should getProjection on ol.source.OSM rather than ol.layer.Tile, so:

layer.getSource().getProjection().getCode()
like image 179
Jonatas Walker Avatar answered Nov 15 '22 20:11

Jonatas Walker