gpt4 book ai didi

javascript - Openlayers 3 - 将点插入到沿线某处之间的 LineString 中

转载 作者:太空宇宙 更新时间:2023-11-04 16:00:05 25 4
gpt4 key购买 nike

我正在寻找一种智能方法,使用 Openlayers-3 将点插入到 LineString 中。今天,我保存了整个 LineString 上最近的点,使用 forEachSegment 进行循环以查找最近点的线段,并将该点插入到该线段的起点和终点之间。最后,我将新部分放回到完整 LineString 的几何形状中。

它正在工作。但还有更聪明、更短的解决方案吗?

谢谢和干杯!安德烈亚斯。

pp=modifyfeatures.item(g).getGeometry().forEachSegment(function (start, end){
waylinexy=new Array();
waylinexy.push(start);
waylinexy.push(end);
var segment = new ol.Feature({geometry:new ol.geom.LineString(waylinexy, 'XY')});
pp.push(start);
if (segment.getGeometry().getClosestPoint(cmpos).toString()==cmpos.toString()){pp.push(cmpos); }
pp.push(end);
return pp;
});
var ps = new ol.Feature({geometry:new ol.geom.LineString(pp, 'XY')});
modifyfeatures.item(g).getGeometry().setCoordinates(pp);

最佳答案

看起来 foreachsegment 不适用于具有多个段的行。为了将多个点插入线串中,我现在使用此解决方案:

p=new Array();
cmpos=modifyfeatures.item(g).getGeometry().getClosestPoint(eventcoord);
linegeo=modifyfeatures.item(g).getGeometry().getCoordinates();
for (a=0;a<linegeo.length-1;a++)
{
start=linegeo[a];
end=linegeo[a+1];
var segment = new ol.Feature({geometry:new ol.geom.LineString([start, end], 'XY')});
p.push(start);
if (segment.getGeometry().getClosestPoint(cmpos).toString()==cmpos.toString()){p.push(cmpos); }
p.push(end);
}
modifyfeatures.item(g).getGeometry().setCoordinates(p);

关于javascript - Openlayers 3 - 将点插入到沿线某处之间的 LineString 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42339085/

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