Skip to content

Move layers to separate files - #108

Merged
easbar merged 6 commits into
react_mapbox_wrapperfrom
layer_management
Jun 16, 2021
Merged

easbar merged 6 commits into
react_mapbox_wrapperfrom
layer_management

Conversation

@easbar

@easbar easbar commented Jun 16, 2021

Copy link
Copy Markdown
Member

Based on #87 I tried making our map component independent from the different layers that are added throughout the application.

@easbar
easbar changed the base branch from master to react_mapbox_wrapper June 16, 2021 17:07
Comment thread src/App.tsx Outdated
Comment on lines +115 to +129
'paths-layer': {
id: 'paths-layer',
interactiveLayerIds: getInteractiveLayerIds(route.selectedPath, route.routingResult.paths),
onClick: feature => {
// select an alternative path if clicked
if (feature.layer.id === pathsLayerKey) {
const index = feature.properties!.index
const path = getCurrentPaths(route.selectedPath, route.routingResult.paths).find(
indexPath => indexPath.index === index
)
Dispatcher.dispatch(new SetSelectedPath(path!.path))
}
},
layer: <PathsLayer selectedPath={route.selectedPath} paths={route.routingResult.paths} />,
},

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Janekdererste maybe you can help me here? Basically I would like to move all this into PathsLayer.tsx for example, so here in App.tsx it would maybe simply look like this:

const mapLayers = [
  new ContextMenuLayer(popupCoordinate),
  new QueryPointLayer(query.queryPoints),
  new PathsLayer(route.selectedPath, route.routingResult.paths),
  new PathDetailsLayer(pathDetails),
]
mapLayers.forEach(layer => {
  Dispatcher.dispatch(new PutMapLayerAction(layer))
})

But I could not figure out how to move the JSX out from here. Note that I already set up the MapLayerStore but not using it so far.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal was that adding a layer would be a matter of adding a file that specifies the layer and calling Dispatch.dispatch(new PutMapLayerAction(layer)) somewhere. The latter is probably done only when the app loads, but in principle we might add/remove layers interactively?! We need the interactiveLayerIds and onClick propertys for every such layer, because the Mapbox/React wrapper needs to pass the user events to all our layers.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I went back and forth here a bit and now I actually minimized the changes and think this should be included in #87

Comment thread src/map/Map.tsx Outdated
pathDetailPoint: PathDetailsPoint | null
highlightedPathDetailSegments: Coordinate[][]
mapLayers: { [key: string]: MapLayer }
setPopupCoordinate: (c: Coordinate | null) => void

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing around the setPopupCoordinate function here is against the current architecture and we probably would need another store for this. So far we were able to keep const [popupCoordinate, setPopupCoordinate] = useState(null) in Map.tsx, but now that Map and ContextMenuLayer are separate components this is more complicated.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, or we move the ContextMenuLayer back into Map.tsx because it is kind of more related to the map than the others? :) Btw. the content of the context menu is definitely something that we might need to update based on user-interaction, e.g. when switching between /route and /isochrone mode for example.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... this is what I did :)

@easbar easbar mentioned this pull request Jun 16, 2021
5 of 6 tasks
@easbar
easbar marked this pull request as ready for review June 16, 2021 18:27
@easbar
easbar merged commit 005e26e into react_mapbox_wrapper Jun 16, 2021
@easbar
easbar deleted the layer_management branch June 16, 2021 18:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant