簡體   English   中英

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 )上找到了添加標題指示器的選項,並且在反應包裝器中有一個 showUserHeading 選項。 而且我無法理解如何在反應包裝器中添加此選項?

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

編輯:v6.1.18 已發布,並且 GeolocateControl 現在具有 showUserHeading 道具。 因此不再需要下面的解決方案。

我發現截至showUserHeading月 21 日,react-map-gl 尚未在其道具中包含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,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM