Integrate maplibre-gl-terradraw with UI drawing playground #172
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue-171-terradraw-playground"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR investigates and demonstrates integrating maplibre-gl-terradraw for drawing shapes (swimming pools, etc.) on the map.
Key finding: maplibre-gl-terradraw implements the standard maplibre-gl
IControlinterface — add it withmap.addControl(). It does not need any special plugin support from vue-maplibre-gl. Integration into the existing customMap.vuewrapper is straightforward.Added:
@watergis/maplibre-gl-terradrawv1.15.0 dependencyts/view/UI.vue— drawing playground at/_/uits/route/config.tsPlayground features:
How to test:
/_/uiNext steps for Nidus Reveal pool shape review:
MaplibreTerradrawControlto the pool review component with modes["polygon", "rectangle", "circle", "select", "delete-selection", "undo", "redo"]finishevents to capture completed shapesgetSnapshot()to get GeoJSON features for persistenceCan you rebase this on the latest main?
294e07aa66b928a5a679Rebased onto latest main. Conflicts in package.json, pnpm-workspace.yaml, ts/route/config.ts, and pnpm-lock.yaml were resolved — kept both the new mitt dependency from main and the terradraw dependency from the branch.
Thanks, I got this running, and it looks pretty good. I'd like you to keep your first commit, but add a commit on top. I want that commit to modify your existing example to use the
<mgl-map>component. I imagine you'll need to leverage the@map:loadevent to add your drawing controls.If you can make it work it will be much easier to integrate into the rest of our existing map-using views.
Replace the manual maplibre-gl Map construction with vue-maplibre-gl's <mgl-map> component and the @map:load event pattern that the rest of the Nidus Reveal codebase uses. The key change: instead of creating a raw maplibregl.Map in onMounted and registering TerraDraw controls in a nested map.on('load', ...), the <mgl-map> component handles map lifecycle and the @map:load event handler wires up the MaplibreTerradrawControl. This makes the playground code structurally identical to how drawing controls will be integrated into the real Pool.vue review component, making the transition from playground to production straightforward.Updated: added a commit on top that refactors the playground to use
<mgl-map>from vue-maplibre-gl instead of rawnew maplibregl.Map().What changed:
onMounted+ nestedmap.on("load", ...)with<mgl-map>component and@map:load="onMapLoad"— the same pattern used byFeature.vue,ParcelDetail.vue, and the rest of the codebaseuseMap()for map access,MglEvent<"load">for the load handler, andmapStyleURL()from@/map/utilfor the style URLmaplibre-gl/dist/maplibre-gl.cssimport (vue-maplibre-gl handles that)onBeforeUnmountAll existing functionality (drawing modes, GeoJSON export, stats, event log, clear) is preserved. The structural change makes the playground an exact template for how drawing controls will be integrated into Pool.vue and other map views.