【问题标题】:get the EPSG code from openlayers 3 layer从 openlayers 3 层获取 EPSG 代码
【发布时间】:2015-09-24 16:10:10
【问题描述】:

这是我在 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

我错过了什么?

请帮帮我

【问题讨论】:

    标签: openlayers-3


    【解决方案1】:

    你应该在ol.source.OSM而不是ol.layer.TilegetProjection,所以:

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

    【讨论】:

    • 成功了。出于好奇,我无法理解为什么我需要getSource,因为我使用getProjection 获得了图层的投影。有什么帮助吗?谢谢
    • 因为ol.layer.Tile对投影一无所知。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-27
    • 1970-01-01
    • 2019-07-25
    • 2023-03-20
    • 1970-01-01
    相关资源
    最近更新 更多