【问题标题】:OpenLayers get Lat, Lon from polygon verticesOpenLayers 从多边形顶点获取纬度、经度
【发布时间】:2011-12-08 16:30:35
【问题描述】:

我正在尝试在 openlayers 中使用方形多边形来获取边界框。我需要从框中获取 North、South、West 和 East 值。现在我正在使用:

var topleft = vectors.features[0].geometry.getVertices()[0];

获取左上角的顶点。但是它返回一个像这样的值:

POINT(-13393350.718762 4024321.5982824)

如何从这个返回的点获取 lat 和 lon 值?

【问题讨论】:

  • 你的 OpenLayers 地图的投影是什么?
  • @AlexC 它使用墨卡托投影。我不需要转换方面的帮助。我只是坚持如何从返回值“POINT(-13393350.718762 4024321.5982824)”中获取纬度/经度值

标签: openlayers polygon latitude-longitude vertices


【解决方案1】:

你有一个选择是使用 getVertices()[i] 来生成一个点

var myPoint = new OpenLayers.Geometry.Point(vectors.features[0].geometry.getVertices()[0].x,
                              vectors.features[0].geometry.getVertices()[0].y )

然后用类似的东西转换那个点以获得纬度和经度

var myLatLonPoint = myPoint.transform( map.getProjectionObject(),
                   new OpenLayers.Projection("EPSG:4326"));

那么你应该能够从这些点中获取经纬度。

另一个可能更可取的选择是转换边界,然后拉出各个顶点。

var myLatLonSquare = vectors.features[0].geometry.transform( map.getProjectionObject(),
                   new OpenLayers.Projection("EPSG:4326"));

然后用以下命令拉出顶点的纬度:

myLatLonSquare.getVertices()[0].x  myLatLonSquare.getVertices()[0].y

【讨论】:

    猜你喜欢
    • 2013-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多