从openlayers 3层获取EPSG代码

use*_*857 6 openlayers-3

这是我在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
});
Run Code Online (Sandbox Code Playgroud)

现在我想得到EPSG code图层来检查它,所以我喜欢

var a = layer.getProjection().getCode();
alert(a);
Run Code Online (Sandbox Code Playgroud)

我得到了错误layer.getProjection is not a function.

我错过了什么?

请帮我

Jon*_*ker 9

你应该getProjectionol.source.OSM,而不是ol.layer.Tile,那么:

layer.getSource().getProjection().getCode()
Run Code Online (Sandbox Code Playgroud)