简体   繁体   English

如何使用 PolylineDecorator 在折线的每条线的末尾放置一个箭头?

[英]How to place an arrowhead at the end of each line of a polyline using PolylineDecorator?

I am experimenting with PolylineDecorator for leaflet.我正在尝试使用 PolylineDecorator 制作传单。 I intend to draw a polyline with arrowheads at the end of each line.我打算在每条线的末尾绘制一条带箭头的折线。 I have this code:我有这个代码:

var somePoints = [];
for (var rowIndex in rows) {
    somePoints.push(L.latLng(rows[rowIndex].Lat, rows[rowIndex].Lon));
}
var pl = L.polyline(somePoints);
pl.addTo(map);
var decorator = L.polylineDecorator(pl, {
    patterns: [
        // defines a pattern of 10px-wide dashes, repeated every 20px on the line
        {offset: 0, repeat: 50, symbol: L.Symbol.arrowHead({pixelSize: 8, polygon: false, pathOptions: {stroke: true}})}
    ]
}).addTo(map);

which produces this产生这个

在此处输入图片说明

My intention is to have an arrowhead at each end of line (the marker positions).我的目的是在行的每一端(标记位置)都有一个箭头。 If I change offset to "100%" and repeat to 0 , then I have this:如果我将offset更改为"100%"repeat0 ,那么我有这个:

在此处输入图片说明

we have an arrow at the very last marker, but no arrowheads for the other markers.我们在最后一个标记处有一个箭头,但其他标记处没有箭头。 I know we can achieve what I want by drawing each line as a separate polyline with an offset of "100%" and repeat of 0 , but I wonder whether this can be achieved using a single polyline with more than two points in the parameters of decorator .我知道我们可以通过将每条线绘制为offset"100%"repeat0的单独折线来实现我想要的,但我想知道这是否可以使用在参数中具有两个以上点的单个折线来实现decorator Is this possible or should I modify my code to have n - 1 polylines with arrowheads?这是可能的还是我应该修改我的代码以获得 n - 1 条带箭头的折线?

I know this is like stupid old but I am actually in the process of building a plugin for this purpose:我知道这很愚蠢,但实际上我正在为此目的构建插件:

https://github.com/slutske22/leaflet-arrowheads https://github.com/slutske22/leaflet-arrowheads

As per request in the comment, here is a working codesandbox with a bunch of examples: https://codesandbox.io/s/leaflet-arrowheads-example-zfxxc根据评论中的要求,这是一个带有一堆示例的有效代码和框: https ://codesandbox.io/s/leaflet-arrowheads-example-zfxxc

I am almost done fleshing out the readme and will soon request it to be added to the leaflet plugin list.我几乎完成了自述文件的充实,很快就会要求将其添加到传单插件列表中。 Let me know what you think, if you find it helpful / any more feature requests / general feedback.如果您觉得有帮助/更多功能请求/一般反馈,请告诉我您的想法。

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

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