将标记与Mapbox GL中的多线线连接

发布于 2025-01-29 08:51:03 字数 201 浏览 3 评论 0原文

我正在使用Mapbox GL开发Web应用程序,更具体地说,它对React的绑定,React Map-Gl

该应用程序的计划功能之一是添加标记并连接它们。

但是,我很难连接标记。

当我单击标记时,我想开始绘制线路,当我单击其他位置时,将断点添加到线路上,然后在单击另一个标记时完成行。

我可以用什么?

I'm developing a web application using Mapbox GL, more specifically, its binding for React, react-map-gl.

One of the planned functionalities for the app is adding markers and connecting them.

However, I'm having trouble connecting markers.

I want to start drawing the line when I click on a marker, add a breakpoint to the line when I click elsewhere and finish the line when I click on another marker.

What can I use for this?

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

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

发布评论

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

评论(2

骷髅 2025-02-05 08:51:03

我也在从事同样的工作,您可以使用deck.gl在地图上绘制线路,也可以使用Geojson。

I am also working on same, you can use deck.gl for plotting lines on map, or you can also use geoJson for the same.

薄荷港 2025-02-05 08:51:03

我最终要做的是使用Editablegeojsonlayer以及标记的功能以及它们之间的连接,如下所示:

data: {
    type: "FeatureCollection",
    features: markers.flatMap((marker) => {
        // Map markers
        let features = [
            {
                geometry: {
                    type: "Point",
                    coordinates: marker.coordinates
                },
                type: "Feature",
                node: marker
            }
        ];

        // Map connections
        if (marker.connections.length > 0) {
            features = features.concat(
                marker.connections.flatMap((endMarker) => [
                    {
                        geometry: {
                            type: "LineString",
                            coordinates: [
                                marker.coordinates,
                                endMarker.coordinates
                            ]
                        },
                        type: "Feature"
                    }
                ])
            );
        }

        return features;
    })
}

What I ended up doing was using an EditableGeoJsonLayer with the features for both the markers and the connections between them as follows:

data: {
    type: "FeatureCollection",
    features: markers.flatMap((marker) => {
        // Map markers
        let features = [
            {
                geometry: {
                    type: "Point",
                    coordinates: marker.coordinates
                },
                type: "Feature",
                node: marker
            }
        ];

        // Map connections
        if (marker.connections.length > 0) {
            features = features.concat(
                marker.connections.flatMap((endMarker) => [
                    {
                        geometry: {
                            type: "LineString",
                            coordinates: [
                                marker.coordinates,
                                endMarker.coordinates
                            ]
                        },
                        type: "Feature"
                    }
                ])
            );
        }

        return features;
    })
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文