Skip to content

Improve layer management #78

Closed
Closed

Description

@easbar

Currently we maintain a hard-coded list of layers in Mapbox.ts:

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:

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:

It's probably a good idea to review this issue when we start working on #24

Activity

  1. easbar commented on Jun 21, 2021

    @easbar
    MemberAuthor

    With #87 it is now easier to add more layers and currently I don't think there is anything more to be done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions