Openlayers 3 从openlayers 3层获取EPSG代码

Openlayers 3 从openlayers 3层获取EPSG代码,openlayers-3,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 &copy; ' + '<a href="http://www.opencyclema

这是我在openlayers 3.9.0中的OSM层

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

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

    ),
    opacity: 0.8,
    brightness: 0.8
});
我得到了错误
层。getProjection不是一个函数

我错过了什么

请帮助我

您应该在
ol.source.OSM
上而不是
ol.layer.Tile
,因此:

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

成功了。出于好奇,我无法理解为什么我需要
getSource
,因为我用
getProjection
获得了层的投影。有什么帮助吗?谢谢,因为ol.layer.Tile对投影一无所知。
layer.getSource().getProjection().getCode()