@defra/interactive-map 0.0.26-alpha → 0.0.28-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/css/index.css +1 -1
  2. package/dist/esm/im-core.js +1 -1
  3. package/dist/esm/im-shell.js +1 -1
  4. package/dist/umd/im-core.js +1 -1
  5. package/dist/umd/index.js +1 -1
  6. package/docs/assets/css/docusaurus.scss +4 -0
  7. package/package.json +1 -1
  8. package/plugins/beta/draw-ml/dist/esm/im-draw-ml-plugin.js +1 -1
  9. package/plugins/beta/draw-ml/dist/umd/im-draw-ml-plugin.js +1 -1
  10. package/plugins/beta/draw-ml/src/defaults.js +14 -14
  11. package/plugins/beta/draw-ml/src/mapboxDraw.js +5 -0
  12. package/plugins/beta/draw-ml/src/mapboxSnap.js +1 -1
  13. package/plugins/beta/draw-ml/src/modes/editVertex/touchHandlers.js +10 -2
  14. package/plugins/beta/draw-ml/src/modes/editVertexMode.js +2 -0
  15. package/plugins/beta/draw-ml/src/reducer.js +4 -1
  16. package/plugins/beta/draw-ml/src/styles.js +42 -39
  17. package/plugins/beta/draw-ol/dist/css/index.css +13 -0
  18. package/plugins/beta/draw-ol/dist/esm/DrawMode.js +1 -0
  19. package/plugins/beta/draw-ol/dist/esm/EditMode.js +1 -0
  20. package/plugins/beta/draw-ol/dist/esm/geometryHelpers.js +1 -0
  21. package/plugins/beta/draw-ol/dist/esm/im-draw-ol-plugin.js +1 -0
  22. package/plugins/beta/draw-ol/dist/esm/index.js +1 -0
  23. package/plugins/beta/draw-ol/src/DrawInit.jsx +67 -0
  24. package/plugins/beta/draw-ol/src/api/addFeature.js +29 -0
  25. package/plugins/beta/draw-ol/src/api/deleteFeature.js +11 -0
  26. package/plugins/beta/draw-ol/src/api/editFeature.js +50 -0
  27. package/plugins/beta/draw-ol/src/api/newLine.js +44 -0
  28. package/plugins/beta/draw-ol/src/api/newPolygon.js +44 -0
  29. package/plugins/beta/draw-ol/src/core/OLDrawManager.js +150 -0
  30. package/plugins/beta/draw-ol/src/core/featureStore.js +65 -0
  31. package/plugins/beta/draw-ol/src/core/styles.js +98 -0
  32. package/plugins/beta/draw-ol/src/core/undoStack.js +31 -0
  33. package/plugins/beta/draw-ol/src/defaults.js +16 -0
  34. package/plugins/beta/draw-ol/src/draw/DrawMode.js +113 -0
  35. package/plugins/beta/draw-ol/src/draw/drawInput.js +199 -0
  36. package/plugins/beta/draw-ol/src/draw.scss +17 -0
  37. package/plugins/beta/draw-ol/src/edit/EditMode.js +424 -0
  38. package/plugins/beta/draw-ol/src/edit/keyboardHandler.js +227 -0
  39. package/plugins/beta/draw-ol/src/edit/midpointLayer.js +57 -0
  40. package/plugins/beta/draw-ol/src/edit/touchHandler.js +171 -0
  41. package/plugins/beta/draw-ol/src/edit/undoOps.js +95 -0
  42. package/plugins/beta/draw-ol/src/edit/vertexHitTest.js +72 -0
  43. package/plugins/beta/draw-ol/src/edit/vertexLayer.js +49 -0
  44. package/plugins/beta/draw-ol/src/edit/vertexOps.js +99 -0
  45. package/plugins/beta/draw-ol/src/events.js +114 -0
  46. package/plugins/beta/draw-ol/src/index.js +12 -0
  47. package/plugins/beta/draw-ol/src/manifest.js +121 -0
  48. package/plugins/beta/draw-ol/src/olDraw.js +38 -0
  49. package/plugins/beta/draw-ol/src/reducer.js +41 -0
  50. package/plugins/beta/draw-ol/src/snap/snapEngine.js +109 -0
  51. package/plugins/beta/draw-ol/src/snap/snapGeometry.js +200 -0
  52. package/plugins/beta/draw-ol/src/snap/snapIndicator.js +81 -0
  53. package/plugins/beta/draw-ol/src/snap/snapInteraction.js +56 -0
  54. package/plugins/beta/draw-ol/src/snap/snapManager.js +90 -0
  55. package/plugins/beta/draw-ol/src/utils/flattenStyleProperties.js +47 -0
  56. package/plugins/beta/draw-ol/src/utils/geometryHelpers.js +97 -0
  57. package/plugins/beta/draw-ol/src/utils/olCoords.js +35 -0
  58. package/plugins/beta/draw-ol/src/utils/resolveColors.js +39 -0
  59. package/plugins/beta/draw-ol/src/utils/spatial.js +28 -0
  60. package/plugins/beta/draw-ol/src/utils/touchTarget.js +61 -0
  61. package/plugins/beta/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  62. package/plugins/beta/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  63. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  64. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  65. package/plugins/interact/src/defaults.js +1 -0
  66. package/plugins/interact/src/hooks/useInteractionHandlers.js +150 -43
  67. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +240 -8
  68. package/plugins/interact/src/reducer.js +7 -0
  69. package/plugins/interact/src/reducer.test.js +16 -0
  70. package/providers/beta/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  71. package/providers/beta/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  72. package/providers/beta/openlayers/dist/umd/index.js +1 -1
  73. package/providers/beta/openlayers/src/appEvents.js +9 -13
  74. package/providers/beta/openlayers/src/appEvents.test.js +25 -17
  75. package/providers/beta/openlayers/src/mapEvents.js +32 -16
  76. package/providers/beta/openlayers/src/mapEvents.test.js +43 -10
  77. package/providers/beta/openlayers/src/openlayersProvider.js +45 -26
  78. package/providers/beta/openlayers/src/openlayersProvider.test.js +12 -34
  79. package/providers/beta/openlayers/src/utils/highlightFeatures.js +245 -0
  80. package/providers/beta/openlayers/src/utils/hoverCursor.js +65 -0
  81. package/providers/beta/openlayers/src/utils/hoverCursor.test.js +235 -0
  82. package/providers/beta/openlayers/src/utils/openLayersFixes.js +11 -0
  83. package/providers/beta/openlayers/src/utils/openLayersFixes.test.js +53 -0
  84. package/providers/beta/openlayers/src/utils/queryFeatures.js +77 -0
  85. package/providers/beta/openlayers/src/utils/queryFeatures.test.js +181 -0
  86. package/providers/beta/openlayers/src/utils/tileLayers.js +19 -1
  87. package/providers/beta/openlayers/src/utils/tileLayers.test.js +74 -3
  88. package/providers/beta/openlayers/src/utils/vtTileFragments.js +86 -0
  89. package/rollup.esm.mjs +6 -0
  90. package/src/App/components/Hints/Hints.test.jsx +2 -2
  91. package/src/App/components/PopupMenu/PopupMenu.module.scss +6 -0
  92. package/src/App/controls/keyboardActions.js +2 -2
  93. package/src/App/controls/keyboardMappings.js +1 -2
  94. package/src/App/controls/keyboardShortcuts.js +5 -3
  95. package/src/App/controls/keyboardShortcuts.test.js +24 -0
  96. package/src/InteractiveMap/InteractiveMap.js +38 -10
  97. package/src/InteractiveMap/InteractiveMap.test.js +282 -356
  98. package/src/InteractiveMap/deviceChecker.js +3 -2
  99. package/src/InteractiveMap/deviceChecker.test.js +7 -10
  100. package/src/InteractiveMap/historyManager.js +7 -0
  101. package/src/InteractiveMap/historyManager.test.js +11 -0
  102. package/src/config/defaults.js +1 -1
  103. package/src/utils/htmlToPlainText.js +11 -0
  104. package/src/utils/htmlToPlainText.test.js +5 -0
  105. package/webpack.dev.mjs +3 -1
@@ -1,17 +1,17 @@
1
1
  export const DEFAULTS = {
2
- editColorsForeground: { light: 'rgba(29,112,184,1)', dark: '#ffffff' },
3
- editColorsBackground: { light: '#ffffff', dark: 'rgba(11,12,12,1)' },
4
- editColorsHalo: { light: 'rgba(11,12,12,1)', dark: '#ffffff' },
5
- splitInvalidColors: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
6
- splitValidColors: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
7
- stroke: 'rgba(212,53,28,1)',
2
+ editStroke: { light: 'rgba(29,112,184,1)', dark: '#ffffff' },
3
+ editVertex: { light: 'rgba(29,112,184,1)', dark: '#ffffff' },
4
+ editMidpoint: { light: 'rgba(29,112,184,1)', dark: '#ffffff' },
5
+ editHalo: { light: '#ffffff', dark: 'rgba(11,12,12,1)' },
6
+ editActive: { light: 'rgba(11,12,12,1)', dark: '#ffffff' },
7
+ splitInvalid: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
8
+ splitValid: { light: 'rgba(29,112,184,1)', dark: 'rgba(29,112,184,1)' },
9
+ shapeStroke: 'rgba(212,53,28,1)',
10
+ shapeFill: 'rgba(212,53,28,0.1)',
8
11
  strokeWidth: 2,
9
- fill: 'rgba(212,53,28,0.1)',
10
- snapLayers: [],
11
- snapColors: {
12
- vertex: 'rgba(212,53,28,1)',
13
- midpoint: 'rgba(40,161,151,1)',
14
- edge: 'rgba(29,112,184,1)'
15
- },
16
- snapRadius: 10
12
+ snapVertex: 'rgba(212,53,28,1)',
13
+ snapMidpoint: 'rgba(40,161,151,1)',
14
+ snapEdge: 'rgba(29,112,184,1)',
15
+ snapRadius: 10,
16
+ snapLayers: []
17
17
  }
@@ -6,6 +6,7 @@ import { DrawLineMode } from './modes/drawLineMode.js'
6
6
  import { createDrawStyles, updateDrawStyles } from './styles.js'
7
7
  import { initMapLibreSnap } from './mapboxSnap.js'
8
8
  import { createUndoStack } from './undoStack.js'
9
+ import { applyTouchVertexColors } from './modes/editVertex/touchHandlers.js'
9
10
 
10
11
  /**
11
12
  * Creates and manages a MapLibre/Mapbox Draw control instance configured for polygon editing.
@@ -90,6 +91,7 @@ export const createMapboxDraw = ({ mapStyle, mapProvider, events, eventBus, snap
90
91
 
91
92
  // We need a reference to this
92
93
  mapProvider.draw = draw
94
+ map._drawCurrentMapStyle = mapStyle
93
95
  // Initialize snap as disabled (matches initialState.snap = false)
94
96
  mapProvider.snapEnabled = false
95
97
  // Initialize undo stack (also stored on map for mode access)
@@ -107,8 +109,11 @@ export const createMapboxDraw = ({ mapStyle, mapProvider, events, eventBus, snap
107
109
 
108
110
  // --- Update colour scheme ---
109
111
  const handleSetMapStyle = (e) => {
112
+ map._drawCurrentMapStyle = e
110
113
  map.once('idle', () => {
111
114
  updateDrawStyles(map, e)
115
+ const svg = map._drawEditContainer?.querySelector('[data-touch-vertex-target]')
116
+ applyTouchVertexColors(svg, e)
112
117
  })
113
118
  }
114
119
  eventBus.on(events.MAP_SET_STYLE, handleSetMapStyle)
@@ -184,7 +184,7 @@ export function initMapLibreSnap (map, draw, snapOptions = {}) {
184
184
  } = snapOptions
185
185
 
186
186
  // Apply global patches to MapboxSnap prototype
187
- applyMapboxSnapPatches({ ...DEFAULTS.snapColors, ...colors })
187
+ applyMapboxSnapPatches({ vertex: DEFAULTS.snapVertex, midpoint: DEFAULTS.snapMidpoint, edge: DEFAULTS.snapEdge, ...colors })
188
188
 
189
189
  // Clean up old snap instance's source and layer
190
190
  function cleanupOldSnap () {
@@ -7,11 +7,18 @@ import { isOnSVG } from './helpers.js'
7
7
 
8
8
  const touchVertexTarget = `
9
9
  <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd' style='display:none;position:absolute;top:50%;left:50%;margin:24px 0 0 -24px' class='touch-vertex-target' data-touch-vertex-target>
10
- <circle cx='24' cy='24' r='24' fill='currentColor'/>
11
- <path d="M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z" fill="#fff"/>
10
+ <circle cx='24' cy='24' r='24' fill='var(--touch-fill, #000)'/>
11
+ <path d="M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z" fill='var(--touch-gfx, #fff)'/>
12
12
  </svg>
13
13
  `
14
14
 
15
+ export const applyTouchVertexColors = (el, mapStyle) => {
16
+ if (!el) { return }
17
+ const dark = mapStyle?.mapColorScheme === 'dark'
18
+ el.style.setProperty('--touch-fill', dark ? '#ffffff' : '#000000')
19
+ el.style.setProperty('--touch-gfx', dark ? '#000000' : '#ffffff')
20
+ }
21
+
15
22
  export const touchHandlers = {
16
23
  addTouchVertexTarget (state) {
17
24
  let el = state.container.querySelector('[data-touch-vertex-target]')
@@ -20,6 +27,7 @@ export const touchHandlers = {
20
27
  el = state.container.querySelector('[data-touch-vertex-target]')
21
28
  }
22
29
  state.touchVertexTarget = el
30
+ applyTouchVertexColors(el, this.map._drawCurrentMapStyle)
23
31
  },
24
32
 
25
33
  updateTouchVertexTarget (state, point) {
@@ -63,6 +63,7 @@ export const EditVertexMode = {
63
63
  }
64
64
  this._ctx.store.render()
65
65
  }
66
+ this.map._drawEditContainer = options.container
66
67
  this.addTouchVertexTarget(state)
67
68
 
68
69
  // Clear any snap indicator when entering edit mode
@@ -441,6 +442,7 @@ export const EditVertexMode = {
441
442
  },
442
443
 
443
444
  onStop (state) {
445
+ this.map._drawEditContainer = null
444
446
  const h = this.handlers
445
447
  state.container.removeEventListener('pointerdown', h.pointerdown)
446
448
  state.container.removeEventListener('pointermove', h.pointermove)
@@ -11,10 +11,13 @@ const initialState = {
11
11
  undoStackLength: 0
12
12
  }
13
13
 
14
+ const DRAW_MODES = new Set(['draw_polygon', 'draw_line'])
15
+
14
16
  const setMode = (state, payload) => {
15
17
  return {
16
18
  ...state,
17
- mode: payload
19
+ mode: payload,
20
+ numVertecies: DRAW_MODES.has(payload) ? 0 : state.numVertecies
18
21
  }
19
22
  }
20
23
 
@@ -3,11 +3,11 @@ import { DEFAULTS } from './defaults.js'
3
3
 
4
4
  const getColorScheme = (mapStyle) => mapStyle.mapColorScheme ?? 'light'
5
5
 
6
- const getUserProp = (mapStyle, prop) => [
6
+ const getUserProp = (mapStyle, prop, defaultsKey = prop) => [
7
7
  'coalesce',
8
8
  ['get', `user_${prop}${mapStyle.id.charAt(0).toUpperCase() + mapStyle.id.slice(1)}`],
9
9
  ['get', `user_${prop}`],
10
- DEFAULTS[prop]
10
+ DEFAULTS[defaultsKey]
11
11
  ]
12
12
 
13
13
  // Inactive lines and fills
@@ -15,7 +15,7 @@ const fillInactive = (mapStyle) => ({
15
15
  id: 'fill-inactive',
16
16
  type: 'fill',
17
17
  filter: ['all', ['==', '$type', 'Polygon'], ['==', 'active', 'false']],
18
- paint: { 'fill-color': getUserProp(mapStyle, 'fill') }
18
+ paint: { 'fill-color': getUserProp(mapStyle, 'fill', 'shapeFill') }
19
19
  })
20
20
 
21
21
  const strokeInactive = (mapStyle) => ({
@@ -24,25 +24,25 @@ const strokeInactive = (mapStyle) => ({
24
24
  filter: ['all', ['any', ['==', '$type', 'Polygon'], ['==', '$type', 'LineString']], ['==', 'active', 'false'], ['!has', 'user_splitter']],
25
25
  layout: { 'line-cap': 'round', 'line-join': 'round' },
26
26
  paint: {
27
- 'line-color': getUserProp(mapStyle, 'stroke'),
27
+ 'line-color': getUserProp(mapStyle, 'stroke', 'shapeStroke'),
28
28
  'line-width': getUserProp(mapStyle, 'strokeWidth')
29
29
  }
30
30
  })
31
31
 
32
32
  // Active lines and fills
33
- const fillActive = (foregroundColor) => ({
33
+ const fillActive = (editStrokeColor) => ({
34
34
  id: 'fill-active',
35
35
  type: 'fill',
36
36
  filter: ['all', ['==', '$type', 'Polygon'], ['==', 'active', 'true']],
37
- paint: { 'fill-color': foregroundColor, 'fill-opacity': 0.1 }
37
+ paint: { 'fill-color': editStrokeColor, 'fill-opacity': 0.1 }
38
38
  })
39
39
 
40
- const strokeActive = (foregroundColor) => ({
40
+ const strokeActive = (editStrokeColor) => ({
41
41
  id: 'stroke-active',
42
42
  type: 'line',
43
43
  filter: ['all', ['any', ['==', '$type', 'Polygon'], ['==', '$type', 'LineString']], ['==', 'active', 'true'], ['!has', 'user_splitter']],
44
44
  layout: { 'line-cap': 'round', 'line-join': 'round' },
45
- paint: { 'line-color': foregroundColor, 'line-width': 2, 'line-opacity': 1 }
45
+ paint: { 'line-color': editStrokeColor, 'line-width': 2, 'line-opacity': 1 }
46
46
  })
47
47
 
48
48
  // Splitter line
@@ -72,63 +72,63 @@ const drawValidSplitter = (splitValidColor) => ({
72
72
  })
73
73
 
74
74
  // Dashed preview line
75
- const drawPreviewLine = (foregroundColor) => ({
75
+ const drawPreviewLine = (editStrokeColor) => ({
76
76
  id: 'stroke-preview-line',
77
77
  type: 'line',
78
78
  filter: ['all', ['==', '$type', 'LineString'], ['==', 'active', 'true'], ['!has', 'user_splitter']],
79
79
  layout: { 'line-cap': 'round', 'line-join': 'round' },
80
- paint: { 'line-color': foregroundColor, 'line-width': 2, 'line-dasharray': [0.2, 2], 'line-opacity': 1 }
80
+ paint: { 'line-color': editStrokeColor, 'line-width': 2, 'line-dasharray': [0.2, 2], 'line-opacity': 1 }
81
81
  })
82
82
 
83
83
  // Vertex layers
84
- const vertex = (foregroundColor) => ({
84
+ const vertex = (editVertexColor) => ({
85
85
  id: 'vertex',
86
86
  type: 'circle',
87
87
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex']],
88
- paint: { 'circle-radius': 6, 'circle-color': foregroundColor }
88
+ paint: { 'circle-radius': 6, 'circle-color': editVertexColor }
89
89
  })
90
90
 
91
- const vertexHalo = (backgroundColor, haloColor) => ({
91
+ const vertexHalo = (editHaloColor, editActiveColor) => ({
92
92
  id: 'vertex-halo',
93
93
  type: 'circle',
94
94
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'true']],
95
- paint: { 'circle-radius': 8, 'circle-stroke-width': 3, 'circle-color': backgroundColor, 'circle-stroke-color': haloColor }
95
+ paint: { 'circle-radius': 8, 'circle-stroke-width': 3, 'circle-color': editHaloColor, 'circle-stroke-color': editActiveColor }
96
96
  })
97
97
 
98
- const vertexActive = (foregroundColor) => ({
98
+ const vertexActive = (editVertexColor) => ({
99
99
  id: 'vertex-active',
100
100
  type: 'circle',
101
101
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'vertex'], ['==', 'active', 'true']],
102
- paint: { 'circle-radius': 6, 'circle-color': foregroundColor }
102
+ paint: { 'circle-radius': 6, 'circle-color': editVertexColor }
103
103
  })
104
104
 
105
105
  // Midpoints
106
- const midpoint = (foregroundColor) => ({
106
+ const midpoint = (editMidpointColor) => ({
107
107
  id: 'midpoint',
108
108
  type: 'circle',
109
109
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint']],
110
- paint: { 'circle-radius': 4, 'circle-color': foregroundColor }
110
+ paint: { 'circle-radius': 4, 'circle-color': editMidpointColor }
111
111
  })
112
112
 
113
- const midpointHalo = (backgroundColor, haloColor) => ({
113
+ const midpointHalo = (editHaloColor, editActiveColor) => ({
114
114
  id: 'midpoint-halo',
115
115
  type: 'circle',
116
116
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint'], ['==', 'active', 'true']],
117
- paint: { 'circle-radius': 6, 'circle-stroke-width': 3, 'circle-color': backgroundColor, 'circle-stroke-color': haloColor }
117
+ paint: { 'circle-radius': 6, 'circle-stroke-width': 3, 'circle-color': editHaloColor, 'circle-stroke-color': editActiveColor }
118
118
  })
119
119
 
120
- const midpointActive = (foregroundColor) => ({
120
+ const midpointActive = (editMidpointColor) => ({
121
121
  id: 'midpoint-active',
122
122
  type: 'circle',
123
123
  filter: ['all', ['==', '$type', 'Point'], ['==', 'meta', 'midpoint'], ['==', 'active', 'true']],
124
- paint: { 'circle-radius': 4, 'circle-color': foregroundColor }
124
+ paint: { 'circle-radius': 4, 'circle-color': editMidpointColor }
125
125
  })
126
126
 
127
- const circle = (foregroundColor) => ({
127
+ const circle = (editStrokeColor) => ({
128
128
  id: 'circle',
129
129
  type: 'line',
130
130
  filter: ['==', 'id', 'circle'],
131
- paint: { 'line-color': foregroundColor, 'line-width': 2, 'line-opacity': 0.8 }
131
+ paint: { 'line-color': editStrokeColor, 'line-width': 2, 'line-opacity': 0.8 }
132
132
  })
133
133
 
134
134
  const touchVertexIndicator = () => ({
@@ -139,27 +139,30 @@ const touchVertexIndicator = () => ({
139
139
  })
140
140
 
141
141
  const createDrawStyles = (mapStyle) => {
142
- const foregroundColor = DEFAULTS.editColorsForeground[getColorScheme(mapStyle)]
143
- const backgroundColor = DEFAULTS.editColorsBackground[getColorScheme(mapStyle)]
144
- const haloColor = DEFAULTS.editColorsHalo[getColorScheme(mapStyle)]
145
- const splitInvalidColor = DEFAULTS.splitInvalidColors[getColorScheme(mapStyle)]
146
- const splitValidColor = DEFAULTS.splitValidColors[getColorScheme(mapStyle)]
142
+ const scheme = getColorScheme(mapStyle)
143
+ const editStrokeColor = DEFAULTS.editStroke[scheme]
144
+ const editVertexColor = DEFAULTS.editVertex[scheme]
145
+ const editMidpointColor = DEFAULTS.editMidpoint[scheme]
146
+ const editHaloColor = DEFAULTS.editHalo[scheme]
147
+ const editActiveColor = DEFAULTS.editActive[scheme]
148
+ const splitInvalidColor = DEFAULTS.splitInvalid[scheme]
149
+ const splitValidColor = DEFAULTS.splitValid[scheme]
147
150
 
148
151
  return [
149
152
  fillInactive(mapStyle),
150
- fillActive(foregroundColor),
151
- strokeActive(foregroundColor),
153
+ fillActive(editStrokeColor),
154
+ strokeActive(editStrokeColor),
152
155
  strokeInactive(mapStyle),
153
156
  drawInvalidSplitter(splitInvalidColor),
154
157
  drawValidSplitter(splitValidColor),
155
- drawPreviewLine(foregroundColor),
156
- midpoint(foregroundColor),
157
- midpointHalo(backgroundColor, haloColor),
158
- midpointActive(foregroundColor),
159
- vertex(foregroundColor),
160
- vertexHalo(backgroundColor, haloColor),
161
- vertexActive(foregroundColor),
162
- circle(foregroundColor),
158
+ drawPreviewLine(editStrokeColor),
159
+ midpoint(editMidpointColor),
160
+ midpointHalo(editHaloColor, editActiveColor),
161
+ midpointActive(editMidpointColor),
162
+ vertex(editVertexColor),
163
+ vertexHalo(editHaloColor, editActiveColor),
164
+ vertexActive(editVertexColor),
165
+ circle(editStrokeColor),
163
166
  touchVertexIndicator()
164
167
  ]
165
168
  }
@@ -0,0 +1,13 @@
1
+ .im-draw-touch-target {
2
+ color: #3b82f6;
3
+ filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
4
+ cursor: grab;
5
+ }
6
+ .im-draw-touch-target:active {
7
+ cursor: grabbing;
8
+ }
9
+
10
+ .im-draw-button:focus-visible {
11
+ outline: 2px solid #3b82f6;
12
+ outline-offset: 2px;
13
+ }
@@ -0,0 +1 @@
1
+ import e from"ol/interaction/Draw.js";import{c as t,p as r,g as n}from"./geometryHelpers.js";var o=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),a=e=>{var n,{drawInteraction:a,options:i}=e,{container:d,addVertexButtonId:s,mapProvider:l,snap:p,onUndo:c}=i,g=i.interfaceType,v=null,u=null;a.on("drawstart",e=>{v=e.feature,u=null}),a.on("drawend",()=>{v=null,u=null}),a.on("drawabort",()=>{v=null,u=null});var y=(e=>{var{container:t,addVertexButtonId:r,olView:n,onUndo:a,getInterfaceType:i,setInterfaceType:d,clearLastCoord:s,updateRubberbanding:l,placeVertex:p}=e,c=()=>{"pointer"!==i()&&l()};null==n||n.on("change:center",c);var g=e=>{t.contains(document.activeElement)&&(o.has(e.key)?d("keyboard"):("Enter"===e.key&&(e.preventDefault(),d("keyboard"),p()),"z"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),null==a||a())))},v=e=>{r&&e.target.closest("#".concat(r))&&p()},u=e=>{"touch"!==e.pointerType&&(d("pointer"),s())},y=()=>{d("touch")},m=()=>{"pointer"!==i()&&l()};return globalThis.addEventListener("keydown",g),globalThis.addEventListener("click",v),t.addEventListener("pointerdown",u),t.addEventListener("touchstart",y,{passive:!0}),t.addEventListener("pointermove",m),{destroy(){null==n||n.un("change:center",c),globalThis.removeEventListener("keydown",g),globalThis.removeEventListener("click",v),t.removeEventListener("pointerdown",u),t.removeEventListener("touchstart",y),t.removeEventListener("pointermove",m)}}})({container:d,addVertexButtonId:s,olView:null===(n=a.getMap())||void 0===n?void 0:n.getView(),onUndo:c,getInterfaceType:()=>g,setInterfaceType:e=>{g=e},clearLastCoord:()=>{u=null},updateRubberbanding:()=>{if(v){var e=v.getGeometry();if(e.getCoordinates().length){var t=l.getCenter();((e,t)=>{if("LineString"===e.getType()){var r=[...e.getCoordinates()];r[r.length-1]=t,e.setCoordinates(r)}else if("Polygon"===e.getType()){var n=e.getCoordinates().map((e,r)=>{if(0!==r)return e;var n=[...e];return n[n.length-1]=t,n});e.setCoordinates(n)}})(e,"pointer"!==g&&p?p.apply(t):t)}}},placeVertex:()=>{var e=l.getCenter(),n="pointer"!==g&&p?p.apply(e):e;if(null==p||p.hideIndicator(),v){var o=v.getGeometry(),i=o.getCoordinates(),d="Polygon"===o.getType()?i[0]||[]:i;if(u&&u[0]===n[0]&&u[1]===n[1])return a.finishDrawing(),void(u=null);if(((e,n,o,a)=>{if("Polygon"!==a||o.length<4)return!1;var i=o[0],d=t(e,n),s=t(e,i);return!(!d||!s)&&r(d,s)<12})(a.getMap(),n,d,o.getType()))return void a.finishDrawing()}a.appendCoordinates([n]),u=n}});return{getInterfaceType:()=>g,destroy(){y.destroy()}}},i=t=>{var{map:r,manager:o,options:i}=t,{geometryType:d,featureId:s,properties:l={},container:p,interfaceType:c,addVertexButtonId:g,mapProvider:v,snap:u}=i,y=new e({type:d,style:o.styles.createSketchStyle(),stopClick:!0,snapTolerance:12});r.addInteraction(y);var m=null,f=()=>{if(m){var e=m.getGeometry(),t=n({type:d,coordinates:e.getCoordinates()}),r=Math.max(0,t.length-1);o.emit("vertexchange",{numVertices:r})}};y.on("drawstart",e=>{(m=e.feature).getGeometry().on("change",f)}),y.on("drawend",e=>{var t=e.feature;t.setId(String(s)),t.setProperties(l),o.store.source.addFeature(t);var r=o.store.toGeoJSON(t);o.emit("create",r)}),y.on("drawabort",()=>{o.emit("cancel")});var w=a({drawInteraction:y,options:{container:p,interfaceType:c,addVertexButtonId:g,mapProvider:v,snap:u,onUndo:()=>{y.removeLastPoint(),f()}}});return{done(){if(m){var e=m.getGeometry(),t=n({type:d,coordinates:e.getCoordinates()}),r="Polygon"===d?4:3;if(t.length<r)return}y.finishDrawing()},cancel(){y.abortDrawing()},undo(){y.removeLastPoint(),f()},destroy(){w.destroy(),r.removeInteraction(y),m=null}}};export{i as createDrawMode};
@@ -0,0 +1 @@
1
+ import e from"ol/interaction/Modify.js";import t from"ol/Collection.js";import r from"ol/source/Vector.js";import n from"ol/layer/Vector.js";import o from"ol/Feature.js";import a from"ol/geom/Point.js";import{a as i,g as d,b as l,d as s,e as c,c as v,p,f as x,n as u}from"./geometryHelpers.js";var y=(e,t)=>{e&&(e.style.setProperty("--draw-halo",t.editActive),e.style.setProperty("--draw-bg",t.editHalo),e.style.setProperty("--draw-primary",t.editVertex))},g=(e,t)=>{t&&e&&(e.style.left="".concat(t.x,"px"),e.style.top="".concat(t.y,"px"),e.style.display="block")},f=e=>{e&&(e.style.display="none")},m=e=>{if(!e)return!1;var t=e.parentNode;return t instanceof globalThis.SVGElement||null!=(null==t?void 0:t.ownerSVGElement)},h=(e,t,r,n)=>{var o=r-n,a=t[o];if(!a)return null;var i=e.getGeometry(),d={type:i.getType(),coordinates:i.getCoordinates()},s=l(d),v=0;for(var p of s){var x=p.closed?p.length:p.length-1;if(o<v+x){var u=o-v+1,y=p.start+u;return c(d,p.path).splice(u,0,[...a]),i.setCoordinates(d.coordinates),{insertedIndex:y}}v+=x}return null},I=(e,t,r)=>{var n=e.getGeometry(),o={type:n.getType(),coordinates:n.getCoordinates()},a=l(o),i=s(a,t);if(i){var d=c(o,i.segment.path);d[i.localIdx]=[...r],i.segment.closed&&0===i.localIdx&&(d[d.length-1]=[...r]),n.setCoordinates(o.coordinates)}},T=function(e,t,r,n){var o,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:12;return null!==(o=function(e,t,r){var n=-1,o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:12;return t.forEach((t,a)=>{var i=v(e,t);if(i){var d=p(i,r);d<o&&(o=d,n=a)}}),n>=0?{index:n,type:"vertex"}:null}(e,t,n,a))&&void 0!==o?o:function(e,t,r,n){var o=-1,a=arguments.length>4&&void 0!==arguments[4]?arguments[4]:12;return t.forEach((t,n)=>{var i=v(e,t);if(i){var d=p(i,r);d<a&&(a=d,o=n)}}),o>=0?{index:n+o,type:"midpoint"}:null}(e,r,n,t.length,a)},V=e=>{var{map:t,container:r,getState:n,setState:o,onVertexMoved:a,onTap:i,colors:d,snap:l}=e,s=(e=>{var t=e.querySelector("[data-im-draw-touch-target]");return t||(e.insertAdjacentHTML("beforeend","\n <svg width='48' height='48' viewBox='0 0 48 48' fill-rule='evenodd'\n style='display:none;position:absolute;top:0;left:0;margin:24px 0 0 -24px;cursor:grab'\n class='im-draw-touch-target' data-im-draw-touch-target>\n <circle cx='24' cy='24' r='24' fill='var(--draw-halo, #000)'/>\n <path d=\"M37.543 25H34a1 1 0 1 1 0-2h3.629l-.836-.837a1 1 0 0 1 1.414-1.414l2.5 2.501A1 1 0 0 1 41 24a1 1 0 0 1-.487.858l-2.306 2.306a1 1 0 0 1-1.414-1.414l.75-.75zM23 10.414l-.793.793a1 1 0 0 1-1.414-1.414l2.5-2.5C23.481 7.105 23.734 7 24 7s.519.105.707.293l2.5 2.5a1 1 0 0 1-1.414 1.414L25 10.414V14a1 1 0 1 1-2 0v-3.586zM7 24a1 1 0 0 1 .293-.75l2.5-2.501a1 1 0 0 1 1.414 1.414l-.836.837H14a1 1 0 1 1 0 2h-3.543l.75.75a1 1 0 0 1-1.414 1.414l-2.306-2.306A1 1 0 0 1 7 24zm16.293 16.707l-2.5-2.5a1 1 0 0 1 1.414-1.414l.793.793V34a1 1 0 1 1 2 0v3.586l.793-.793a1 1 0 0 1 1.414 1.414l-2.5 2.5c-.188.188-.441.293-.707.293s-.519-.105-.707-.293zM24 20c2.208 0 4 1.792 4 4s-1.792 4-4 4-4-1.792-4-4 1.792-4 4-4z\" fill='var(--draw-bg, #fff)'/>\n </svg>\n"),t=e.querySelector("[data-im-draw-touch-target]")),t})(r);y(s,d);var c={scale:1,ox:0,oy:0},p=e=>({x:e.x*c.scale+c.ox,y:e.y*c.scale+c.oy}),u=()=>{var e=t.getViewport(),n=e.getBoundingClientRect(),o=r.getBoundingClientRect(),a=e.offsetWidth>0?n.width/e.offsetWidth:1,i=r.offsetWidth>0?o.width/r.offsetWidth:1;Object.assign(c,{scale:a/i,ox:(n.left-o.left)/i,oy:(n.top-o.top)/i})},h=(e=>{var{container:t,map:r,targetEl:n,olToCSS:o,cssToOl:a,getState:i,setState:d,onVertexMoved:l,onTap:s,snap:c}=e,p=null,u=null,y=null,f=null,h=null,V=e=>{var t=e.touches[0],o=m(e.target);if(h={x:t.clientX,y:t.clientY,time:Date.now(),onTarget:o},o){var{selectedVertexIndex:d,vertices:l}=i(),s=l[d];if(s){var c=r.getEventPixel({clientX:t.clientX,clientY:t.clientY}),x=v(r,s),g=getComputedStyle(n),I=a({x:Number.parseFloat(g.left),y:Number.parseFloat(g.top)});p=[...s],u=d,y={x:c[0]-x.x,y:c[1]-x.y},f={x:c[0]-I.x,y:c[1]-I.y},e.preventDefault()}}},w=e=>{if(m(e.target)&&null!=u){e.preventDefault();var t=r.getEventPixel({clientX:e.touches[0].clientX,clientY:e.touches[0].clientY}),a=x(r,{x:t[0]-y.x,y:t[1]-y.y}),l=c?c.apply(a):a;null==c||c.hideIndicator();var{olFeature:s,vertices:v}=i();s&&(I(s,u,l),d({vertices:v.map((e,t)=>t===u?l:e)}),g(n,o({x:t[0]-f.x,y:t[1]-f.y})))}},S=e=>{if(null!=u){h=null;var{vertices:t}=i();t[u]&&p&&l({vertexIndex:u,previousCoord:p}),null==c||c.hideIndicator(),p=null,u=null,y=null,f=null,e.preventDefault()}else{if(h&&!h.onTarget&&e.changedTouches.length>0){var n=e.changedTouches[0],o=Date.now()-h.time;if(Math.hypot(n.clientX-h.x,n.clientY-h.y)<10&&o<400){var a=r.getEventPixel({clientX:n.clientX,clientY:n.clientY}),d=i();null==s||s(T(r,d.vertices,d.midpoints,{x:a[0],y:a[1]},24)),e.preventDefault()}}h=null}};return t.addEventListener("touchstart",V,{passive:!1}),t.addEventListener("touchmove",w,{passive:!1}),t.addEventListener("touchend",S,{passive:!1}),{isDragging:()=>null!=u,destroy(){t.removeEventListener("touchstart",V),t.removeEventListener("touchmove",w),t.removeEventListener("touchend",S)}}})({container:r,map:t,targetEl:s,olToCSS:p,cssToOl:e=>({x:(e.x-c.ox)/c.scale,y:(e.y-c.oy)/c.scale}),getState:n,setState:o,onVertexMoved:a,onTap:i,snap:l}),V=()=>{var{selectedVertexIndex:e,vertices:r,interfaceType:o}=n();if(e<0||!r[e]||"touch"!==o)f(s);else{var a=v(t,r[e]);a?g(s,p(a)):f(s)}},w=()=>{var{selectedVertexIndex:e,interfaceType:t}=n();e>=0&&!h.isDragging()&&"touch"===t&&V()};t.on("postrender",w);var S=()=>{u(),t.once("postrender",V)};return t.on("change:size",S),u(),{updateTargetPosition:V,updateColors(e){y(s,e)},hide(){f(s)},destroy(){t.un("change:size",S),t.un("postrender",w),h.destroy(),f(s)}}},w=(e,t,r)=>{var n=t.filter(t=>{var n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return("ArrowUp"===r?t[1]<=e[1]&&o>=n:"ArrowDown"===r?t[1]>e[1]&&o>=n:"ArrowLeft"===r?t[0]<=e[0]&&o<n:"ArrowRight"!==r||t[0]>e[0]&&o<n)&&JSON.stringify(t)!==JSON.stringify(e)});n.length||n.push(e);var o=t=>Math.sqrt((e[0]-t[0])**2+(e[1]-t[1])**2),a=n.reduce((e,t)=>o(t)<o(e)?t:e);return t.findIndex(e=>JSON.stringify(e)===JSON.stringify(a))},S=new Set(["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"]),C=new Set(["INPUT","TEXTAREA","BUTTON","SELECT","A"]),E=e=>{var{map:t,snap:r,getState:n,setState:o,onInserted:a}=e,i={start:null,index:null};return{nudge:e=>{var{selectedVertexIndex:d,selectedVertexType:l,vertices:s,midpoints:c,olFeature:v}=n();if(v){var p=e.shiftKey?1:5,x={ArrowUp:[0,-p],ArrowDown:[0,p],ArrowLeft:[-p,0],ArrowRight:[p,0]},[y,g]=x[e.key];if("midpoint"!==l){if(!(d<0)&&s[d]){var f=s[d];i.start||(i.start=[...f],i.index=d);var m=u(t,f,y,g),T=r?r.apply(m):m;null==r||r.hideIndicator();var V=((e,t,r,n,o,a,i)=>{if(!e)return o;var d=[n[0]-r[0],n[1]-r[1]],l=[o[0]-r[0],o[1]-r[1]],s=d[0]**2+d[1]**2;if(s>0&&(l[0]*d[0]+l[1]*d[1])/s<.5){var c=e.snapRadius+1;return u(t,r,0===a?0:Math.sign(a)*c,0===i?0:Math.sign(i)*c)}return o})(r,t,f,m,T,y,g);I(v,d,V),o({vertices:s.map((e,t)=>t===d?V:e)})}}else((e,d,l,s,c,v)=>{var p=h(e,d,l,s.length);if(p){a({insertedIndex:p.insertedIndex});var x=n().vertices,y=x[p.insertedIndex];if(y){i.start=[...y],i.index=p.insertedIndex;var g=u(t,y,c,v),f=r?r.apply(g):g;I(e,p.insertedIndex,f),o({selectedVertexIndex:p.insertedIndex,selectedVertexType:"vertex",vertices:x.map((e,t)=>t===p.insertedIndex?f:e)})}}})(v,c,d,s,y,g)}},keyMove:i}},L=e=>{var t,{map:r,snap:n,getState:o,setState:a,onVertexMoved:i,onInserted:d,onDeleted:l,onUndo:s,onKeyboardActive:c}=e,{nudge:p,keyMove:x}=E({map:r,snap:n,getState:o,setState:a,onInserted:d}),u=null!==(t=r.getViewport().closest('[role="application"]'))&&void 0!==t?t:r.getViewport(),y=()=>(e=>{var t=document.activeElement;if(!t||t===document.body)return!1;if(e.contains(t))return!1;var r=t.tagName;return C.has(r)||t.isContentEditable||t.hasAttribute("tabindex")})(u),g=e=>{e.altKey?(e.preventDefault(),e.stopPropagation(),((e,t,r,n)=>{var{selectedVertexIndex:o,vertices:a,midpoints:i}=r();if(a.length){var d,l=[...a,...i].map(e=>v(t,e)).filter(Boolean).map(e=>[e.x,e.y]),s=o>=0?l[o]:(d=v(t,t.getView().getCenter()))?[d.x,d.y]:null;if(s){var c=w(s,l,e);n({selectedVertexIndex:c,selectedVertexType:c<a.length?"vertex":"midpoint"})}}})(e.key,r,o,a)):o().selectedVertexIndex>=0&&(e.preventDefault(),e.stopPropagation(),p(e))},f=e=>{if(null==c||c()," "===e.key&&o().selectedVertexIndex<0)e.preventDefault(),((e,t,r)=>{var{vertices:n,midpoints:o}=t();if(n.length){var a=e.getView().getCenter(),i=v(e,a);if(i){var d=[...n.map(t=>v(e,t)),...o.map(t=>v(e,t))].filter(Boolean).map(e=>[e.x,e.y]),l=w([i.x,i.y],d,void 0);r({selectedVertexIndex:l,selectedVertexType:l<n.length?"vertex":"midpoint"})}}})(r,o,a);else if(S.has(e.key))g(e);else if("z"===e.key&&(e.metaKey||e.ctrlKey)){var t,n=null===(t=document.activeElement)||void 0===t?void 0:t.tagName;C.has(n)||(e.preventDefault(),e.stopPropagation(),s())}},m=e=>{y()||("Escape"===e.key&&o().selectedVertexIndex>=0?(e.preventDefault(),x.start=null,x.index=null,a({selectedVertexIndex:-1,selectedVertexType:null})):f(e))},h=e=>{y()||(S.has(e.key)&&x.start&&null!=x.index&&(null==n||n.hideIndicator(),i({vertexIndex:x.index,previousCoord:x.start}),x.start=null,x.index=null),"Delete"===e.key&&l())};return window.addEventListener("keydown",m,{capture:!0}),window.addEventListener("keyup",h,{capture:!0}),{destroy(){window.removeEventListener("keydown",m,{capture:!0}),window.removeEventListener("keyup",h,{capture:!0})}}},b=(e,t)=>{switch(t.type){case"move_vertex":return((e,t)=>{var{vertexIndex:r,previousCoord:n}=t,o=e.getGeometry(),a={type:o.getType(),coordinates:o.getCoordinates()},i=l(a),d=s(i,r);if(!d)return-1;var v=c(a,d.segment.path);return v[d.localIdx]=[...n],d.segment.closed&&0===d.localIdx&&(v[v.length-1]=[...n]),o.setCoordinates(a.coordinates),r})(e,t);case"insert_vertex":return((e,t)=>{var{vertexIndex:r}=t,n=e.getGeometry(),o={type:n.getType(),coordinates:n.getCoordinates()},a=l(o),i=s(a,r);if(!i)return-1;var d=c(o,i.segment.path);return d.splice(i.localIdx,1),i.segment.closed&&(d[d.length-1]=[...d[0]]),n.setCoordinates(o.coordinates),-1})(e,t);case"delete_vertex":return((e,t)=>{var{vertexIndex:r,deletedCoord:n}=t,o=e.getGeometry(),a={type:o.getType(),coordinates:o.getCoordinates()},i=l(a),d=s(i,r);if(!d)for(var v of i)if(r===v.start+v.length){d={segment:v,localIdx:v.length};break}if(!d)return-1;var p=c(a,d.segment.path);return p.splice(d.localIdx,0,[...n]),d.segment.closed&&(p[p.length-1]=[...p[0]]),o.setCoordinates(a.coordinates),r})(e,t);default:return-1}},k=v=>{var{map:p,manager:x,options:u}=v,{featureId:y,container:g,interfaceType:f,deleteVertexButtonId:m,snap:I}=u,{store:w,undoStack:S}=x,C=w.getOL(y);if(!C)return null;var E=C.getStyle();C.setStyle(x.styles.editFeatureStyle);var k={olFeature:C,selectedVertexIndex:-1,selectedVertexType:null,vertices:[],midpoints:[],interfaceType:null!=f?f:"pointer"},A=()=>k,M=null,P=null,D=e=>{if(Object.assign(k,e),void 0!==e.selectedVertexIndex){var t;if(X.setSelected("vertex"===k.selectedVertexType?k.selectedVertexIndex:-1),_.setSelected("midpoint"===k.selectedVertexType?k.selectedVertexIndex-k.vertices.length:-1),k.selectedVertexIndex<0)null===(t=M)||void 0===t||t();R(),x.emit("vertexselection",{index:"vertex"===k.selectedVertexType?k.selectedVertexIndex:-1,numVertices:k.vertices.length})}if(void 0!==e.vertices){var r,n={type:C.getGeometry().getType(),coordinates:C.getGeometry().getCoordinates()};_.update(n),X.update(n),k.midpoints=_.getCoords(),R(),null===(r=P)||void 0===r||r(),p.render()}},G=()=>{var e=C.getGeometry(),t={type:e.getType(),coordinates:e.getCoordinates()};k.vertices=d(t),k.midpoints=i(t),_.update(t),X.update(t),R()},z=()=>{G(),x.emit("vertexchange",{numVertices:k.vertices.length}),x.emit("update",w.toGeoJSON(C))},N=()=>G();C.getGeometry().on("change",N);var F=new t([C]),O=new e({features:F,style:()=>[],pixelTolerance:12,condition:e=>{if("touch"===k.interfaceType)return!1;var t=p.getEventPixel(e.originalEvent);return null!==T(p,k.vertices,k.midpoints,{x:t[0],y:t[1]})}});p.addInteraction(O);var j=null;O.on("modifystart",()=>{"touch"!==k.interfaceType&&(j=k.vertices.map(e=>[...e]))}),O.on("modifyend",()=>{if("touch"!==k.interfaceType){var e=j;if(z(),e){var t=k.vertices;if(t.length>e.length){var r=t.findIndex((t,r)=>!e[r]||t[0]!==e[r][0]),n=Math.max(0,r);S.push({type:"insert_vertex",vertexIndex:n}),D({selectedVertexIndex:n,selectedVertexType:"vertex"})}else if(t.length===e.length){var o=t.findIndex((t,r)=>t[0]!==e[r][0]||t[1]!==e[r][1]);o>=0&&(S.push({type:"move_vertex",vertexIndex:o,previousCoord:e[o]}),D({selectedVertexIndex:o,selectedVertexType:"vertex"}))}j=null}}});var _=((e,t)=>{var d=t,l=-1,s=new r,c=new n({source:s,style:e=>e.get("midpointIndex")===l?null:[d],zIndex:101});return e.addLayer(c),{update(e){s.clear();var t=i(e).map((e,t)=>{var r=new o({geometry:new a(e)});return r.set("midpointIndex",t),r});s.addFeatures(t)},setSelected(e){l=e,s.changed()},updateStyle(e){d=e,s.changed()},getCoords:()=>s.getFeatures().sort((e,t)=>e.get("midpointIndex")-t.get("midpointIndex")).map(e=>e.getGeometry().getCoordinates()),remove(){s.clear(),e.removeLayer(c)}}})(p,x.styles.midpointStyle),X=((e,t)=>{var i=t,l=-1,s=new r,c=new n({source:s,style:e=>e.get("vertexIndex")===l?null:[i],zIndex:102});return e.addLayer(c),{update(e){s.clear(),d(e).forEach((e,t)=>{var r=new o({geometry:new a(e)});r.set("vertexIndex",t),s.addFeature(r)})},setSelected(e){l=e,s.changed()},updateStyle(e){i=e,s.changed()},remove(){s.clear(),e.removeLayer(c)}}})(p,x.styles.vertexStyle),Y=new r,B=new n({source:Y,zIndex:103});p.addLayer(B);var R=()=>{Y.clear();var{selectedVertexIndex:e,selectedVertexType:t,vertices:r,midpoints:n}=k;if(!(e<0)){var i,d;if("vertex"===t)i=r[e],d=x.styles.selectedVertexStyle;else{if("midpoint"!==t)return;i=n[e-r.length],d=x.styles.selectedMidpointStyle}if(i){var l=new o({geometry:new a(i)});l.setStyle(d),Y.addFeature(l)}}};z();var U=e=>{C.setStyle(e.editFeatureStyle),X.updateStyle(e.vertexStyle),_.updateStyle(e.midpointStyle),R(),Z.updateColors(x.colors)};x.on("styleschanged",U);var J=e=>{if("touch"===e.pointerType)return k.interfaceType="touch",void Z.updateTargetPosition();k.interfaceType="pointer";var t=p.getEventPixel(e),r={x:t[0],y:t[1]},n=T(p,k.vertices,k.midpoints,r);"vertex"===(null==n?void 0:n.type)&&D({selectedVertexIndex:n.index,selectedVertexType:"vertex"})},K=e=>{if("touch"!==k.interfaceType){var t=p.getEventPixel(e),r={x:t[0],y:t[1]},n=T(p,k.vertices,k.midpoints,r);"vertex"===(null==n?void 0:n.type)?D({selectedVertexIndex:n.index,selectedVertexType:"vertex"}):"midpoint"===(null==n?void 0:n.type)||D({selectedVertexIndex:-1,selectedVertexType:null})}},H=e=>{"mouse"===e.pointerType&&"pointer"!==k.interfaceType&&(k.interfaceType="pointer",Z.hide())};g.addEventListener("pointerdown",J),g.addEventListener("pointerenter",H),g.addEventListener("pointermove",H),g.addEventListener("click",K);var W=e=>{m&&e.target.closest("#".concat(m))&&q()};globalThis.addEventListener("click",W);var q=()=>{if(!("vertex"!==k.selectedVertexType||k.selectedVertexIndex<0)){var e=((e,t)=>{var r=e.getGeometry(),n={type:r.getType(),coordinates:r.getCoordinates()},o=d(n),a=l(n),i=s(a,t);if(!i)return null;var{segment:v}=i,p=v.closed?3:2;if(v.length<=p)return null;var x=[...o[t]],u=c(n,v.path);return u.splice(i.localIdx,1),v.closed&&(u[u.length-1]=[...u[0]]),r.setCoordinates(n.coordinates),{deletedIndex:t,deletedCoord:x}})(C,k.selectedVertexIndex);e&&(S.push({type:"delete_vertex",vertexIndex:e.deletedIndex,deletedCoord:e.deletedCoord}),z(),D({selectedVertexIndex:-1,selectedVertexType:null}))}},Q=()=>{var e=S.pop();if(e){var t=k.selectedVertexIndex,r=b(C,e);z();var n,o=t>=0?r:-1;if(D({selectedVertexIndex:o,selectedVertexType:o>=0?"vertex":null}),t>=0&&o>=0)null===(n=P)||void 0===n||n()}},Z=V({map:p,container:g,getState:A,setState:D,colors:x.colors,snap:I,onVertexMoved(e){var{vertexIndex:t,previousCoord:r}=e;S.push({type:"move_vertex",vertexIndex:t,previousCoord:r}),z(),D({selectedVertexIndex:t,selectedVertexType:"vertex"}),Z.updateTargetPosition()},onTap(e){if(e){if("vertex"===e.type)return D({selectedVertexIndex:e.index,selectedVertexType:"vertex"}),void Z.updateTargetPosition();if("midpoint"===e.type){var t=h(C,k.midpoints,e.index,k.vertices.length);if(!t)return;S.push({type:"insert_vertex",vertexIndex:t.insertedIndex}),z(),D({selectedVertexIndex:t.insertedIndex,selectedVertexType:"vertex"}),Z.updateTargetPosition()}}else D({selectedVertexIndex:-1,selectedVertexType:null})}});M=()=>Z.hide(),P=()=>{"touch"===k.interfaceType&&Z.updateTargetPosition()};var $=()=>{"touch"!==k.interfaceType||k.selectedVertexIndex<0||p.once("postrender",()=>Z.updateTargetPosition())};p.on("change:size",$);var ee=(e=>L(e))({map:p,getState:A,setState:D,snap:I,onVertexMoved(e){var{vertexIndex:t,previousCoord:r}=e;S.push({type:"move_vertex",vertexIndex:t,previousCoord:r}),z(),D({selectedVertexIndex:t,selectedVertexType:"vertex"})},onInserted(e){var{insertedIndex:t}=e;S.push({type:"insert_vertex",vertexIndex:t}),z()},onDeleted:q,onUndo:Q,onKeyboardActive(){"keyboard"!==k.interfaceType&&(k.interfaceType="keyboard",Z.hide(),g.focus({preventScroll:!0}))}});return{setInterfaceType(e){e!==k.interfaceType&&(k.interfaceType=e,"touch"===e?Z.updateTargetPosition():Z.hide())},done(){x.emit("editfinish",w.toGeoJSON(C))},cancel(){},undo:Q,deleteVertex:q,destroy(){C.setStyle(E),C.getGeometry().un("change",N),x.off("styleschanged",U),g.removeEventListener("pointerdown",J),g.removeEventListener("pointerenter",H),g.removeEventListener("pointermove",H),g.removeEventListener("click",K),globalThis.removeEventListener("click",W),p.un("change:size",$),p.removeInteraction(O),Y.clear(),p.removeLayer(B),_.remove(),X.remove(),Z.destroy(),ee.destroy()}}};export{k as createEditMode};
@@ -0,0 +1 @@
1
+ var t=(t,r)=>{var e=t.getPixelFromCoordinate(r);return e?{x:e[0],y:e[1]}:null},r=(t,r)=>t.getCoordinateFromPixel([r.x,r.y]),e=(t,r)=>Math.sqrt((t.x-r.x)**2+(t.y-r.y)**2),a=(t,r,e,a)=>{var n=t.getPixelFromCoordinate(r);return n?t.getCoordinateFromPixel([n[0]+e,n[1]+a]):r},n=t=>{if(null==t||!t.coordinates)return[];switch(t.type){case"LineString":return t.coordinates;case"Polygon":return t.coordinates.flatMap(t=>t.slice(0,-1));case"MultiLineString":return t.coordinates.flat(1);case"MultiPolygon":return t.coordinates.flatMap(t=>t.flatMap(t=>t.slice(0,-1)));default:return[]}},o=t=>{if(null==t||!t.coordinates)return[];var r=[],e=0;switch(t.type){case"LineString":r.push({start:0,length:t.coordinates.length,path:[],closed:!1});break;case"Polygon":t.coordinates.forEach((t,a)=>{var n=t.length-1;r.push({start:e,length:n,path:[a],closed:!0}),e+=n});break;case"MultiLineString":t.coordinates.forEach((t,a)=>{r.push({start:e,length:t.length,path:[a],closed:!1}),e+=t.length});break;case"MultiPolygon":t.coordinates.forEach((t,a)=>{t.forEach((t,n)=>{var o=t.length-1;r.push({start:e,length:o,path:[a,n],closed:!0}),e+=o})})}return r},s=(t,r)=>{for(var e of t)if(r>=e.start&&r<e.start+e.length)return{segment:e,localIdx:r-e.start};return null},l=(t,r)=>{var e=t.coordinates;for(var a of r)e=e[a];return e},i=t=>{var r=n(t),e=o(t);if(!r.length||!e.length)return[];var a=[];for(var s of e)for(var l=s.closed?s.length:s.length-1,i=0;i<l;i++){var c=s.start+i,h=s.start+(i+1)%s.length,[g,u]=r[c],[d,f]=r[h];a.push([(g+d)/2,(u+f)/2])}return a};export{i as a,o as b,t as c,s as d,l as e,r as f,n as g,a as n,e as p};
@@ -0,0 +1 @@
1
+ import e from"@babel/runtime/helpers/defineProperty";import{useEffect as t}from"preact/compat";import r from"@babel/runtime/helpers/asyncToGenerator";import n from"ol/layer/Vector.js";import a from"ol/source/Vector.js";import o from"ol/format/GeoJSON.js";import i from"ol/style/Style.js";import l from"ol/style/Fill.js";import d from"ol/style/Stroke.js";import s from"ol/style/Circle.js";import p from"ol/layer/VectorTile.js";import c from"ol/Feature.js";import u from"ol/geom/Point.js";import{Style as v}from"ol/style.js";import f from"ol/interaction/Interaction.js";import h from"@babel/runtime/helpers/objectWithoutProperties";function y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function m(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?y(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):y(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var g={SET_MODE:(e,t)=>m(m({},e),{},{mode:t}),SET_FEATURE:(e,t)=>m(m({},e),{},{feature:void 0===t.feature?e.feature:t.feature,tempFeature:void 0===t.tempFeature?e.tempFeature:t.tempFeature}),SET_SELECTED_VERTEX_INDEX:(e,t)=>m(m({},e),{},{selectedVertexIndex:t.index,numVertices:t.numVertices}),SET_UNDO_STACK_LENGTH:(e,t)=>m(m({},e),{},{undoStackLength:t}),TOGGLE_SNAP:e=>m(m({},e),{},{snap:!e.snap}),SET_HAS_SNAP_LAYERS:(e,t)=>m(m({},e),{},{hasSnapLayers:!!t})},_={APP_ADD_MARKER:"app:addmarker",APP_UPDATE_MARKER:"app:updatemarker",APP_REMOVE_MARKER:"app:removemarker",APP_SET_MODE:"app:setmode",APP_REVERT_MODE:"app:revertmode",APP_ADD_BUTTON:"app:addbutton",APP_TOGGLE_BUTTON_STATE:"app:togglebuttonstate",APP_ADD_PANEL:"app:addpanel",APP_REMOVE_PANEL:"app:removepanel",APP_SHOW_PANEL:"app:showpanel",APP_HIDE_PANEL:"app:hidepanel",APP_ADD_CONTROL:"app:addcontrol",APP_READY:"app:ready",APP_OPENED:"app:opened",APP_CLOSED:"app:closed",APP_PANEL_OPENED:"app:panelopened",APP_PANEL_CLOSED:"app:panelclosed",MAP_SET_STYLE:"map:setstyle",MAP_SET_SIZE:"map:setsize",MAP_SET_FEATURES:"map:setfeatures",MAP_SET_ACTIVE_FEATURE:"map:setactivefeature",MAP_SELECT_FEATURE:"map:selectfeature",MAP_SET_PIXEL_RATIO:"map:setpixelratio",MAP_FIT_TO_BOUNDS:"map:fittobounds",MAP_SET_VIEW:"map:setview",MAP_INIT_MAP_STYLES:"map:initmapstyles",MAP_STYLE_CHANGE:"map:stylechange",MAP_LOADED:"map:loaded",MAP_READY:"map:ready",MAP_SIZE_CHANGE:"map:sizechange",MAP_FIRST_IDLE:"map:firstidle",MAP_MOVE_START:"map:movestart",MAP_MOVE:"map:move",MAP_MOVE_END:"map:moveend",MAP_STATE_UPDATED:"map:stateupdated",MAP_DATA_CHANGE:"map:datachange",MAP_RENDER:"map:render",MAP_CLICK:"map:click",MAP_DESTROY:"map:destroy"},S="EPSG:27700",P=new o({dataProjection:S,featureProjection:S}),w=()=>{var e=new a;return{source:e,getOL(t){var r;return null!==(r=e.getFeatureById(String(t)))&&void 0!==r?r:null},add(t){var r=this.getOL(t.id);r&&e.removeFeature(r);var n=P.readFeature(t);return e.addFeature(n),n},get(e){var t=this.getOL(e);return t?P.writeFeatureObject(t):null},remove(t){var r=this.getOL(t);r&&e.removeFeature(r)},clear(){e.clear()},toGeoJSON:e=>P.writeFeatureObject(e),fromGeoJSON:e=>P.readFeature(e)}},E={outer:11,mid:8,inner:6},O={outer:9,mid:6,inner:4},b=(e,t,r,n,a)=>{e.beginPath(),e.arc(t,r,n,0,2*Math.PI),e.fillStyle=a,e.fill()},A=(e,t,r)=>{var{outer:n,mid:a,inner:o}=e;return(e,i)=>{var l=i.context,d=i.pixelRatio,[s,p]=e;l.save(),b(l,s,p,n*d,t.editActive),b(l,s,p,a*d,t.editHalo),b(l,s,p,o*d,t[r]),l.restore()}},T=e=>e.charAt(0).toUpperCase()+e.slice(1),j=e=>{var t=new i({image:new s({radius:6,fill:new l({color:e.editVertex})})}),r=new i({renderer:A(E,e,"editVertex")}),n=new i({image:new s({radius:4,fill:new l({color:e.editMidpoint})})}),a=new i({renderer:A(O,e,"editMidpoint")}),o=new i({stroke:new d({color:e.editStroke,width:2}),fill:new l({color:e.shapeFill})}),p=new i({stroke:new d({color:e.editStroke,width:2}),fill:new l({color:e.shapeFill})}),c=new i({image:new s({radius:5,fill:new l({color:e.editVertex})})});return{vertexStyle:t,selectedVertexStyle:r,midpointStyle:n,selectedMidpointStyle:a,editFeatureStyle:o,createSketchStyle:()=>e=>"Point"===e.getGeometry().getType()?[c]:[p],createFeatureStyle:()=>t=>{var r=t.getProperties(),n=e.mapStyleId,a=n&&r["stroke".concat(T(n))]||r.stroke||e.shapeStroke,o=n&&r["fill".concat(T(n))]||r.fill||e.shapeFill,s=r.strokeWidth||e.strokeWidth;return[new i({stroke:new d({color:a,width:s}),fill:new l({color:o})})]}}},M={editStroke:{light:"#1a65a6",dark:"#ffffff"},editVertex:{light:"#1a65a6",dark:"#ffffff"},editMidpoint:{light:"#1a65a6",dark:"#ffffff"},editHalo:{light:"#ffffff",dark:"rgba(11,12,12,1)"},editActive:{light:"#000000",dark:"#ffffff"},splitInvalid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},splitValid:{light:"rgba(29,112,184,1)",dark:"rgba(29,112,184,1)"},shapeStroke:"#1a65a6",shapeFill:"rgba(26,101,166,0.1)",strokeWidth:2,snapVertex:"rgba(212,53,28,0.5)",snapMidpoint:"rgba(40,161,151,1)",snapEdge:"rgba(29,112,184,0.5)",snapRadius:10},k=function(e){var t,r,n,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=null!==(t=null==e?void 0:e.mapColorScheme)&&void 0!==t?t:"light",i=null!==(r=null==e?void 0:e.id)&&void 0!==r?r:null,l=e=>{var t;return((e,t,r)=>"object"!=typeof e||null===e?e:r&&void 0!==e[r]?e[r]:void 0!==e[t]?e[t]:void 0!==e.light?e.light:Object.values(e)[0])(null!==(t=a[e])&&void 0!==t?t:M[e],o,i)};return{editStroke:l("editStroke"),editVertex:l("editVertex"),editMidpoint:l("editMidpoint"),editActive:l("editActive"),editHalo:l("editHalo"),shapeStroke:l("shapeStroke"),strokeWidth:null!==(n=a.strokeWidth)&&void 0!==n?n:M.strokeWidth,shapeFill:l("shapeFill"),snapVertex:l("snapVertex"),snapEdge:l("snapEdge"),mapStyleId:i}},D=(e,t)=>{var r=e[0]-t[0],n=e[1]-t[1];return r*r+n*n},x=(e,t,r)=>{var n=r[0]-t[0],a=r[1]-t[1],o=n*n+a*a;if(0===o)return[t[0],t[1]];var i=Math.max(0,Math.min(1,((e[0]-t[0])*n+(e[1]-t[1])*a)/o));return[t[0]+i*n,t[1]+i*a]},I=(e,t)=>L(e,t)?t:e,L=(e,t)=>e?!!t&&("edge"===e.type&&"vertex"===t.type||("vertex"!==e.type||"edge"!==t.type)&&t.distSq<e.distSq):!!t,C=(e,t,r,n)=>{for(var a=null,o=n&&e.length>1?e.length-1:e.length,i=n?o:o-1,l=0;l<o;l++){var d=e[l],s=D(t,d);s<=r&&(a=I(a,{type:"vertex",coord:[d[0],d[1]],distSq:s}))}for(var p=0;p<i;p++){var c=e[p],u=e[(p+1)%o],v=x(t,c,u),f=D(t,v);f<=r&&(a=I(a,{type:"edge",coord:v,distSq:f}))}return a},V=(e,t,r,n,a,o)=>{for(var i=null,l=0;l<r;l++){var d=t+2*l,s=[e[d],e[d+1]],p=D(a,s);p<=o&&(i=I(i,{type:"vertex",coord:s,distSq:p}))}return I(i,((e,t,r,n,a,o)=>{for(var i=null,l=0;l<n;l++){var d=t+2*l,s=t+(l+1)%r*2,p=[e[d],e[d+1]],c=[e[s],e[s+1]],u=x(a,p,c),v=D(a,u);v<=o&&(i=I(i,{type:"edge",coord:u,distSq:v}))}return i})(e,t,r,n,a,o))},R=(e,t,r,n,a,o)=>{var i=(r-t)/2;return V(e,t,i,o?i:i-1,n,a)},F={Point(e,t,r){var n=e.getCoordinates(),a=D(t,n);return a<=r?{type:"vertex",coord:[n[0],n[1]],distSq:a}:null},LineString:(e,t,r)=>C(e.getCoordinates(),t,r,!1),LinearRing:(e,t,r)=>C(e.getCoordinates(),t,r,!0),Polygon(e,t,r){var n=null;for(var a of e.getCoordinates())n=I(n,C(a,t,r,!0));return n},MultiLineString(e,t,r){var n=null;for(var a of e.getCoordinates())n=I(n,C(a,t,r,!1));return n},MultiPolygon(e,t,r){var n=null;for(var a of e.getCoordinates())for(var o of a)n=I(n,C(o,t,r,!0));return n}},N=(e,t,r)=>{var n=e.getGeometry();if(!n)return null;var a=F[n.getType()];return a?a(n,t,r):null},W=(e,t)=>t?e?"vertex"===e.type&&"edge"===t.type?e:"edge"===e.type&&"vertex"===t.type||t.distSq<e.distSq?t:e:t:e,H=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=new Set,a=[],o=e=>{for(var t of(r=new Set,a=[],null!=e?e:[]))"string"==typeof t?r.add(t):t instanceof n&&a.push(t)};o(t);return{query:(t,n)=>{var o=e.getView().getResolution();if(!o)return null;var i=n*o,l=i*i,d=[t[0]-i,t[1]-i,t[0]+i,t[1]+i],s=null;for(var c of a){var u=c.getSource();if(u)for(var v of u.getFeaturesInExtent(d))s=W(s,N(v,t,l))}if(r.size>0){var f=(e=>{var t=[];return e.getLayers().forEach(e=>{e instanceof p&&t.push(e)}),t})(e),h=f.length>0?e.getPixelFromCoordinate(t):null;h&&e.forEachFeatureAtPixel(h,(e,n)=>{var a;r.has(null===(a=e.get("mapbox-layer"))||void 0===a?void 0:a.id)&&(s=W(s,((e,t,r)=>{var n=e.getType(),a=e.getFlatCoordinates(),o=null;if("Point"===n){var i=D(t,a);i<=r&&(o=I(o,{type:"vertex",coord:[a[0],a[1]],distSq:i}))}else if("LineString"===n)o=I(o,R(a,0,a.length,t,r,!1));else if("Polygon"===n||"MultiLineString"===n){var l=e.getEnds(),d=0,s="Polygon"===n;for(var p of l)o=I(o,R(a,d,p,t,r,s)),d=p}return o})(e,t,l)))},{hitTolerance:n,layerFilter:e=>f.includes(e)})}return s?{type:s.type,coord:s.coord}:null},setLayers:o}},G=e=>(t,r)=>{var n=r.context,[a,o]=t;n.beginPath(),n.arc(a,o,10*r.pixelRatio,0,2*Math.PI),n.fillStyle=e,n.fill()},U=e=>({vertex:new v({renderer:G(e.snapVertex)}),edge:new v({renderer:G(e.snapEdge)})}),B=new Set(["pointermove","pointerdrag","pointerdown","pointerup","singleclick","click"]),q=(e,t,r,o)=>{if(null==t||!t.length)return null;var i=H(e,t),l=((e,t)=>{var r=U(t),o=new a,i=new n({source:o,style:e=>{var t;return null!==(t=r[e.get("snapType")])&&void 0!==t?t:null},zIndex:200,updateWhileAnimating:!0,updateWhileInteracting:!0});e.addLayer(i);var l=new c,d=!1;return{show(e,t){l.setGeometry(new u(e)),l.set("snapType",t,!0),d?o.changed():(o.addFeature(l),d=!0)},hide(){d&&(o.clear(),d=!1)},updateColors(e){r=U(e),d&&o.changed()},remove(){o.clear(),e.removeLayer(i)}}})(e,r),d=((e,t,r)=>{var n=new f({handleEvent(a){if(!n.getActive())return!0;var{type:o}=a;if("pointerout"===o||"pointerleave"===o)return t.hide(),!0;if(!B.has(o))return!0;var i=e.query(a.coordinate,r);return i&&(a.coordinate=i.coord.slice()),"pointermove"===o?i?t.show(i.coord,i.type):t.hide():"pointerdrag"===o&&t.hide(),!0}});return n})(i,l,o);e.addInteraction(d),d.setActive(!1);var s=!1;return{snapRadius:o,apply(e){if(!s)return e;var t=i.query(e,o);return t?(l.show(t.coord,t.type),t.coord):(l.hide(),e)},hideIndicator(){l.hide()},setActive(e){s=e,d.setActive(e),e||l.hide()},setSnapLayers(e){i.setLayers(null==e?null!=t?t:[]:e)},reattach(){e.removeInteraction(d),e.addInteraction(d)},updateColors(e){l.updateColors(e)},destroy(){e.removeInteraction(d),l.remove()}}};function Y(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function X(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Y(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Y(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}class z{constructor(e){var t,r,a,o,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this._map=e,this._pluginConfig=i,this._mode="disabled",this._modeInstance=null,this._listeners=new Map,this.store=w(),this.undoStack=(a=e=>this.emit("undochange",e),o=[],{push(e){o.push(e),a(o.length)},pop(){var e=o.pop();return a(o.length),e},clear(){o.length=0,a(o.length)},get length(){return o.length}}),this.colors=k(null,i),this.styles=j(this.colors),this.snap=q(e,null!==(t=i.snapLayers)&&void 0!==t?t:null,this.colors,null!==(r=i.snapRadius)&&void 0!==r?r:M.snapRadius),this._layer=new n({source:this.store.source,style:this.styles.createFeatureStyle(),zIndex:100}),this._layer.set("layerId","draw"),e.addLayer(this._layer)}setMapStyle(e){var t;this.colors=k(e,this._pluginConfig),this.styles=j(this.colors),this._layer.setStyle(this.styles.createFeatureStyle()),this.store.source.changed(),null===(t=this.snap)||void 0===t||t.updateColors(this.colors),this.emit("styleschanged",this.styles)}on(e,t){this._listeners.has(e)||this._listeners.set(e,new Set),this._listeners.get(e).add(t)}off(e,t){var r;null===(r=this._listeners.get(e))||void 0===r||r.delete(t)}emit(e,t){var r;null===(r=this._listeners.get(e))||void 0===r||r.forEach(e=>e(t))}changeMode(e){var t=arguments,n=this;return r(function*(){var r,a,o=t.length>1&&void 0!==t[1]?t[1]:{};null===(r=n._modeInstance)||void 0===r||r.destroy(),n._modeInstance=null,n._mode=e;var i=X(X({},o),{},{snap:n.snap});if("draw_polygon"===e||"draw_line"===e){var{createDrawMode:l}=yield import(/* webpackChunkName: "DrawMode" */ "./DrawMode.js");n._modeInstance=l({map:n._map,manager:n,options:i})}else if("edit_vertex"===e){var{createEditMode:d}=yield import(/* webpackChunkName: "EditMode" */ "./EditMode.js");n._modeInstance=d({map:n._map,manager:n,options:i})}null===(a=n.snap)||void 0===a||a.reattach()})()}getMode(){return this._mode}done(){var e;null===(e=this._modeInstance)||void 0===e||e.done()}cancel(){var e;null===(e=this._modeInstance)||void 0===e||e.cancel(),this.changeMode("disabled")}undo(){var e;null===(e=this._modeInstance)||void 0===e||e.undo()}deleteVertex(){var e;null===(e=this._modeInstance)||void 0===e||e.deleteVertex()}setInterfaceType(e){var t,r;null===(t=this._modeInstance)||void 0===t||null===(r=t.setInterfaceType)||void 0===r||r.call(t,e)}get(e){return this.store.get(e)}add(e){return this.store.add(e)}delete(e){return this.store.remove(e)}deleteAll(){return this.store.clear()}remove(){var e,t;null===(e=this._modeInstance)||void 0===e||e.destroy(),this._modeInstance=null,null===(t=this.snap)||void 0===t||t.destroy(),this.snap=null,this.store.clear(),this._map.removeLayer(this._layer),this._listeners.clear()}}var K=["stroke","fill","strokeWidth"],Z=e=>{if(!e)return{};var t={};for(var[r,n]of Object.entries(e))if(K.includes(r)&&"object"==typeof n&&null!==n){var a=Object.entries(n);for(var[o,i]of(a.length>0&&(t[r]=a[0][1]),a))t["".concat(r).concat(o.charAt(0).toUpperCase()+o.slice(1))]=i}else t[r]=n;return t},J=["stroke","fill","strokeWidth","properties"];function Q(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function $(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?Q(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):Q(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ee=["stroke","fill","strokeWidth","properties"];function te(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function re(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?te(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):te(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var ne=["stroke","fill","strokeWidth","properties"];function ae(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function oe(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ae(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ae(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}function ie(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function le(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?ie(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):ie(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var de=e=>({mobile:{slot:"actions",showLabel:e},tablet:{slot:"actions",showLabel:e},desktop:{slot:"actions",showLabel:e}}),se={reducer:{initialState:{mode:null,feature:null,tempFeature:null,selectedVertexIndex:-1,numVertices:null,undoStackLength:0,snap:!1,hasSnapLayers:!1},actions:g},InitComponent:e=>{var{appState:r,appConfig:n,mapState:a,pluginConfig:o,pluginState:i,services:l,mapProvider:d,buttonConfig:s}=e,{eventBus:p}=l,{crossHair:c}=a,u=["touch","keyboard"].includes(r.interfaceType);t(()=>{var e,t,n,l,s,c=null===(e=null===(t=o.includeModes)||void 0===t?void 0:t.includes(r.mode))||void 0===e||e,u=null!==(n=null===(l=o.excludeModes)||void 0===l?void 0:l.includes(r.mode))&&void 0!==n&&n;if(a.isMapReady&&c&&!u){var{remove:v}=(e=>{var{mapProvider:t,events:r,eventBus:n,pluginConfig:a={},mapStyle:o=null}=e,{map:i}=t,l=new z(i,a);o&&l.setMapStyle(o),t.draw=l;var d=e=>{var r;t.drawScale=null!==(r={small:1,medium:1.5,large:2}[e])&&void 0!==r?r:1};n.on(r.MAP_SET_SIZE,d);var s=e=>{l.setMapStyle(e)};return n.on(r.MAP_SET_STYLE,s),{remove(){n.off(r.MAP_SET_SIZE,d),n.off(r.MAP_SET_STYLE,s),l.remove(),t.draw=null}}})({mapProvider:d,events:_,eventBus:p,pluginConfig:o,mapStyle:a.mapStyle});return i.dispatch({type:"SET_MODE",payload:null}),i.dispatch({type:"SET_HAS_SNAP_LAYERS",payload:(null===(s=o.snapLayers)||void 0===s?void 0:s.length)>0}),p.emit("draw:ready"),()=>v()}},[a.isMapReady,r.mode]),t(()=>{if(["draw_polygon","draw_line"].includes(i.mode)&&u){var e=c.isVisible;return c.fixAtCenter(),()=>{e||c.hide()}}},[i.mode,r.interfaceType]),t(()=>{"edit_vertex"===i.mode&&d.draw&&d.draw.setInterfaceType(r.interfaceType)},[r.interfaceType,i.mode]),t(()=>{if(d.draw)return function(e){var{pluginState:t,mapProvider:r,buttonConfig:n,eventBus:a}=e,{drawDone:o,drawCancel:i,drawUndo:l,drawDeletePoint:d,drawSnap:s}=n,{draw:p}=r,{dispatch:c,feature:u,tempFeature:v}=t,f=()=>{p.undoStack.clear(),c({type:"SET_MODE",payload:null}),c({type:"SET_FEATURE",payload:{feature:null,tempFeature:null}})},h=e=>{f(),p.changeMode("disabled"),a.emit("draw:created",e)},y=e=>{f(),p.changeMode("disabled"),a.emit("draw:edited",e)},m=()=>{},g=e=>{c({type:"SET_SELECTED_VERTEX_INDEX",payload:e}),a.emit("draw:vertexselection",e)},_=e=>{c({type:"SET_SELECTED_VERTEX_INDEX",payload:{index:-1,numVertices:e.numVertices}})},S=e=>{c({type:"SET_UNDO_STACK_LENGTH",payload:e})},P=e=>{a.emit("draw:updated",e)};return o.onClick=()=>{p.undoStack.clear(),p.done()},i.onClick=()=>{"edit_vertex"===p.getMode()&&null!=v&&v.id&&p.add(u),p.cancel(),f(),a.emit("draw:cancelled",u)},l.onClick=()=>{p.undo()},d&&(d.onClick=()=>{p.deleteVertex()}),s&&(s.onClick=()=>{var e,r=!t.snap;c({type:"TOGGLE_SNAP"}),null===(e=p.snap)||void 0===e||e.setActive(r)}),p.on("create",h),p.on("editfinish",y),p.on("cancel",m),p.on("vertexselection",g),p.on("vertexchange",_),p.on("undochange",S),p.on("update",P),()=>{o.onClick=null,i.onClick=null,l.onClick=null,d&&(d.onClick=null),s&&(s.onClick=null),p.off("create",h),p.off("editfinish",y),p.off("cancel",m),p.off("vertexselection",g),p.off("vertexchange",_),p.off("undochange",S),p.off("update",P)}}({mapProvider:d,buttonConfig:s,pluginState:i,eventBus:p})},[d,r,i])},buttons:[le({id:"drawCancel",label:"Cancel",variant:"tertiary",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode}},de(!0)),le({id:"drawAddPoint",label:"Add point",variant:"primary",hiddenWhen:e=>{var{appState:t,pluginState:r}=e;return!["draw_polygon","draw_line"].includes(r.mode)||"touch"!==t.interfaceType}},de(!0)),le({id:"drawDone",label:"Done",variant:"primary",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return"draw_polygon"===t.mode?t.numVertices>=3:"draw_line"===t.mode?t.numVertices>=2:"edit_vertex"===t.mode}},de(!0)),{id:"drawMenu",label:"Menu",iconId:"menu",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},menuItems:[{id:"drawUndo",label:"Undo",iconId:"undo",hiddenWhen:e=>{var{pluginState:t}=e;return!["draw_polygon","draw_line","edit_vertex"].includes(t.mode)},enableWhen:e=>{var{pluginState:t}=e;return["draw_polygon","draw_line"].includes(t.mode)?t.numVertices>0:t.undoStackLength>0}},{id:"drawSnap",label:"Snap to feature",iconId:"magnet",hiddenWhen:e=>{var{pluginState:t}=e;return!t.mode||!t.hasSnapLayers},pressedWhen:e=>{var{pluginState:t}=e;return!!t.snap}},{id:"drawDeletePoint",label:"Delete point",iconId:"trash",enableWhen:e=>{var{pluginState:t}=e;return t.selectedVertexIndex>=0&&t.numVertices>2},hiddenWhen:e=>{var{pluginState:t}=e;return"edit_vertex"!==t.mode}}],mobile:{slot:"bottom-right"},tablet:{slot:"top-middle"},desktop:{slot:"top-middle"}}],keyboardShortcuts:[{id:"drawStart",group:"Drawing",title:"Edit vertex",command:"<kbd>Spacebar</kbd></dd>"}],icons:[{id:"menu",svgContent:'<path d="m6 9 6 6 6-6"/>'},{id:"undo",svgContent:'<path d="M9 14 4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/>'},{id:"magnet",svgContent:'<path d="m12 15 4 4"/><path d="M2.352 10.648a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.029-6.029a1 1 0 1 1 3 3l-6.029 6.029a1.205 1.205 0 0 0 0 1.704l2.296 2.296a1.205 1.205 0 0 0 1.704 0l6.365-6.367A1 1 0 0 0 8.716 4.282z"/><path d="m5 8 4 4"/>'},{id:"trash",svgContent:'<path d="M10 11v6"/><path d="M14 11v6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"/><path d="M3 6h18"/><path d="M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>'}],api:{newPolygon:function(e,t){var{appState:r,appConfig:n,mapState:a,pluginState:o,mapProvider:i,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:s}=o,{draw:p}=i,{eventBus:c}=l;if(p){c.emit("draw:started",{mode:"draw_polygon"});var{stroke:u,fill:v,strokeWidth:f,properties:y}=d,m=h(d,J),g=$($({},y),Z({stroke:u,fill:v,strokeWidth:f}));p.changeMode("draw_polygon",$({container:r.layoutRefs.viewportRef.current,interfaceType:r.interfaceType,addVertexButtonId:"".concat(n.id,"-draw-add-point"),featureId:t,geometryType:"Polygon",properties:g,mapProvider:i,crossHair:a.crossHair},m)),s({type:"SET_MODE",payload:"draw_polygon"})}},newLine:function(e,t){var{appState:r,appConfig:n,mapState:a,pluginState:o,mapProvider:i,services:l}=e,d=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:s}=o,{draw:p}=i,{eventBus:c}=l;if(p){c.emit("draw:started",{mode:"draw_line"});var{stroke:u,fill:v,strokeWidth:f,properties:y}=d,m=h(d,ee),g=re(re({},y),Z({stroke:u,fill:v,strokeWidth:f}));p.changeMode("draw_line",re({container:r.layoutRefs.viewportRef.current,interfaceType:r.interfaceType,addVertexButtonId:"".concat(n.id,"-draw-add-point"),featureId:t,geometryType:"LineString",properties:g,mapProvider:i,crossHair:a.crossHair},m)),s({type:"SET_MODE",payload:"draw_line"})}},editFeature:function(e,t){var r,n,{appState:a,appConfig:o,pluginConfig:i,pluginState:l,mapProvider:d,services:s}=e,p=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},{dispatch:c}=l,{draw:u}=d,{eventBus:v}=s;if(!u)return!1;var f=u.get(t);if(!f)return!1;v.emit("draw:editstart",{mode:"edit_vertex"});var h=void 0===p.snapLayers?null!==(r=i.snapLayers)&&void 0!==r?r:null:p.snapLayers;return null===(n=u.snap)||void 0===n||n.setSnapLayers(h),c({type:"SET_HAS_SNAP_LAYERS",payload:(null==h?void 0:h.length)>0}),u.changeMode("edit_vertex",{container:a.layoutRefs.viewportRef.current,deleteVertexButtonId:"".concat(o.id,"-draw-delete-point"),interfaceType:a.interfaceType,featureId:t}),c({type:"SET_FEATURE",payload:{feature:f,tempFeature:f}}),c({type:"SET_MODE",payload:"edit_vertex"}),!0},addFeature:(e,t)=>{var{mapProvider:r,services:n}=e,{draw:a}=r,{eventBus:o}=n;if(a){var{stroke:i,fill:l,strokeWidth:d,properties:s}=t,p=oe(oe({},h(t,ne)),{},{properties:oe(oe({},s),Z({stroke:i,fill:l,strokeWidth:d}))});a.add(p),o.emit("draw:add",p)}},deleteFeature:(e,t)=>{var{mapProvider:r}=e,{draw:n}=r;n&&n.delete(t)}}};export{se as manifest};
@@ -0,0 +1 @@
1
+ import e from"@babel/runtime/helpers/asyncToGenerator";import r from"@babel/runtime/helpers/defineProperty";function t(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);r&&(n=n.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable})),t.push.apply(t,n)}return t}function n(e){for(var n=1;n<arguments.length;n++){var o=null!=arguments[n]?arguments[n]:{};n%2?t(Object(o),!0).forEach(function(t){r(e,t,o[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):t(Object(o)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))})}return e}function o(){var r;return n(n({},arguments.length>0&&void 0!==arguments[0]?arguments[0]:{}),{},{id:"draw",load:(r=e(function*(){return(yield import(/* webpackChunkName: "im-draw-ol-plugin" */ "./im-draw-ol-plugin.js")).manifest}),function(){return r.apply(this,arguments)})})}export{o as default};
@@ -0,0 +1,67 @@
1
+ import { useEffect } from 'react'
2
+ import { EVENTS } from '../../../../src/config/events.js'
3
+ import { createOLDraw } from './olDraw.js'
4
+ import { attachEvents } from './events.js'
5
+
6
+ export const DrawInit = ({ appState, appConfig, mapState, pluginConfig, pluginState, services, mapProvider, buttonConfig }) => {
7
+ const { eventBus } = services
8
+ const { crossHair } = mapState
9
+ const isTouchOrKeyboard = ['touch', 'keyboard'].includes(appState.interfaceType)
10
+
11
+ // Create the OLDrawManager once when the map is ready
12
+ useEffect(() => {
13
+ const inModeWhitelist = pluginConfig.includeModes?.includes(appState.mode) ?? true
14
+ const inExcludeModes = pluginConfig.excludeModes?.includes(appState.mode) ?? false
15
+ if (!mapState.isMapReady || !inModeWhitelist || inExcludeModes) {
16
+ return undefined
17
+ }
18
+
19
+ const { remove } = createOLDraw({ mapProvider, events: EVENTS, eventBus, pluginConfig, mapStyle: mapState.mapStyle })
20
+
21
+ pluginState.dispatch({ type: 'SET_MODE', payload: null })
22
+ pluginState.dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: pluginConfig.snapLayers?.length > 0 })
23
+ eventBus.emit('draw:ready')
24
+
25
+ return () => remove()
26
+ }, [mapState.isMapReady, appState.mode])
27
+
28
+ // Show crosshair when entering draw mode on touch/keyboard
29
+ useEffect(() => {
30
+ if (!['draw_polygon', 'draw_line'].includes(pluginState.mode) || !isTouchOrKeyboard) {
31
+ return undefined
32
+ }
33
+ const wasVisible = crossHair.isVisible
34
+ crossHair.fixAtCenter()
35
+ return () => {
36
+ if (!wasVisible) { crossHair.hide() }
37
+ }
38
+ }, [pluginState.mode, appState.interfaceType])
39
+
40
+ // Keep edit mode in sync with the global interface type so the touch
41
+ // offset target hides immediately when the user switches to mouse/keyboard.
42
+ useEffect(() => {
43
+ if (pluginState.mode !== 'edit_vertex' || !mapProvider.draw) {
44
+ return undefined
45
+ }
46
+ mapProvider.draw.setInterfaceType(appState.interfaceType)
47
+ return undefined
48
+ }, [appState.interfaceType, pluginState.mode])
49
+
50
+ // Re-attach events when state changes
51
+ useEffect(() => {
52
+ if (!mapProvider.draw) {
53
+ return undefined
54
+ }
55
+
56
+ return attachEvents({
57
+ appState,
58
+ appConfig,
59
+ mapState,
60
+ mapProvider,
61
+ buttonConfig,
62
+ pluginState,
63
+ events: EVENTS,
64
+ eventBus
65
+ })
66
+ }, [mapProvider, appState, pluginState])
67
+ }
@@ -0,0 +1,29 @@
1
+ import { flattenStyleProperties } from '../utils/flattenStyleProperties.js'
2
+
3
+ /**
4
+ * Add a pre-drawn feature (GeoJSON) to the draw layer.
5
+ * The feature will be stored and available for editing.
6
+ *
7
+ * @param {object} context - plugin context
8
+ * @param {object} feature - GeoJSON feature with id, geometry, properties
9
+ */
10
+ export const addFeature = ({ mapProvider, services }, feature) => {
11
+ const { draw } = mapProvider
12
+ const { eventBus } = services
13
+
14
+ if (!draw) {
15
+ return
16
+ }
17
+
18
+ const { stroke, fill, strokeWidth, properties, ...featureRest } = feature
19
+ const flatFeature = {
20
+ ...featureRest,
21
+ properties: {
22
+ ...properties,
23
+ ...flattenStyleProperties({ stroke, fill, strokeWidth })
24
+ }
25
+ }
26
+
27
+ draw.add(flatFeature)
28
+ eventBus.emit('draw:add', flatFeature)
29
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Delete a feature from the draw layer by ID.
3
+ *
4
+ * @param {object} context - plugin context
5
+ * @param {string} featureId - ID of the feature to delete
6
+ */
7
+ export const deleteFeature = ({ mapProvider }, featureId) => {
8
+ const { draw } = mapProvider
9
+ if (!draw) return
10
+ draw.delete(featureId)
11
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Programmatically start editing a feature.
3
+ *
4
+ * @param {object} context - plugin context
5
+ * @param {string} featureId - ID of the feature to edit
6
+ * @param {object} options - { snapLayers }
7
+ * @returns {boolean} true if edit mode entered, false if feature not found
8
+ */
9
+ export const editFeature = (
10
+ { appState, appConfig, pluginConfig, pluginState, mapProvider, services },
11
+ featureId,
12
+ options = {}
13
+ ) => {
14
+ const { dispatch } = pluginState
15
+ const { draw } = mapProvider
16
+ const { eventBus } = services
17
+
18
+ if (!draw) {
19
+ return false
20
+ }
21
+
22
+ const existingFeature = draw.get(featureId)
23
+ if (!existingFeature) {
24
+ return false
25
+ }
26
+
27
+ eventBus.emit('draw:editstart', { mode: 'edit_vertex' })
28
+
29
+ const snapLayers = options.snapLayers === undefined
30
+ ? (pluginConfig.snapLayers ?? null)
31
+ : options.snapLayers
32
+
33
+ draw.snap?.setSnapLayers(snapLayers)
34
+ dispatch({ type: 'SET_HAS_SNAP_LAYERS', payload: snapLayers?.length > 0 })
35
+
36
+ draw.changeMode('edit_vertex', {
37
+ container: appState.layoutRefs.viewportRef.current,
38
+ deleteVertexButtonId: `${appConfig.id}-draw-delete-point`,
39
+ interfaceType: appState.interfaceType,
40
+ featureId
41
+ })
42
+
43
+ dispatch({
44
+ type: 'SET_FEATURE',
45
+ payload: { feature: existingFeature, tempFeature: existingFeature }
46
+ })
47
+
48
+ dispatch({ type: 'SET_MODE', payload: 'edit_vertex' })
49
+ return true
50
+ }