从 openlayers 3 层获取 EPSG 代码

get the EPSG code from openlayers 3 layer

这是我在 openlayers 3.9.0 中的 OSM 层。

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

现在我想获取层的EPSG code来检查它所以我喜欢

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

我收到错误 layer.getProjection is not a function

我错过了什么?

请帮帮我

你应该 getProjectionol.source.OSM 而不是 ol.layer.Tile,所以:

layer.getSource().getProjection().getCode()