Closed paoloviselli closed 4 months ago
Have you imported the css file in your index.html?
or
import 'mapbox-gl/dist/mapbox-gl.css'; -- in your component file?
If anyone is still suffering with this even after adding the CSS, try turning off 3D terrain 😔
Description
Normally my map works totally fine, however as soon as I set a maxZoom value, then zoom in and drag around the map, the markers start going all over the map.
This is my code:
`import React, { useEffect, useState, useCallback } from "react"; import Map, { Layer, Marker, NavigationControl, Source } from "react-map-gl"; import MyLocationIcon from "@mui/icons-material/MyLocation"; import { Box, Typography } from "@mui/material"; import SatelliteAltIcon from "@mui/icons-material/SatelliteAlt";
const VesselAisMap = ({ locations }) => { const [isLoading, setIsLoading] = useState(true); const [initialViewport, setInitialViewport] = useState({}); const [viewport, setViewport] = useState({ latitude: 0, longitude: 0, zoom: 4, bearing: 0, pitch: 40, });
useEffect(() => { setIsLoading(true);
}, [locations]);
const recenterMap = () => { // Set your desired center latitude and longitude setViewport((prevState) => ({ ...prevState, latitude: initialViewport.latitude, longitude: initialViewport.longitude, zoom: 4, bearing: 0, pitch: 40, transitionDuration: 500, // Optional: add transition effect })); };
// Define the line as a GeoJSON object const routeGeoJSON = { type: "Feature", geometry: { type: "LineString", coordinates: locations.map((loc) => [loc.longitude, loc.latitude]), }, };
return ( <> {locations === null && !isLoading && ( <Box height={320} sx={{ minHeight: 320, maxHeight: 320, marginTop: "20px", borderRadius: "8px", display: "flex", alignItems: "center", justifyContent: "center", backgroundColor: "#f5f5f5", flexDirection: "column", }}
); };
export default VesselAisMap; `
https://github.com/visgl/react-map-gl/assets/46694996/71a36f52-aba0-4650-b3e3-3ec8d3f58f65
Expected Behavior
No response
Steps to Reproduce
Set maxZoom, zoom in from default value, then drag the map around.
Environment
Logs
No response