From 90b87123fe6597e080d2ab03463f50617cd2c5dd Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 21 Aug 2021 17:31:38 -0700 Subject: Fix map switches --- modern/src/map/AccuracyMap.js | 8 ++++++-- modern/src/map/GeofenceMap.js | 16 ++++++++++++---- modern/src/map/PositionsMap.js | 12 +++++++++--- modern/src/map/ReplayPathMap.js | 8 ++++++-- 4 files changed, 33 insertions(+), 11 deletions(-) (limited to 'modern/src/map') diff --git a/modern/src/map/AccuracyMap.js b/modern/src/map/AccuracyMap.js index 4baa105..5734ee8 100644 --- a/modern/src/map/AccuracyMap.js +++ b/modern/src/map/AccuracyMap.js @@ -36,8 +36,12 @@ const AccuracyMap = () => { }); return () => { - map.removeLayer(id); - map.removeSource(id); + if (map.getLayer(id)) { + map.removeLayer(id); + } + if (map.getSource(id)) { + map.removeSource(id); + } }; }, []); diff --git a/modern/src/map/GeofenceMap.js b/modern/src/map/GeofenceMap.js index d00cbb1..c0ecef4 100644 --- a/modern/src/map/GeofenceMap.js +++ b/modern/src/map/GeofenceMap.js @@ -56,10 +56,18 @@ const GeofenceMap = () => { }); return () => { - map.removeLayer('geofences-fill'); - map.removeLayer('geofences-line'); - map.removeLayer('geofences-title'); - map.removeSource(id); + if (map.getLayer('geofences-fill')) { + map.removeLayer('geofences-fill'); + } + if (map.getLayer('geofences-line')) { + map.removeLayer('geofences-line'); + } + if (map.getLayer('geofences-title')) { + map.removeLayer('geofences-title'); + } + if (map.getSource(id)) { + map.removeSource(id); + } }; }, []); diff --git a/modern/src/map/PositionsMap.js b/modern/src/map/PositionsMap.js index 9719b45..8d10053 100644 --- a/modern/src/map/PositionsMap.js +++ b/modern/src/map/PositionsMap.js @@ -148,9 +148,15 @@ const PositionsMap = ({ positions }) => { map.off('click', id, onMarkerClick); map.off('click', clusters, onClusterClick); - map.removeLayer(id); - map.removeLayer(clusters); - map.removeSource(id); + if (map.getLayer(id)) { + map.removeLayer(id); + } + if (map.getLayer(clusters)) { + map.removeLayer(clusters); + } + if (map.getSource(id)) { + map.removeSource(id); + } }; }, [onMarkerClick]); diff --git a/modern/src/map/ReplayPathMap.js b/modern/src/map/ReplayPathMap.js index 62b3f27..022548b 100644 --- a/modern/src/map/ReplayPathMap.js +++ b/modern/src/map/ReplayPathMap.js @@ -31,8 +31,12 @@ const ReplayPathMap = ({ positions }) => { }); return () => { - map.removeLayer(id); - map.removeSource(id); + if (map.getLayer(id)) { + map.removeLayer(id); + } + if (map.getSource(id)) { + map.removeSource(id); + } }; }, []); -- cgit v1.2.3