Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
6210d7d
Draw plugin refactored using adapters
dannyleech Jul 1, 2026
d1a7fa6
Maplibre undo stack fixes
dannyleech Jul 2, 2026
5f4af6b
Refactored to rduce function line count
dannyleech Jul 2, 2026
3ec4ab9
Colour default consistency fixes between adapters
dannyleech Jul 2, 2026
b016c10
Colour fixes
dannyleech Jul 2, 2026
b700ce7
Centralize touch target generation from config — both adapters now us…
dannyleech Jul 2, 2026
251a7ca
Export applyTouchVertexColors from touchHandlers
dannyleech Jul 2, 2026
84122f6
Consolidate keyboard nudge/step amounts to shared defaults
dannyleech Jul 2, 2026
8796f92
Consolidate keyboard nudge/step amounts to shared defaults.
dannyleech Jul 2, 2026
864c23e
ESM and UMD updated with unified draw plugin
dannyleech Jul 2, 2026
613faf7
ESM build sonar fixes
dannyleech Jul 2, 2026
e4f48e4
Consistent mouse pointer vertex marker
dannyleech Jul 2, 2026
8ee16ed
OL snap at tile buffers fix
dannyleech Jul 2, 2026
e2cc38e
Refactoring and de duplication
dannyleech Jul 2, 2026
b83a09f
Draw vertex display consistency fixes
dannyleech Jul 3, 2026
15730e9
Code simplification
dannyleech Jul 3, 2026
fcc5e39
Maplibre keyboard crosshair marker apearing on shortcut fix
dannyleech Jul 3, 2026
cef4144
Midpoint highlight fix
dannyleech Jul 3, 2026
9407d83
createDrawMode.js tests
dannyleech Jul 3, 2026
e2f966d
Edit vertex mode code splitting plus tests
dannyleech Jul 3, 2026
20148ba
Draw mode code splitting and tests
dannyleech Jul 3, 2026
13ef52c
Remaning mode tests added
dannyleech Jul 3, 2026
abc210a
Utils tests added
dannyleech Jul 3, 2026
422a2fe
mapboxDraw.js tests added
dannyleech Jul 3, 2026
d1f7f6b
mapboxSnap code splitting and tests
dannyleech Jul 3, 2026
7fecf1c
MaplibreDrawAdpater.js tests and event consts
dannyleech Jul 3, 2026
c5bfcd3
styles.js tests added
dannyleech Jul 3, 2026
346d574
loadDrawAdapter.js tests added
dannyleech Jul 3, 2026
0cbc07c
API method tests added
dannyleech Jul 3, 2026
d049287
spatial.js utils tests added
dannyleech Jul 3, 2026
d15b504
Remaining utils tests added
dannyleech Jul 3, 2026
ed25203
Remaining route files tests added
dannyleech Jul 3, 2026
d1818ed
Shared adapter events and OpenLayers refactor plus tests
dannyleech Jul 5, 2026
f1dddd8
Edit and utils tests
dannyleech Jul 6, 2026
4e2be40
OpenLayers snap geometry, core and orchestration tests added
dannyleech Jul 6, 2026
47fdc8e
Snap tests added
dannyleech Jul 6, 2026
29050c9
EditMode line 96 test added
dannyleech Jul 6, 2026
4c17095
Edit mode partial coverage tests added
dannyleech Jul 6, 2026
81fcac1
Snap mode remaining partial tests added
dannyleech Jul 6, 2026
c0c65ff
Remaing partial coverage added for draw functionlaity
dannyleech Jul 6, 2026
e3d1938
Remaining partial test coverage added
dannyleech Jul 6, 2026
399cf9a
Draw plugin moved out of beta folder
dannyleech Jul 6, 2026
f850822
DrawInit.jsx extra crossHair test added
dannyleech Jul 6, 2026
df7eaf6
Sonar cloud fixes
dannyleech Jul 6, 2026
c6c6f90
Persist snap state between modes
dannyleech Jul 6, 2026
2d4966c
Persist snap between all draw modes
dannyleech Jul 6, 2026
54b3549
Sonar cloud simplification warnings for two functions
dannyleech Jul 6, 2026
71d0255
Keyboard shortcuts for drawing added
dannyleech Jul 6, 2026
8429f86
Draw keyboard controls registered
dannyleech Jul 6, 2026
69d1443
Geometry validation basics
dannyleech Jul 7, 2026
a8b628f
Realtime invalid stroke style
dannyleech Jul 7, 2026
829fcad
Geometry validation refeactoring
dannyleech Jul 7, 2026
ad46ca3
Lint fixes
dannyleech Jul 7, 2026
90df8d4
govuk plugin updated for songle draw plugin
dannyleech Jul 8, 2026
a101dc4
Merge main
dannyleech Jul 8, 2026
f774375
Split basics demo added
dannyleech Jul 9, 2026
e87cbf8
Split extend line fix
dannyleech Jul 9, 2026
30a4402
Split tests updated
dannyleech Jul 9, 2026
7d25664
Snap tests updated
dannyleech Jul 9, 2026
165ed01
Snap indicators and split line fix
dannyleech Jul 9, 2026
c348a7c
Split done button disabling
dannyleech Jul 9, 2026
e09433e
Split invalid disable complete
dannyleech Jul 9, 2026
e139844
Comment updated
dannyleech Jul 9, 2026
f0ea94e
OLDrawManager _manager ref fixed
dannyleech Jul 9, 2026
eab7205
geometry change kind prop renamed phase
dannyleech Jul 9, 2026
8a54a82
Split amened to use exisitng geometryValidation mechanism
dannyleech Jul 10, 2026
5efa957
Comment shortened
dannyleech Jul 10, 2026
29af129
Merge shapes added
dannyleech Jul 10, 2026
3e8d9a3
Split and merge minor refactor
dannyleech Jul 10, 2026
4d62c40
Minor formatting fix
dannyleech Jul 10, 2026
42696b2
OL Split and merge basics added
dannyleech Jul 10, 2026
cabf728
Openlayers merge fixes
dannyleech Jul 10, 2026
557df47
draw-ol.js demo minor consistency amends
dannyleech Jul 10, 2026
c3f74f9
Merge main
dannyleech Jul 15, 2026
02aa128
package.json unsed deps removed
dannyleech Jul 15, 2026
2cee435
Merge main
dannyleech Jul 15, 2026
6e69711
Merge main
dannyleech Jul 16, 2026
07e5a2c
Merge main
dannyleech Jul 17, 2026
65e2ca6
Megre main
dannyleech Aug 3, 2026
6ee6b9f
Merge main
dannyleech Aug 3, 2026
71da66d
Merge main
dannyleech Aug 3, 2026
1a0d65d
Rubberband fix when switching to touch and using the move control
dannyleech Aug 3, 2026
0a5ce4a
Move control wired up to draw plugin
dannyleech Aug 3, 2026
f516f8f
Keyboard interacytion focus fix on move control
dannyleech Aug 3, 2026
af6b1b5
Move control keyboard events
dannyleech Aug 4, 2026
1b047a2
MapLibre move control snapping fix
dannyleech Aug 4, 2026
8863462
placeCount renamed numVertices plus onGeometryChnage amends
dannyleech Aug 4, 2026
11c4a22
Hint added to show validation reason
dannyleech Aug 4, 2026
7190fd9
onGeometryChange callback event consolidation
dannyleech Aug 4, 2026
e0eaaf8
Import MIN_VERTICES plus minor amends
dannyleech Aug 5, 2026
6b93dca
Menu cross hair fix
dannyleech Aug 5, 2026
bef02c5
Docusuarus draw demo fixes
dannyleech Aug 5, 2026
de3c743
Maplibre colour and size config fixes and demos updated
dannyleech Aug 5, 2026
03e988d
Merge main
dannyleech Aug 5, 2026
1295edf
Maplibre edit cancel revert fix
dannyleech Aug 5, 2026
873c83e
Sonar cloud fixes
dannyleech Aug 5, 2026
bbab8c1
Validation error message amend
dannyleech Aug 5, 2026
77e3ab5
Sonar missing else fix
dannyleech Aug 5, 2026
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
7 changes: 4 additions & 3 deletions assets/templates/draw-tools.njk
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<script src="/plugin-assets/%40defra%2Finteractive-map/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/providers/maplibre/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/interact/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/beta/draw-ml/dist/umd/index.js"></script>
<script src="/plugin-assets/%40defra%2Finteractive-map/plugins/draw/dist/umd/index.js"></script>

<script>
const DRAW_LAYERS = ['fill-inactive.cold', 'stroke-inactive.cold']
Expand All @@ -48,7 +48,7 @@
deselectOnClickOutside: true
})

const drawPlugin = defra.drawMLPlugin({
const drawPlugin = defra.drawPlugin({
snapLayers: ['building-3d']
})

Expand All @@ -75,7 +75,7 @@

interactiveMap.addButton('drawTools', {
label: 'Draw tools',
mobile: { slot: 'bottom-right' },
mobile: { slot: 'top-middle' },
tablet: { slot: 'top-middle' },
desktop: { slot: 'top-middle' },
menuItems: [
Expand Down Expand Up @@ -150,6 +150,7 @@
var singleFeature = e.selectedFeatures.length === 1
var anyFeature = e.selectedFeatures.length > 0
var isDrawFeature = singleFeature && DRAW_LAYERS.includes(e.selectedFeatures[0].layerId)
var isPolygon = singleFeature && e.selectedFeatures[0].geometryType === 'Polygon'
var allDrawFeatures = anyFeature && e.selectedFeatures.every(function (f) { return DRAW_LAYERS.includes(f.layerId) })
selectedFeatureIds = e.selectedFeatures.map(function (f) { return f.featureId })
interactiveMap.toggleButtonState('drawPolygon', 'disabled', singleFeature)
Expand Down
4 changes: 2 additions & 2 deletions demo/DemoMapDrawTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function MapInner () {
import('../src/index.js'),
import('../providers/maplibre/src/index.js'),
import('../plugins/interact/src/index.js'),
import('../plugins/beta/draw-ml/src/index.js')
import('../plugins/draw/src/index.js')
]).then(([
{ default: InteractiveMap },
{ default: maplibreProvider },
Expand Down Expand Up @@ -70,7 +70,7 @@ function MapInner () {

interactiveMap.addButton('drawTools', {
label: 'Draw tools',
mobile: { slot: 'bottom-right' },
mobile: { slot: 'top-middle' },
tablet: { slot: 'top-middle' },
desktop: { slot: 'top-middle' },
menuItems: [
Expand Down
2 changes: 1 addition & 1 deletion demo/DemoMapSelectFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function MapInner () {
import('../src/index.js'),
import('../providers/maplibre/src/index.js'),
import('../plugins/interact/src/index.js'),
import('../plugins/beta/datasets/src/index.js')
import('../plugins/datasets/src/index.js')
]).then(([
{ default: InteractiveMap },
{ default: maplibreProvider },
Expand Down
90 changes: 79 additions & 11 deletions demo/js/draw-ol.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import openLayersProvider from '/providers/beta/openlayers/src/index.js'
import openNamesProvider from '/providers/beta/open-names/src/index.js'
// Plugins
import mapStylesPlugin from '/plugins/beta/map-styles/src/index.js'
import createDrawPlugin from '/plugins/beta/draw-ol/src/index.js'
import createDrawPlugin from '/plugins/draw/src/index.js'
import searchPlugin from '/plugins/search/src/index.js'
import createInteractPlugin from '/plugins/interact/src/index.js'

Expand All @@ -28,9 +28,22 @@ const interactPlugin = createInteractPlugin({
// debug: true
})

// Rough approximation of the England/Wales border as a line of easting —
// good enough for a demo, not for anything that actually needs to be accurate.
const WALES_BORDER_EASTING = 337300

const getAllCoordinates = (coordinates) =>
Array.isArray(coordinates[0][0]) ? coordinates.flatMap(getAllCoordinates) : coordinates

const isEastOfWalesBorder = (geometry) =>
getAllCoordinates(geometry.coordinates).every(([lng]) => lng > WALES_BORDER_EASTING)

const drawPlugin = createDrawPlugin({
// snapLayers: ['OS/NGD/lnd_fts_land/Arable Or Grazing Land']
snapLayers: ['OS/TopographicArea_1/Agricultural Land', 'OS/TopographicLine/Building Outline']
snapLayers: ['OS/TopographicArea_1/Agricultural Land', 'OS/TopographicLine/Building Outline'],
onGeometryChange: (event) => { console.log(event.phase); return {
valid: isEastOfWalesBorder(event.feature.geometry),
reason: 'Points must be placed east of the England/Wales border'
}}
})

const interactiveMap = new InteractiveMap('map', {
Expand Down Expand Up @@ -75,7 +88,7 @@ interactiveMap.on('map:ready', function (e) {
interactPlugin.enable()
interactiveMap.addButton('geometryActions', {
label: 'Draw tools',
mobile: { slot: 'bottom-right', order: 3 },
mobile: { slot: 'top-middle', order: 3 },
tablet: { slot: 'top-middle', order: 3 },
desktop: { slot: 'top-middle', order: 3 },
menuItems: [{
Expand All @@ -101,8 +114,8 @@ interactiveMap.on('map:ready', function (e) {
})
}
},{
id: 'editFeature',
label: 'Edit feature',
id: 'editShape',
label: 'Edit shape',
iconSvgContent: '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/>',
isDisabled: true,
onClick: function (e) {
Expand All @@ -113,6 +126,25 @@ interactiveMap.on('map:ready', function (e) {
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
interactPlugin.disable()
}
},{
id: 'splitShape',
label: 'Split shape',
iconSvgContent: '<path d="M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3"/><path d="M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3"/><line x1="12" x2="12" y1="4" y2="20"/>',
isDisabled: true,
onClick: function (e) {
drawPlugin.split(selectedFeatureIds[0])
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
interactPlugin.disable()
}
},{
id: 'mergeShapes',
label: 'Merge shapes',
iconSvgContent: '<path d="M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v3a1 1 0 0 0 1 1h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2v-3a1 1 0 0 0-1-1z"/>',
isDisabled: true,
onClick: function (e) {
drawPlugin.merge(selectedFeatureIds)
interactPlugin.clear()
}
},{
id: 'deleteFeature',
label: 'Delete feature',
Expand All @@ -124,7 +156,9 @@ interactiveMap.on('map:ready', function (e) {
interactPlugin.clear()
interactiveMap.toggleButtonState('drawPolygon', 'disabled', false)
interactiveMap.toggleButtonState('drawLine', 'disabled', false)
interactiveMap.toggleButtonState('editFeature', 'disabled', true)
interactiveMap.toggleButtonState('editShape', 'disabled', true)
interactiveMap.toggleButtonState('splitShape', 'disabled', true)
interactiveMap.toggleButtonState('mergeShapes', 'disabled', true)
interactiveMap.toggleButtonState('deleteFeature', 'disabled', true)
}
}]
Expand All @@ -146,13 +180,12 @@ interactiveMap.on('draw:ready', function () {
})

interactiveMap.on('draw:started', function (e) {
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
// console.log('draw:started')
interactPlugin.disable()
})

interactiveMap.on('draw:editstart', function (e) {
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
interactPlugin.disable()
console.log('draw:editstart', e)
})

interactiveMap.on('draw:created', function (e) {
Expand All @@ -177,16 +210,51 @@ interactiveMap.on('draw:cancelled', function (e) {
interactPlugin.enable()
})

interactiveMap.on('draw:split', function (e) {
// Delete the original polygon
drawPlugin.deleteFeature([e.originalFeatureId])

// Add the two new split features with IDs based on the original
e.featureCollection.features.forEach(function (feature, index) {
const newId = e.originalFeatureId + (index === 0 ? '-a' : '-b')
drawPlugin.addFeature({
id: newId,
type: feature.type,
geometry: feature.geometry,
properties: feature.properties
})
})

interactPlugin.clear()
})

interactiveMap.on('draw:merge', function (e) {
// Delete the original polygons
drawPlugin.deleteFeature(e.originalFeatureIds)

// Add the single merged feature, keeping the first original's id
drawPlugin.addFeature({
id: e.originalFeatureIds[0],
type: e.feature.type,
geometry: e.feature.geometry,
properties: e.feature.properties
})
})


interactiveMap.on('interact:selectionchange', function (e) {
const singleFeature = e.selectedFeatures.length === 1
const anyFeature = e.selectedFeatures.length > 0
const isDrawFeature = singleFeature && e.selectedFeatures[0].layerId === 'draw'
const isPolygon = singleFeature && e.selectedFeatures[0].geometryType === 'Polygon'
const allDrawFeatures = anyFeature && e.selectedFeatures.every(function (f) { return f.layerId === 'draw' })
const canMerge = allDrawFeatures && e.contiguous && e.selectedFeatures.length > 1
selectedFeatureIds = e.selectedFeatures.map(function (f) { return f.featureId })
interactiveMap.toggleButtonState('drawPolygon', 'disabled', !!singleFeature)
interactiveMap.toggleButtonState('drawLine', 'disabled', !!singleFeature)
interactiveMap.toggleButtonState('editFeature', 'disabled', !isDrawFeature)
interactiveMap.toggleButtonState('editShape', 'disabled', !isDrawFeature)
interactiveMap.toggleButtonState('splitShape', 'disabled', !isPolygon)
interactiveMap.toggleButtonState('mergeShapes', 'disabled', !canMerge)
interactiveMap.toggleButtonState('deleteFeature', 'disabled', !allDrawFeatures)
})

Expand Down
96 changes: 87 additions & 9 deletions demo/js/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import openNamesProvider from '/providers/beta/open-names/src/index.js'
// Plugins
import mapStylesPlugin from '/plugins/beta/map-styles/src/index.js'
import createDatasetsPlugin from '/plugins/datasets/src/index.js'
import createDrawPlugin from '/plugins/beta/draw-ml/src/index.js'
import createDrawPlugin from '/plugins/draw/src/index.js'
import scaleBarPlugin from '/plugins/beta/scale-bar/src/index.js'
import searchPlugin from '/plugins/search/src/index.js'
import createInteractPlugin from '/plugins/interact/src/index.js'
Expand Down Expand Up @@ -40,8 +40,26 @@ const interactPlugin = createInteractPlugin({
deselectOnClickOutside: true
})

// Rough approximation of the England/Wales border as a line of longitude —
// good enough for a demo, not for anything that actually needs to be accurate.
const WALES_BORDER_LONGITUDE = -3.0

const getAllCoordinates = (coordinates) =>
Array.isArray(coordinates[0][0]) ? coordinates.flatMap(getAllCoordinates) : coordinates

const isEastOfWalesBorder = (geometry) =>
getAllCoordinates(geometry.coordinates).every(([lng]) => lng > WALES_BORDER_LONGITUDE)

const drawPlugin = createDrawPlugin({
snapLayers: ['OS/TopographicArea_1/Agricultural Land', 'OS/TopographicLine/Building Outline']
snapLayers: ['OS/TopographicArea_1/Agricultural Land', 'OS/TopographicLine/Building Outline'],
// onGeometryChange: (event) => ({
// valid: isEastOfWalesBorder(event.feature.geometry),
// reason: 'Points must be placed east of the England/Wales border'
// })
onGeometryChange: (event) => { console.log(event.phase); return {
valid: isEastOfWalesBorder(event.feature.geometry),
reason: 'Points must be placed east of the England/Wales border'
}}
})

const datasetsPlugin = createDatasetsPlugin({
Expand Down Expand Up @@ -182,8 +200,8 @@ interactiveMap.on('map:ready', function (e) {
})
}
},{
id: 'editFeature',
label: 'Edit feature',
id: 'editShape',
label: 'Edit shape',
iconSvgContent: '<path d="M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/><path d="m15 5 4 4"/>',
isDisabled: true,
onClick: function (e) {
Expand All @@ -194,6 +212,25 @@ interactiveMap.on('map:ready', function (e) {
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
interactPlugin.disable()
}
},{
id: 'splitShape',
label: 'Split shape',
iconSvgContent: '<path d="M8 19H5c-1 0-2-1-2-2V7c0-1 1-2 2-2h3"/><path d="M16 5h3c1 0 2 1 2 2v10c0 1-1 2-2 2h-3"/><line x1="12" x2="12" y1="4" y2="20"/>',
isDisabled: true,
onClick: function (e) {
drawPlugin.split(selectedFeatureIds[0])
interactiveMap.toggleButtonState('geometryActions', 'hidden', true)
interactPlugin.disable()
}
},{
id: 'mergeShapes',
label: 'Merge shapes',
iconSvgContent: '<path d="M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2v3a1 1 0 0 0 1 1h3a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2v-3a1 1 0 0 0-1-1z"/>',
isDisabled: true,
onClick: function (e) {
drawPlugin.merge(selectedFeatureIds)
interactPlugin.clear()
}
},{
id: 'deleteFeature',
label: 'Delete feature',
Expand All @@ -205,7 +242,9 @@ interactiveMap.on('map:ready', function (e) {
interactPlugin.clear()
interactiveMap.toggleButtonState('drawPolygon', 'disabled', false)
interactiveMap.toggleButtonState('drawLine', 'disabled', false)
interactiveMap.toggleButtonState('editFeature', 'disabled', true)
interactiveMap.toggleButtonState('editShape', 'disabled', true)
interactiveMap.toggleButtonState('splitShape', 'disabled', true)
interactiveMap.toggleButtonState('mergeShapes', 'disabled', true)
interactiveMap.toggleButtonState('deleteFeature', 'disabled', true)
}
}]
Expand Down Expand Up @@ -242,7 +281,7 @@ interactiveMap.on('draw:ready', function () {
})

interactiveMap.on('draw:started', function (e) {
console.log('draw:started')
// console.log('draw:started')
interactPlugin.disable()
})

Expand All @@ -251,7 +290,7 @@ interactiveMap.on('draw:editstart', function (e) {
})

interactiveMap.on('draw:created', function (e) {
console.log('draw:created', e)
// console.log('draw:created', e)
interactiveMap.toggleButtonState('geometryActions', 'hidden', false)
interactPlugin.enable()
})
Expand All @@ -261,7 +300,7 @@ interactiveMap.on('draw:updated', function (e) {
})

interactiveMap.on('draw:edited', function (e) {
console.log('draw:edited', e) // Should be editcomplete
// console.log('draw:edited', e)
interactiveMap.toggleButtonState('geometryActions', 'hidden', false)
interactPlugin.enable()
})
Expand All @@ -278,14 +317,53 @@ interactiveMap.on('interact:selectionchange', function (e) {
const singleFeature = e.selectedFeatures.length === 1
const anyFeature = e.selectedFeatures.length > 0
const isDrawFeature = singleFeature && drawLayers.includes(e.selectedFeatures[0].layerId)
const isPolygon = singleFeature && e.selectedFeatures[0].geometryType === 'Polygon'
const allDrawFeatures = anyFeature && e.selectedFeatures.every(function (f) { return drawLayers.includes(f.layerId) })
const canMerge = allDrawFeatures && e.contiguous && e.selectedFeatures.length > 1
selectedFeatureIds = e.selectedFeatures.map(function (f) { return f.featureId })
interactiveMap.toggleButtonState('drawPolygon', 'disabled', !!singleFeature)
interactiveMap.toggleButtonState('drawLine', 'disabled', !!singleFeature)
interactiveMap.toggleButtonState('editFeature', 'disabled', !isDrawFeature)
interactiveMap.toggleButtonState('editShape', 'disabled', !isDrawFeature)
interactiveMap.toggleButtonState('splitShape', 'disabled', !isPolygon)
interactiveMap.toggleButtonState('mergeShapes', 'disabled', !canMerge)
interactiveMap.toggleButtonState('deleteFeature', 'disabled', !allDrawFeatures)
})

interactiveMap.on('draw:split', function (e) {
// console.log('draw:split', { originalFeatureId: e.originalFeatureId, newFeatures: e.featureCollection.features })

// Delete the original polygon
drawPlugin.deleteFeature([e.originalFeatureId])

// Add the two new split features with IDs based on the original
e.featureCollection.features.forEach(function (feature, index) {
const newId = e.originalFeatureId + (index === 0 ? '-a' : '-b')
drawPlugin.addFeature({
id: newId,
type: feature.type,
geometry: feature.geometry,
properties: feature.properties
})
})

interactPlugin.clear()
})

interactiveMap.on('draw:merge', function (e) {
// console.log('draw:merge', { originalFeatureIds: e.originalFeatureIds, feature: e.feature })

// Delete the original polygons
drawPlugin.deleteFeature(e.originalFeatureIds)

// Add the single merged feature, keeping the first original's id
drawPlugin.addFeature({
id: e.originalFeatureIds[0],
type: e.feature.type,
geometry: e.feature.geometry,
properties: e.feature.properties
})
})

interactiveMap.on('interact:markerchange', function (e) {
// console.log('interact:markerchange', e)
})
Expand Down
Loading
Loading