You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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";
if (locations.length === 0) {
setIsLoading(false);
return;
}
//set the latitude and longitude of the last locations as the initial view state
setViewport({
...viewport,
latitude: locations[locations.length - 1].latitude,
longitude: locations[locations.length - 1].longitude,
});
setInitialViewport({
latitude: locations[locations.length - 1].latitude,
longitude: locations[locations.length - 1].longitude,
zoom: 4,
bearing: 0,
pitch: 40,
});
setIsLoading(false);
}, [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]),
},
};
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",
}}
>
<SatelliteAltIcon sx={{ fontSize: "120px", color: "#1f677a" }} />
<Typography variant="h6" component="span" sx={{ mt: "32px" }}>
LOADING
)}
);
};
export default VesselAisMap;
`
Screen.Recording.2024-03-04.at.15.28.49.mov
Expected Behavior
No response
Steps to Reproduce
Set maxZoom, zoom in from default value, then drag the map around.
Environment
Logs
No response
The text was updated successfully, but these errors were encountered: