Draw Tools & Modes Lifecycle
useDrawTools(map, focusedArea) owns MapboxDraw setup, custom modes, and event lifecycles.
Initialization
- Creates a single
MapboxDrawinstance withdisplayControlsDefault:falseanduserProperties:true. - Registers custom modes (e.g.
draw_rect_object) alongside built-ins. - Adds control to the map and wires
draw.create,draw.update,draw.delete,draw.selectionchange.
Style reloads
- Initializes early and also listens to
style.loadto rebind layers/filters after basemap switches. reinitializeDrawControls()ensures a draw instance exists and reattaches events when style changes.
Mode changes
- On
draw.modechange, clears active rect indicator when leaving the custom mode, and clears the active tool highlight when returning tosimple_select. - Map container also re-hides Draw point layers for text on
style.load,draw.modechange, anddraw.renderby applying a filter.
Retry mechanism
- If initialization is delayed, the UI exposes a Retry button (
DrawingTools) which calls the hook’s manual initializer to re-attempt binding.
Key files:
src/hooks/useDrawTools.jssrc/components/Sidebar/DrawingTools.jsxsrc/components/Map/MapContainer.jsx(reapplies Draw point filters)