道路内的 Mapbox 线串

发布于 2025-01-19 08:08:58 字数 857 浏览 1 评论 0原文

我有一组从卡车上取出的GPS坐标,我需要在地图上放上MAPBOX的地图,然后画一条线以显示卡车路线。

有没有办法绘制沿着道路的线路?目前,我只是坐标之间的一条直线。

由于我有很多坐标,因此我将代码放在这里:

const geojson = data on JSFiddle

const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [13.23065662, 43.2500267],
zoom: 12
});
 
map.on('load', () => {
map.addSource('LineString', {
'type': 'geojson',
'data': geojson
});
map.addLayer({
'id': 'LineString',
'type': 'line',
'source': 'LineString',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#BF93E4',
'line-width': 5
}
});
})

I have a set of GPS coordinates taken from a truck, that I need to put on a map with mapbox and then draw a line to show the truck route.

Is there a way to draw the line that follow the roads? At the moment is very I have just a straight line beetween the coordinates.

enter image description here

Since I have a lot of coordinates I put my code here: JSFiddle

const geojson = data on JSFiddle

const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [13.23065662, 43.2500267],
zoom: 12
});
 
map.on('load', () => {
map.addSource('LineString', {
'type': 'geojson',
'data': geojson
});
map.addLayer({
'id': 'LineString',
'type': 'line',
'source': 'LineString',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#BF93E4',
'line-width': 5
}
});
})

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

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

发布评论

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

评论(1

春花秋月 2025-01-26 08:08:58

您正在寻找地图匹配 API

You're looking for the Map Matching API.

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