gpt4 book ai didi

react-map-gl - 如何使用 react-map-gl 将连接线添加到 map 标记

转载 作者:行者123 更新时间:2023-12-05 06:37:31 24 4
gpt4 key购买 nike

如何使用 react-map-gl 添加连接线到 map 标记?

例如:我有 3 个标记(mark1、mark2、mark3)

mark1 应该连接到 mark2 & mark3 。mark2 应该连接到 mark1 &mark 3....谁能帮帮我...

最佳答案

几种方式:

1) 可能最好的方法是使用deck.gl LineLayer . Deck.gl 旨在与 react-map-gl 一起使用,所以我想这是 react-map-gl 的预期解决方案。
2) 在 map 上设置一个 ref,然后向 map 添加一个图层:

   <ReactMapGL
id={'map'}
ref={'map'}
onLoad={this.addLines}
.... />

addLines = () => {
const map = this.refs.map.getMap()
map.addLayer({
"id": "route",
"type": "line",
"source": {
"type": "geojson",
"data": {
"type": "Feature",
"properties": {},
"geometry": {
"type": "LineString",
"coordinates": [
[-122.48369693756104, 37.83381888486939],
[116.48348236083984, 37.83317489144141],
]
}
}
},
"layout": {
"line-join": "round",
"line-cap": "round"
},
"paint": {
"line-color": "#888",
"line-width": 8
}
});
}

3) 通过 mapStyles Prop 设置 geojson,如 this 中所示例子

关于react-map-gl - 如何使用 react-map-gl 将连接线添加到 map 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47790967/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com