gpt4 book ai didi

javascript - 绘制的多边形不显示在 openlayers 中

转载 作者:行者123 更新时间:2023-12-02 23:37:32 26 4
gpt4 key购买 nike

我必须在 openlayers map 上绘制一个多边形。这是我的代码:

   draw = new Draw({
source: this.vectorSource,
type: 'Polygon'
})
draw.on('drawend', e => {

// sol 1, result is not as required
let coords = e.feature.getGeometry().getCoordinates()

//sol 2, give correct results, but drawn polygon gone
let coords = e..feature.getGeometry().transform('EPSG:3857', 'EPSG:4326').getCoordinates()
}
this.olmap.addInteraction(draw)

我必须将转换后的坐标存储在数据库中,但解决方案#2 不能保持绘制的多边形的可见性。对于解决方案#1,如果我稍后尝试使用

转换它们,它不会提供所需的格式化坐标
    transform(coords, 'EPSG:3857', 'EPSG:4326')

它不返回格式化的坐标。请指导我在保持多边形可见性和获取转换后的坐标方面出错的地方。

最佳答案

您需要克隆几何图形

let coords = e..feature.getGeometry().clone().transform('EPSG:3857', 'EPSG:4326').getCoordinates();

否则您将把特征移动到 View 坐标中靠近点 [0, 0] 的位置

关于javascript - 绘制的多边形不显示在 openlayers 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56222036/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com