我正在尝试使用 react-map-gl 库在两个点之间绘制一条线。然而,我在官方文档中找不到示例。因此,我正在尝试从以下使用 Mapbox 库的代码片段中复现相同的行为。
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-122.486052, 37.830348],
zoom: 15
});
map.on('load', function() {
map.addSource('route', {
'type': 'geojson',
'data': {
'type': 'Feature',
'properties': {},
'geometry': {
'type': 'LineString',
'coordinates': [
[-122.483696, 37.833818],
[-122.493782, 37.833683]
]
}
}
});
map.addLayer({
'id': 'route',
'type': 'line',
'source': 'route',
'layout': {
'line-join': 'round',
'line-cap': 'round'
},
'paint': {
'line-color': '#888',
'line-width': 8
}
});
});
这是沙盒,我在控制台上没有看到任何错误,但线条没有显示出来:
https://codesandbox.io/s/draw-line-between-two-point-v0mbc?file=/src/index.js:214-226