5

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

Jose Gómez
  • 3,110
  • 2
  • 32
  • 54
user2860857
  • 549
  • 3
  • 10
  • 21

1 Answers1

9

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

layer.getSource().getProjection().getCode()
Jonatas Walker
  • 13,583
  • 5
  • 53
  • 82