diff options
author | Anton Tananaev <anton@traccar.org> | 2022-06-11 16:34:29 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2022-06-11 16:34:29 -0700 |
commit | 7b703f07c6134046f80e2d859f5d607f024df191 (patch) | |
tree | 4a668a34e90978b56a9a3f1a953a8f295d796c69 /modern/src/map | |
parent | 4660911c014cba2186f9c3637f017c5f077bb2f8 (diff) | |
download | trackermap-web-7b703f07c6134046f80e2d859f5d607f024df191.tar.gz trackermap-web-7b703f07c6134046f80e2d859f5d607f024df191.tar.bz2 trackermap-web-7b703f07c6134046f80e2d859f5d607f024df191.zip |
Improve and fix map selection
Diffstat (limited to 'modern/src/map')
-rw-r--r-- | modern/src/map/core/MapView.js | 6 | ||||
-rw-r--r-- | modern/src/map/switcher/switcher.js | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/modern/src/map/core/MapView.js b/modern/src/map/core/MapView.js index 7f183346..1e16e4dc 100644 --- a/modern/src/map/core/MapView.js +++ b/modern/src/map/core/MapView.js @@ -74,17 +74,17 @@ const MapView = ({ children }) => { const [mapReady, setMapReady] = useState(false); + const mapStyles = useMapStyles(); const [defaultMapLayer] = usePersistedState('mapLayer', 'locationIqStreets'); const mapboxAccessToken = useAttributePreference('mapboxAccessToken'); - const mapStyles = useMapStyles(); - useEffect(() => { maplibregl.accessToken = mapboxAccessToken; }, [mapboxAccessToken]); useEffect(() => { - switcher.updateStyles(mapStyles, defaultMapLayer); + const filteredStyles = mapStyles.filter((style) => style.available); + switcher.updateStyles(filteredStyles, defaultMapLayer); }, [mapStyles, defaultMapLayer]); useEffect(() => { diff --git a/modern/src/map/switcher/switcher.js b/modern/src/map/switcher/switcher.js index 742ff8c3..60a5eff7 100644 --- a/modern/src/map/switcher/switcher.js +++ b/modern/src/map/switcher/switcher.js @@ -13,9 +13,11 @@ export class SwitcherControl { return 'top-right'; } - updateStyles(updatedStyles, selectedStyle) { + updateStyles(updatedStyles, defaultStyle) { this.styles = updatedStyles; + const selectedStyle = this.currentStyle || defaultStyle; + while (this.mapStyleContainer.firstChild) { this.mapStyleContainer.removeChild(this.mapStyleContainer.firstChild); } @@ -65,6 +67,8 @@ export class SwitcherControl { } target.classList.add('active'); + this.currentStyle = target.dataset.id; + this.onAfterSwitch(); } |