Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demo/js/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions demo/js/mapStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ const vtsMapStyles3857 = [{
thumbnail: DARK_THUMBNAIL,
logo: OS_LOGO_WHITE,
logoAltText: OS_LOGO_ALT,
attribution: 'Test'
attribution: OS_ATTRIBUTION
}, {
id: BW_ID,
label: BW_LABEL,
url: process.env.VTS_BLACK_AND_WHITE_URL,
thumbnail: BW_THUMBNAIL,
logo: OS_LOGO_BLACK,
logoAltText: OS_LOGO_ALT,
attribution: 'Test'
attribution: OS_ATTRIBUTION
}, {
id: 'aerial',
label: 'Aerial',
Expand Down
14 changes: 13 additions & 1 deletion plugins/beta/draw-ml/src/events.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 || []
Expand All @@ -113,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)
Expand Down Expand Up @@ -148,6 +158,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)
Expand All @@ -166,6 +177,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)
Expand Down
Loading