react-map-gl showUserHeading 不在 GeolocateControl 中

react-map-gl showUserHeading not in GeolocateControl

我正在尝试在 React-mapbox-gl 中显示用户位置和航向指示器。

import * as React from "react";
import ReactMapGL, { GeolocateControl } from "react-map-gl";

const geolocateControlStyle = {
  right: 10,
  top: 10
};

function App() {
  const [viewport, setViewport] = React.useState({
    longitude: -122.45,
    latitude: 37.78,
    zoom: 14
  });
  return (
    <ReactMapGL
      {...viewport}
      width="80vw"
      height="80vh"
      onViewportChange={setViewport}
      mapboxApiAccessToken={
        "<token here>"
      }
    >
      <GeolocateControl
        style={geolocateControlStyle}
        positionOptions={{ enableHighAccuracy: true }}
        trackUserLocation={true}
        auto
      />
    </ReactMapGL>
  );
}

目前我只有用户所在的位置,没有当前航向。

我想要的是显示当前标题,像这样:,

我在文档 (https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) 上找到了添加标题指示器的选项,并且在 react 包装器中有一个 showUserHeading 选项。我不知道如何在反应包装器中添加这个选项?

这是 GeoLocation 道具文档: https://visgl.github.io/react-map-gl/docs/api-reference/geolocate-control

编辑:v6.1.18 已发布,GeolocateControl 现在具有 showUserHeading 道具。因此不再需要下面的解决方案。

我发现截至 2021 年 9 月 21 日,react-map-gl 尚未在其 props 中包含 showUserHeading。我通过使用此工具 https://www.npmjs.com/package/patch-package

进行修补解决了这个问题

这是补丁

diff --git a/node_modules/react-map-gl/src/components/geolocate-control.d.ts b/node_modules/react-map-gl/src/components/geolocate-control.d.ts
index 7c5d2a4..949f38b 100644
--- a/node_modules/react-map-gl/src/components/geolocate-control.d.ts
+++ b/node_modules/react-map-gl/src/components/geolocate-control.d.ts
@@ -9,6 +9,7 @@ type GeolocateControlProps = MapControlProps & Partial<{
   positionOptions: any,
   fitBoundsOptions: any,
   trackUserLocation: boolean,
+  showUserHeading?: boolean,
   showUserLocation: boolean,
   showAccuracyCircle: boolean,
   onViewStateChange?: Function,