微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Mapbox react-使用位置点列表显示路线并调整到最近的道路

如何解决Mapbox react-使用位置点列表显示路线并调整到最近的道路

我正在使用带有包装器react-map-gl的mapBox。 我正在尝试用我的lat lang点数组绘制路线, 我从以下地方找到了部分解决方案: https://github.com/visgl/react-map-gl/issues/591#issuecomment-454307294

enter image description here

问题在于显示的路线与最近的道路不匹配。

当前路线是绿线,我正尝试将其更改为类似于橙色线

解决方法

所以我发现最好的解决方案是将react-map-gl与deck.gl库一起使用。

decl.glreact-map-gl

  1. 安装库

  2. 使用Mapbox中的Matching API创建函数:
    https://docs.mapbox.com/help/tutorials/get-started-map-matching-api/#add-the-map-matching-api 使用geometries = geojson选项参数(在匹配调用的URL内)

  3. 从Matching API响应(data.matchings [0] .geometry)返回几何对象

  4. 使用新的几何对象创建GeoJsonLayer:

    const layerRoute = new GeoJsonLayer({
     id: "geojson-layer",data: getMatchingGeometry(),filled: true,stroked: false,extruded: true,pickable: true,lineJointRounded: true,getRadius: 50,getElevation: 30,lineWidthScale: 20,})
    
  5. 将新图层添加到地图:

      return (
       <DeckGL layers={[layerRoute]} initialViewState={{ ...initialView }} controller={true}>
         <StaticMap
           height={height}
           width={width}
           mapStyle={mapboxstyle}
           mapboxApiAccessToken={API_TOKEN}
         />
       </DeckGL>)
    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。