Repository navigation
Description
Currently we maintain a hard-coded list of layers in Mapbox.ts:
graphhopper-maps/src/map/Mapbox.ts
Lines 17 to 20 in d860313
| const selectedPathSourceKey = 'selectedPathSource' | |
| const selectedPathLayerKey = 'selectedPathLayer' | |
| const pathsSourceKey = 'pathsSource' | |
| const pathsLayerKey = 'pathsLayer' |
This seems to work for now, but when we start adding more layers this is probably not ideal and it might be better to keep Mapbox.ts independent from the layers we like to add to the map. With some kind of external layer management maybe we also do not need the current workaround of re-creating the map instance when we change the background layer (mapStyle) here:
graphhopper-maps/src/map/Map.tsx
Lines 22 to 35 in d860313
| useEffect(() => { | |
| if (map) map.remove() | |
| const mapWrapper = new Mapbox( | |
| mapContainerRef.current!, | |
| mapStyle, | |
| () => { | |
| setMap(mapWrapper) | |
| Dispatcher.dispatch(new MapIsLoaded()) | |
| } | |
| ) | |
| mapWrapper.fitBounds(bbox) | |
| return () => map?.remove() | |
| }, [mapStyle]) |
Maybe we can take a look at popular react/mapbox wrappers to borrow some ideas for this and/or even use one of those wrappers, like:
- https://github.com/visgl/react-map-gl
- https://github.com/alex3165/react-mapbox-gl
It's probably a good idea to review this issue when we start working on #24
Activity
easbar commentedon Jun 21, 2021
With #87 it is now easier to add more layers and currently I don't think there is anything more to be done.