terra-draw icon indicating copy to clipboard operation
terra-draw copied to clipboard

[Feature Request] Handling of style switching

Open bjtrounson opened this issue 4 months ago • 12 comments
trafficstars

Is your feature request related to a problem? Please describe. This feature request is related to the problem of managing layers and sources when users switch between different map styles (e.g., switching from a satellite to a street map, or between different base layers). Previously, switching styles could result in invalid drawing state because the adapter logic expects the layers to exist and was not aware of or responsive to the style change.

Describe your proposed idea for the solution to this problem

  • Listen to the style.load event for when the style changes.
  • When this event is fired try to reapply the style layers
  • Add some handling to deal with if they layers already exist and don't add it if it does. (I'm assuming this event doesn't get fired anywhere else but I thought I should handle this side-effect. This also helps when running terra-draw in React strict mode as it does try to apply the same layer and sources multiple times when React re-renders)

Describe alternatives you've considered I've tried managing this within my app but with a combination of React strict mode and trying to reinitialize terra-draw when the style changed became really complicated and over bearing, when this could just be easily handled by terra-draw itself.

I've got a fork that makes the changes, but I think there maybe some consideration for other adapters here Mapbox probably has the same thing that could be handled.

bjtrounson avatar Jul 18 '25 04:07 bjtrounson