【问题标题】:How can I get the coordinates of a feature in OpenLayers 3如何在 OpenLayers 3 中获取要素的坐标
【发布时间】:2016-05-27 16:18:15
【问题描述】:

到目前为止,我已经尝试过使用此代码

feature.getGeometry().getCoordinates()

但它不起作用。我得到的错误是“几何类型上不存在属性 getCoordinates”。这可能与我使用 TypeScript 的事实有关吗?

【问题讨论】:

  • “很多人说”The documentation 应该是您的参考点,它显然没有在 Geometry 对象上指定 getCoordinates 方法,它是在各个子类上定义的。你甚至没有说你对什么样的功能感兴趣。

标签: openlayers-3


【解决方案1】:

是的,这与我使用 TypeScript 的事实有关。事实上,在 TypeScript 中,你必须这样进行:

let p: ol.geom.Point = <ol.geom.Point>feature.getGeometry();
let c: ol.Coordinate = p.getCoordinates();

基本上,您首先必须执行从几何到点的转换。然后你得到坐标。

编辑ol v6.13.0

他们现在可以使用打字稿,该功能应声明如下

feature: Feature<Point> = new Feature()

feature.getGeometry().getCoordinates()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多