传单获取具有特定起点和终点的子折线
Leaflet get sub-polyline with specific start and end point
我想获得由特定起点和终点(以米为单位)确定的给定折线的"sub-Polyline"。
例如,我有一条 500 米的折线(使用 30 个坐标构建(不在同一空间中分隔)),我想用不同的颜色为 200 米和 300 米之间的线着色。是否可以使用传单功能?
在这里查看 LineStringSelect 插件:https://github.com/w8r/L.Control.LineStringSelect
随着演示(点击折线上的 2 个不同位置):
所以基本上你是在问 "If I have a polyline and a distance value, what is the point along the polyline with the desired length-distance to the line's starting point"?
此算法已被多次介绍,例如:
- http://www.postgis.org/docs/ST_Line_Interpolate_Point.html, http://www.postgis.org/docs/ST_Line_Substring.html
- http://turfjs.org/docs/#along
- https://github.com/IvanSanchez/Leaflet.Polyline.SnakeAnim
算法总是一样的:将polyline/linestring分成几段,测量每段的长度,定位点,在该点所在的段中应用直接插值。
请记住,二维笛卡尔平面中的几何与大地水准面中的几何不同,尤其是在测量距离时。对 GeographicLib 及其操纵测地线的方法做一些研究。
对于您的问题«是否可以使用 Leaflet 函数?»,答案是«否,Leaflet 未实现此算法»。最简单的方法应该是阅读答案中提到的 Leaflet 插件的源代码,或者使用 Turf 库中的 along()
方法。
我想获得由特定起点和终点(以米为单位)确定的给定折线的"sub-Polyline"。
例如,我有一条 500 米的折线(使用 30 个坐标构建(不在同一空间中分隔)),我想用不同的颜色为 200 米和 300 米之间的线着色。是否可以使用传单功能?
在这里查看 LineStringSelect 插件:https://github.com/w8r/L.Control.LineStringSelect
随着演示(点击折线上的 2 个不同位置):
所以基本上你是在问 "If I have a polyline and a distance value, what is the point along the polyline with the desired length-distance to the line's starting point"?
此算法已被多次介绍,例如:
- http://www.postgis.org/docs/ST_Line_Interpolate_Point.html, http://www.postgis.org/docs/ST_Line_Substring.html
- http://turfjs.org/docs/#along
- https://github.com/IvanSanchez/Leaflet.Polyline.SnakeAnim
算法总是一样的:将polyline/linestring分成几段,测量每段的长度,定位点,在该点所在的段中应用直接插值。
请记住,二维笛卡尔平面中的几何与大地水准面中的几何不同,尤其是在测量距离时。对 GeographicLib 及其操纵测地线的方法做一些研究。
对于您的问题«是否可以使用 Leaflet 函数?»,答案是«否,Leaflet 未实现此算法»。最简单的方法应该是阅读答案中提到的 Leaflet 插件的源代码,或者使用 Turf 库中的 along()
方法。