gpt4 book ai didi

OpenLayers - 如何从现有的 lonLat 点绘制多边形?

转载 作者:行者123 更新时间:2023-12-03 11:51:03 32 4
gpt4 key购买 nike

我的数据库中有来自用户定义多边形的经纬度顶点。我的问题是:我现在如何在 map 上重新创建和显示它们?使用 Google Maps API 很容易做到这一点,但我找不到关于如何使用 OpenLayers 做到这一点的任何文档或示例。有没有人有这样做的经验?

最佳答案

经过大量的实验,我发现了如何做到这一点:

let sitePoints = [];
let siteStyle = {
// style_definition
};

let epsg4326 = new OpenLayers.Projection("EPSG:4326");
for (let i in coordinates) {
let coord = coordinates[i];
let point = new OpenLayers.Geometry.Point(coord.lng, coord.lat);
// transform from WGS 1984 to Spherical Mercator
point.transform(epsg4326, map.getProjectionObject());
sitePoints.push(point);
}
sitePoints.push(sitePoints[0]);

let linearRing = new OpenLayers.Geometry.LinearRing(sitePoints);
let geometry = new OpenLayers.Geometry.Polygon([linearRing]);
let polygonFeature = new OpenLayers.Feature.Vector(geometry, null, siteStyle);
vectors.addFeatures([polygonFeature]);

关于OpenLayers - 如何从现有的 lonLat 点绘制多边形?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4002981/

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