简体   繁体   English

沿现有要素延伸 LineString/MultiLineString

[英]Extending LineString/MultiLineString along existing Feature

I have given coordinates of two points.我已经给出了两个点的坐标。 I can draw a LineString that is connecting these two points.我可以绘制一个连接这两点的 LineString。 What I'd like to achieve is having a LineString/MultiLineString that's connecting points but it's also a little longer (let's say 20% longer than distance between these two points) and it's extended after one point only.我想要实现的是拥有一个连接点的 LineString/MultiLineString,但它也稍微长一点(比方说比这两点之间的距离长 20%),并且它仅在一个点后延长。

What I currently have:我目前拥有的: 在此处输入图像描述

What I want to achieve:我想要实现的目标: 在此处输入图像描述

My issue is that I don't know how to find position of third point which would indicate end of the line.我的问题是我不知道如何找到第三点的 position,它表示行尾。 It should be placed exactly along existing line in given distance.它应该在给定距离内准确地沿着现有线放置。 Any kind of map projection is not important, because I just want to have a line that will be always straight.任何一种 map 投影都不重要,因为我只想有一条永远笔直的线。

const markerOne = new ol.Feature({
  geometry: new ol.geom.Point([-1000, -1000])
});

const markerTwo = new ol.Feature({
  geometry: new ol.geom.Point([1000, 1000])
});

const lineStrEnd = ?;

const lineStr = new ol.Feature({
 geometry: new ol.geom.LineString([markerOne.getGeometry().getCoordinates(), lineStrEnd])
});

HERE'S WORKING FIDDLE这是工作小提琴

The simplest way would be to scale the geometry, eg a linestring from markerOne to markerTwo increased by 20% with the scaling anchored at markerOne so the line extents beyond markerTwo最简单的方法是缩放几何图形,例如,从markerOnemarkerTwo的线串增加 20%,缩放固定在markerOne处,因此线延伸到markerTwo之外

const lineStr = new ol.Feature({
 geometry: new ol.geom.LineString([markerOne.getGeometry().getCoordinates(), markerTwo.getGeometry().getCoordinates()])
});

lineStr.getGeometry().scale(1.2, 1.2, markerOne.getGeometry().getCoordinates());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM