传单 - 在沿多线线的特定距离添加标记

发布于 2025-02-08 08:10:52 字数 854 浏览 1 评论 0原文

我正在研究基于传单的地图,并想在沿多线线的特定距离上添加标记。

我已经看过并使作品类似(将标记添加到沿整个路线/多线线的距离标记的lefflet 中的多线距离的各种距离) - 但我只需要显示一个标记。

这是我认为我需要更新的代码部分,但不确定什么?

提前致谢 :-)

    //  coords (from gpx)
        var coords = 
            [
                [58.64385, -3.02631],[58.64385, -3.02631],[58.64359, -3.0291],[58.64375, -3.03169],[58.64368, -3.0321],[58.64355, -3.03239],[58.64327, -3.03267]
            ]

    // polyline
        var polyline = L.polyline(coords, {
            distanceMarkers: { offset: 1600, iconSize: [20, 20] }
        });


    // zoom the map to the route
        map.fitBounds(polyline.getBounds());
        map.addLayer(polyline);

I'm working on a leaflet based map and would like to add a marker at a specific distance along a polyline.

I've seen and made work something similar (add marker on polyline due various distances of polyline in leaflet) that places distance markers along the whole route/polyline - but I only need to show a single marker.

Here's the section of code that I think I need to update, but not sure what?

thanks in advance :-)

    //  coords (from gpx)
        var coords = 
            [
                [58.64385, -3.02631],[58.64385, -3.02631],[58.64359, -3.0291],[58.64375, -3.03169],[58.64368, -3.0321],[58.64355, -3.03239],[58.64327, -3.03267]
            ]

    // polyline
        var polyline = L.polyline(coords, {
            distanceMarkers: { offset: 1600, iconSize: [20, 20] }
        });


    // zoom the map to the route
        map.fitBounds(polyline.getBounds());
        map.addLayer(polyline);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2025-02-15 08:10:52

这就是我与Turf.fs一起使用的方式

        var line = turf.lineString(somePoints);
        var options = {units: 'miles'};
        L.geoJSON(line).addTo(map);
        
        var along = turf.along(line, 1.25, options);
            L.geoJSON(along).addTo(map).bindTooltip("my tooltip text");
         
            along = turf.along(line, 2.123, options);
            L.geoJSON(along).addTo(map).bindTooltip("12345");

this is how I made it work with Turf.fs

        var line = turf.lineString(somePoints);
        var options = {units: 'miles'};
        L.geoJSON(line).addTo(map);
        
        var along = turf.along(line, 1.25, options);
            L.geoJSON(along).addTo(map).bindTooltip("my tooltip text");
         
            along = turf.along(line, 2.123, options);
            L.geoJSON(along).addTo(map).bindTooltip("12345");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文