aboutsummaryrefslogtreecommitdiff
path: root/modern/src/map/core
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-06-11 16:51:50 -0700
committerAnton Tananaev <anton@traccar.org>2022-06-11 16:51:50 -0700
commit0aecbc3bf856b17f42e363eff2bac4fb0ce1f7ed (patch)
tree79eeaf8e4197a7ef3710fdd21641ebf0fda71566 /modern/src/map/core
parente34214fe32cafb19d871d3e20a2c5ad80de56a20 (diff)
downloadtrackermap-web-0aecbc3bf856b17f42e363eff2bac4fb0ce1f7ed.tar.gz
trackermap-web-0aecbc3bf856b17f42e363eff2bac4fb0ce1f7ed.tar.bz2
trackermap-web-0aecbc3bf856b17f42e363eff2bac4fb0ce1f7ed.zip
Preference for map layers
Diffstat (limited to 'modern/src/map/core')
-rw-r--r--modern/src/map/core/MapView.js11
1 files changed, 6 insertions, 5 deletions
diff --git a/modern/src/map/core/MapView.js b/modern/src/map/core/MapView.js
index 1e16e4dc..20e84185 100644
--- a/modern/src/map/core/MapView.js
+++ b/modern/src/map/core/MapView.js
@@ -52,7 +52,7 @@ map.addControl(new maplibregl.NavigationControl());
const switcher = new SwitcherControl(
() => updateReadyValue(false),
- (layerId) => savePersistedState('mapLayer', layerId),
+ (styleId) => savePersistedState('selectedMapStyle', styleId),
() => {
map.once('styledata', () => {
const waiting = () => {
@@ -75,7 +75,8 @@ const MapView = ({ children }) => {
const [mapReady, setMapReady] = useState(false);
const mapStyles = useMapStyles();
- const [defaultMapLayer] = usePersistedState('mapLayer', 'locationIqStreets');
+ const [activeMapStyles] = usePersistedState('activeMapStyles', ['locationIqStreets', 'osm', 'carto']);
+ const [defaultMapStyle] = usePersistedState('selectedMapStyle', 'locationIqStreets');
const mapboxAccessToken = useAttributePreference('mapboxAccessToken');
useEffect(() => {
@@ -83,9 +84,9 @@ const MapView = ({ children }) => {
}, [mapboxAccessToken]);
useEffect(() => {
- const filteredStyles = mapStyles.filter((style) => style.available);
- switcher.updateStyles(filteredStyles, defaultMapLayer);
- }, [mapStyles, defaultMapLayer]);
+ const filteredStyles = mapStyles.filter((style) => style.available && activeMapStyles.includes(style.id));
+ switcher.updateStyles(filteredStyles, defaultMapStyle);
+ }, [mapStyles, defaultMapStyle]);
useEffect(() => {
const listener = (ready) => setMapReady(ready);