Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 [open-formulieren/open-forms#2177] Duplicate Leaflet shapes
Since we persist the leaflet changes in React state, and have to act on state changes, only the shapes from the React state should be shown. Leaflet adds new shapes to its map before calling `onCreated`. If we then save the new shape to state, and show this using `<GeoJSON ... />`, we have two shapes on the exact same spot. This causes weird behavior when you want to remove them using the delete button. Clearing the leaflet map before saving the new shape does ensure only one shape is present. If we then use `<GeoJSON ... />` to show the new shape, the leaflet soft-delete won't work. (Because `<GeoJSON ... />` can't be temporarily hidden, without some extra work) To ensure only one shape is present and to allow soft-deletion, we have two options: - We clear the map every time a new shape is created, and save the new shape to state. Using `<GeoJSON ... />` we show the newly created shape. For the deletion we keep inventory of the soft-delete actions and change the map display accordingly, and persist the changes when confirmed by the user. - We clear the map every time a new shape is created, and save the new shape to state. Using useEffect we add the newly created shape to the leaflet map (this doesn't trigger `onCreated`). With this we can use the complete deletion functionality from leaflet, and only have to persist on `onDeleted`. To keep this component as simple as we can, I've opted for the second option
- Loading branch information