From 136c4eaed6f100e0d9a2ec4ef350b61100189ead Mon Sep 17 00:00:00 2001 From: Dan Leech Date: Tue, 2 Jun 2026 10:13:42 +0100 Subject: [PATCH 1/2] draw-ml clear snap indicator when not in drawing mode --- demo/js/draw.js | 4 ++-- demo/js/mapStyles.js | 4 ++-- plugins/beta/draw-ml/src/events.js | 13 ++++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/demo/js/draw.js b/demo/js/draw.js index 8f1143bd..f878b7e1 100755 --- a/demo/js/draw.js +++ b/demo/js/draw.js @@ -85,7 +85,7 @@ const datasetsPlugin = createDatasetsPlugin({ }) const interactiveMap = new InteractiveMap('map', { - behaviour: 'hybrid', + behaviour: 'mapOnly', mapProvider: maplibreProvider(), reverseGeocodeProvider: openNamesProvider({ url: process.env.OS_NEAREST_URL, @@ -102,7 +102,7 @@ const interactiveMap = new InteractiveMap('map', { autoColorScheme: true, // center: [-2.938769, 54.893806], bounds: [-2.989707, 54.864555, -2.878635, 54.937635], - containerHeight: '650px', + containerHeight: '600px', transformRequest: transformVtsRequest3857, enableZoomControls: true, readMapText: true, diff --git a/demo/js/mapStyles.js b/demo/js/mapStyles.js index 6b07f31b..4c64a15b 100755 --- a/demo/js/mapStyles.js +++ b/demo/js/mapStyles.js @@ -65,7 +65,7 @@ const vtsMapStyles3857 = [{ thumbnail: DARK_THUMBNAIL, logo: OS_LOGO_WHITE, logoAltText: OS_LOGO_ALT, - attribution: 'Test' + attribution: OS_ATTRIBUTION }, { id: BW_ID, label: BW_LABEL, @@ -73,7 +73,7 @@ const vtsMapStyles3857 = [{ thumbnail: BW_THUMBNAIL, logo: OS_LOGO_BLACK, logoAltText: OS_LOGO_ALT, - attribution: 'Test' + attribution: OS_ATTRIBUTION }, { id: 'aerial', label: 'Aerial', diff --git a/plugins/beta/draw-ml/src/events.js b/plugins/beta/draw-ml/src/events.js index be0e58fb..a997c15e 100755 --- a/plugins/beta/draw-ml/src/events.js +++ b/plugins/beta/draw-ml/src/events.js @@ -1,4 +1,4 @@ -import { clearSnapState, getSnapInstance } from './utils/snapHelpers.js' +import { clearSnapState, clearSnapIndicator, getSnapInstance } from './utils/snapHelpers.js' export function attachEvents ({ pluginState, mapProvider, buttonConfig, eventBus }) { const { drawDone, drawAddPoint, drawUndo, drawDeletePoint, drawSnap, drawCancel } = buttonConfig @@ -101,6 +101,15 @@ export function attachEvents ({ pluginState, mapProvider, buttonConfig, eventBus } } + // --- Ensure snap indicator is hidden whenever not in a drawing mode + const DRAWING_MODES = ['draw_polygon', 'draw_line'] + const handleModeChange = (e) => { + if (!DRAWING_MODES.includes(e.mode)) { + const snap = getSnapInstance(map) + clearSnapIndicator(snap, map) + } + } + // --- Map style update const handleStyleData = () => { const layers = map.getStyle().layers || [] @@ -148,6 +157,7 @@ export function attachEvents ({ pluginState, mapProvider, buttonConfig, eventBus map.on('styledata', handleStyleData) map.on('draw.cancel', handleCancel) map.on('draw.create', onCreate) + map.on('draw.modechange', handleModeChange) map.on('draw.editfinish', onEditFinish) map.on('draw.update', handleUpdate) map.on('draw.vertexselection', onVertexSelection) @@ -166,6 +176,7 @@ export function attachEvents ({ pluginState, mapProvider, buttonConfig, eventBus map.off('draw.create', onCreate) map.off('draw.editfinish', onEditFinish) map.off('draw.update', handleUpdate) + map.off('draw.modechange', handleModeChange) map.off('draw.vertexselection', onVertexSelection) map.off('draw.vertexchange', onVertexChange) map.off('draw.undochange', onUndoChange) From 5203a468261990dc2e4c97ba02b356ffb9f8c990 Mon Sep 17 00:00:00 2001 From: Dan Leech Date: Tue, 2 Jun 2026 15:06:00 +0100 Subject: [PATCH 2/2] Snap disabled when leaving draw modes --- plugins/beta/draw-ml/src/events.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/beta/draw-ml/src/events.js b/plugins/beta/draw-ml/src/events.js index a997c15e..c1a2a3b5 100755 --- a/plugins/beta/draw-ml/src/events.js +++ b/plugins/beta/draw-ml/src/events.js @@ -122,6 +122,7 @@ export function attachEvents ({ pluginState, mapProvider, buttonConfig, eventBus // --- Draw completion handlers (create / edit) const handleDrawCompletion = (eventName) => (e) => { const newFeature = e.features[0] + disableSnap() resetDrawModeAndFeature() setTimeout(() => draw.changeMode('disabled'), 0) eventBus.emit(eventName, newFeature)