Estoy tratando de mostrar la posición de los usuarios y el indicador de rumbo en 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> ); }Actualmente solo tengo donde está el usuario, no su título actual.
Lo que quiero es mostrar el encabezado actual, así:
Encontré la opción para agregar el indicador de encabezado en los documentos ( https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol ), y hay una opción para mostrar el encabezado del usuario en el contenedor de reacción. ¿Y no puedo entender cómo agregar esta opción en el contenedor de reacción?
Aquí está la documentación de accesorios de GeoLocation: https://visgl.github.io/react-map-gl/docs/api-reference/geolocate-control
EDITAR: se lanzó v6.1.18, y GeolocateControl ahora tiene el accesorio showUserHeading. Por lo tanto, la solución a continuación ya no es necesaria.
Descubrí que a partir del 21.09.2021, react-map-gl no ha incluido showUserHeading dentro de sus accesorios. Resolví esto parcheando usando esta herramienta https://www.npmjs.com/package/patch-package
aquí está el parche
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,