Skip to content

Commit

Permalink
Fix map change crash
Browse files Browse the repository at this point in the history
  • Loading branch information
tananaev committed Mar 26, 2023
1 parent 4e733fb commit 6402a8a
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion modern/src/map/MapGeofence.js
Expand Up @@ -81,7 +81,7 @@ const MapGeofence = () => {

useEffect(() => {
if (mapGeofences) {
map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: Object.values(geofences).map((geofence) => geofenceToFeature(theme, geofence)),
});
Expand Down
4 changes: 2 additions & 2 deletions modern/src/map/MapMarkers.js
Expand Up @@ -67,7 +67,7 @@ const MapMarkers = ({ markers, showTitles }) => {
}, [showTitles]);

useEffect(() => {
map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: markers.map(({ latitude, longitude, image, title }) => ({
type: 'Feature',
Expand All @@ -81,7 +81,7 @@ const MapMarkers = ({ markers, showTitles }) => {
},
})),
});
}, [markers]);
}, [showTitles, markers]);

return null;
};
Expand Down
4 changes: 2 additions & 2 deletions modern/src/map/MapPositions.js
Expand Up @@ -178,7 +178,7 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF
}, [mapCluster, clusters, direction, onMarkerClick, onClusterClick]);

useEffect(() => {
map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: positions.filter((it) => devices.hasOwnProperty(it.deviceId)).map((position) => ({
type: 'Feature',
Expand All @@ -189,7 +189,7 @@ const MapPositions = ({ positions, onClick, showStatus, selectedPosition, titleF
properties: createFeature(devices, position, selectedPosition && selectedPosition.id),
})),
});
}, [devices, positions, selectedPosition]);
}, [mapCluster, clusters, direction, onMarkerClick, onClusterClick, devices, positions, selectedPosition]);

return null;
};
Expand Down
2 changes: 1 addition & 1 deletion modern/src/map/MapRoutePath.js
Expand Up @@ -81,7 +81,7 @@ const MapRoutePath = ({ name, positions, coordinates }) => {
if (!coordinates) {
coordinates = positions.map((item) => [item.longitude, item.latitude]);
}
map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'Feature',
geometry: {
type: 'LineString',
Expand Down
4 changes: 2 additions & 2 deletions modern/src/map/MapRoutePoints.js
Expand Up @@ -55,7 +55,7 @@ const MapPositions = ({ positions, onClick }) => {
}, [onMarkerClick]);

useEffect(() => {
map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: positions.map((position, index) => ({
type: 'Feature',
Expand All @@ -69,7 +69,7 @@ const MapPositions = ({ positions, onClick }) => {
},
})),
});
}, [positions]);
}, [onMarkerClick, positions]);

return null;
};
Expand Down
5 changes: 2 additions & 3 deletions modern/src/map/main/MapAccuracy.js
Expand Up @@ -42,13 +42,12 @@ const MapAccuracy = ({ positions }) => {
}, []);

useEffect(() => {
const data = {
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: positions
.filter((position) => position.accuracy > 0)
.map((position) => circle([position.longitude, position.latitude], position.accuracy * 0.001)),
};
map.getSource(id).setData(data);
});
}, [positions]);

return null;
Expand Down
2 changes: 1 addition & 1 deletion modern/src/map/main/MapLiveRoutes.js
Expand Up @@ -61,7 +61,7 @@ const MapLiveRoutes = () => {
.filter((id) => (type === 'selected' ? id === selectedDeviceId : true))
.filter((id) => history.hasOwnProperty(id));

map.getSource(id).setData({
map.getSource(id)?.setData({
type: 'FeatureCollection',
features: deviceIds.map((deviceId) => ({
type: 'Feature',
Expand Down

0 comments on commit 6402a8a

Please sign in to comment.