Fix Leaflet map initialization: prevent DOM errors and ensure robust container checks
- Refactored initializeMap to accept the DOM node instead of the ref object - Updated all checks to use the DOM node directly - Improved useInitializeMap to only call initializeMap when the container is ready - Prevents "mapRef.current ist nicht definiert oder nicht im DOM" errors - Ensures map is only initialized when the container is attached
This commit is contained in:
@@ -206,6 +206,16 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
}
|
||||
};
|
||||
//-----------------------------Map Initialisierung----------------
|
||||
// Default map options for Leaflet
|
||||
const mapOptions = {
|
||||
center: currentCenter,
|
||||
zoom: currentZoom,
|
||||
zoomControl: true,
|
||||
contextmenu: true,
|
||||
contextmenuWidth: 180,
|
||||
contextmenuItems: [],
|
||||
};
|
||||
|
||||
useInitializeMap(
|
||||
map,
|
||||
mapRef,
|
||||
@@ -214,7 +224,8 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
setMenuItemAdded,
|
||||
addItemsToMapContextMenu,
|
||||
hasRights,
|
||||
value => dispatch(setDisabled(value))
|
||||
value => dispatch(setDisabled(value)),
|
||||
mapOptions // pass mapOptions
|
||||
);
|
||||
|
||||
//-------------------------React Hooks--------------------------------
|
||||
|
||||
Reference in New Issue
Block a user