@eox/drawtools 1.2.0 → 1.4.0

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 (184) hide show
  1. package/dist/eox-drawtools.js +4194 -7303
  2. package/dist/eox-drawtools.umd.cjs +63 -63
  3. package/dist/material-symbols-outlined.woff2 +0 -0
  4. package/dist/material-symbols-rounded.woff2 +0 -0
  5. package/dist/material-symbols-sharp.woff2 +0 -0
  6. package/dist/material-symbols-subset.woff2 +0 -0
  7. package/package.json +8 -8
  8. package/src/components/controller.js +7 -7
  9. package/src/main.js +130 -20
  10. package/src/methods/draw/emit-drawn-features.js +7 -1
  11. package/src/methods/draw/index.js +5 -0
  12. package/src/methods/draw/init-layer.js +38 -36
  13. package/src/methods/draw/on-key-down.js +16 -0
  14. package/src/methods/draw/remove-feature.js +27 -0
  15. package/src/methods/draw/start-drawing.js +0 -9
  16. package/types/components/controller.d.ts.map +1 -0
  17. package/types/{drawtools/src/components → components}/list.d.ts +3 -3
  18. package/types/components/list.d.ts.map +1 -0
  19. package/types/{drawtools/src/enums → enums}/draw.d.ts.map +1 -1
  20. package/types/{drawtools/src/enums → enums}/index.d.ts.map +1 -1
  21. package/types/enums/stories.d.ts.map +1 -0
  22. package/types/{drawtools/src/enums → enums}/test.d.ts.map +1 -1
  23. package/types/helpers/copy-text-to-clipboard.d.ts.map +1 -0
  24. package/types/helpers/features-to-geojson.d.ts.map +1 -0
  25. package/types/helpers/features-to-wkt.d.ts.map +1 -0
  26. package/types/{drawtools/src/helpers → helpers}/generate-upload-events.d.ts +1 -1
  27. package/types/helpers/generate-upload-events.d.ts.map +1 -0
  28. package/types/{drawtools/src/helpers → helpers}/index.d.ts.map +1 -1
  29. package/types/{drawtools/src/main.d.ts → main.d.ts} +57 -13
  30. package/types/main.d.ts.map +1 -0
  31. package/types/methods/controller/index.d.ts.map +1 -0
  32. package/types/methods/controller/update-button-states.d.ts.map +1 -0
  33. package/types/methods/draw/create-select-handler.d.ts.map +1 -0
  34. package/types/methods/draw/discard-drawing.d.ts.map +1 -0
  35. package/types/methods/draw/emit-drawn-features.d.ts.map +1 -0
  36. package/types/{drawtools/src/methods → methods}/draw/handle-layer-id.d.ts +1 -1
  37. package/types/methods/draw/handle-layer-id.d.ts.map +1 -0
  38. package/types/{drawtools/src/methods → methods}/draw/index.d.ts +2 -0
  39. package/types/{map/src/enums → methods/draw}/index.d.ts.map +1 -1
  40. package/types/{drawtools/src/methods → methods}/draw/init-layer.d.ts +2 -2
  41. package/types/methods/draw/init-layer.d.ts.map +1 -0
  42. package/types/methods/draw/init-measuring.d.ts.map +1 -0
  43. package/types/{drawtools/src/methods → methods}/draw/init-selection.d.ts +1 -1
  44. package/types/methods/draw/init-selection.d.ts.map +1 -0
  45. package/types/methods/draw/on-draw-end.d.ts.map +1 -0
  46. package/types/methods/draw/on-key-down.d.ts +10 -0
  47. package/types/methods/draw/on-key-down.d.ts.map +1 -0
  48. package/types/methods/draw/remove-feature.d.ts +15 -0
  49. package/types/methods/draw/remove-feature.d.ts.map +1 -0
  50. package/types/methods/draw/start-drawing.d.ts.map +1 -0
  51. package/types/methods/list/delete-feature.d.ts.map +1 -0
  52. package/types/methods/list/first-update.d.ts.map +1 -0
  53. package/types/methods/list/hover-feature.d.ts.map +1 -0
  54. package/types/{map/src/helpers → methods/list}/index.d.ts.map +1 -1
  55. package/types/methods/list/select-deselect-feature.d.ts.map +1 -0
  56. package/types/{drawtools/src/style.eox.d.ts.map → style.eox.d.ts.map} +1 -1
  57. package/types/drawtools/src/components/controller.d.ts.map +0 -1
  58. package/types/drawtools/src/components/list.d.ts.map +0 -1
  59. package/types/drawtools/src/enums/stories.d.ts.map +0 -1
  60. package/types/drawtools/src/helpers/copy-text-to-clipboard.d.ts.map +0 -1
  61. package/types/drawtools/src/helpers/features-to-geojson.d.ts.map +0 -1
  62. package/types/drawtools/src/helpers/features-to-wkt.d.ts.map +0 -1
  63. package/types/drawtools/src/helpers/generate-upload-events.d.ts.map +0 -1
  64. package/types/drawtools/src/main.d.ts.map +0 -1
  65. package/types/drawtools/src/methods/controller/index.d.ts.map +0 -1
  66. package/types/drawtools/src/methods/controller/update-button-states.d.ts.map +0 -1
  67. package/types/drawtools/src/methods/draw/create-select-handler.d.ts.map +0 -1
  68. package/types/drawtools/src/methods/draw/discard-drawing.d.ts.map +0 -1
  69. package/types/drawtools/src/methods/draw/emit-drawn-features.d.ts.map +0 -1
  70. package/types/drawtools/src/methods/draw/handle-layer-id.d.ts.map +0 -1
  71. package/types/drawtools/src/methods/draw/index.d.ts.map +0 -1
  72. package/types/drawtools/src/methods/draw/init-layer.d.ts.map +0 -1
  73. package/types/drawtools/src/methods/draw/init-measuring.d.ts.map +0 -1
  74. package/types/drawtools/src/methods/draw/init-selection.d.ts.map +0 -1
  75. package/types/drawtools/src/methods/draw/on-draw-end.d.ts.map +0 -1
  76. package/types/drawtools/src/methods/draw/start-drawing.d.ts.map +0 -1
  77. package/types/drawtools/src/methods/list/delete-feature.d.ts.map +0 -1
  78. package/types/drawtools/src/methods/list/first-update.d.ts.map +0 -1
  79. package/types/drawtools/src/methods/list/hover-feature.d.ts.map +0 -1
  80. package/types/drawtools/src/methods/list/index.d.ts.map +0 -1
  81. package/types/drawtools/src/methods/list/select-deselect-feature.d.ts.map +0 -1
  82. package/types/map/src/components/compare.d.ts +0 -31
  83. package/types/map/src/components/compare.d.ts.map +0 -1
  84. package/types/map/src/components/tooltip.d.ts +0 -41
  85. package/types/map/src/components/tooltip.d.ts.map +0 -1
  86. package/types/map/src/controls/controls.d.ts +0 -21
  87. package/types/map/src/controls/controls.d.ts.map +0 -1
  88. package/types/map/src/controls/geo-location.d.ts +0 -41
  89. package/types/map/src/controls/geo-location.d.ts.map +0 -1
  90. package/types/map/src/controls/loading-indicator.d.ts +0 -20
  91. package/types/map/src/controls/loading-indicator.d.ts.map +0 -1
  92. package/types/map/src/custom/layers/MapboxStyle.d.ts +0 -13
  93. package/types/map/src/custom/layers/MapboxStyle.d.ts.map +0 -1
  94. package/types/map/src/custom/sources/Cluster.d.ts +0 -20
  95. package/types/map/src/custom/sources/Cluster.d.ts.map +0 -1
  96. package/types/map/src/custom/sources/FlatGeoBuf.d.ts +0 -28
  97. package/types/map/src/custom/sources/FlatGeoBuf.d.ts.map +0 -1
  98. package/types/map/src/custom/sources/WMTSCapabilities.d.ts +0 -35
  99. package/types/map/src/custom/sources/WMTSCapabilities.d.ts.map +0 -1
  100. package/types/map/src/enums/index.d.ts +0 -2
  101. package/types/map/src/enums/map.d.ts +0 -5
  102. package/types/map/src/enums/map.d.ts.map +0 -1
  103. package/types/map/src/helpers/add-new-feature.d.ts +0 -15
  104. package/types/map/src/helpers/add-new-feature.d.ts.map +0 -1
  105. package/types/map/src/helpers/cancel-animation.d.ts +0 -7
  106. package/types/map/src/helpers/cancel-animation.d.ts.map +0 -1
  107. package/types/map/src/helpers/center.d.ts +0 -12
  108. package/types/map/src/helpers/center.d.ts.map +0 -1
  109. package/types/map/src/helpers/cluster-explode.d.ts +0 -38
  110. package/types/map/src/helpers/cluster-explode.d.ts.map +0 -1
  111. package/types/map/src/helpers/coordinates-roughly-equals.d.ts +0 -12
  112. package/types/map/src/helpers/coordinates-roughly-equals.d.ts.map +0 -1
  113. package/types/map/src/helpers/draw.d.ts +0 -22
  114. package/types/map/src/helpers/draw.d.ts.map +0 -1
  115. package/types/map/src/helpers/generate.d.ts +0 -32
  116. package/types/map/src/helpers/generate.d.ts.map +0 -1
  117. package/types/map/src/helpers/index.d.ts +0 -17
  118. package/types/map/src/helpers/interactions.d.ts +0 -16
  119. package/types/map/src/helpers/interactions.d.ts.map +0 -1
  120. package/types/map/src/helpers/layer.d.ts +0 -24
  121. package/types/map/src/helpers/layer.d.ts.map +0 -1
  122. package/types/map/src/helpers/parse-feature.d.ts +0 -8
  123. package/types/map/src/helpers/parse-feature.d.ts.map +0 -1
  124. package/types/map/src/helpers/parse-text.d.ts +0 -45
  125. package/types/map/src/helpers/parse-text.d.ts.map +0 -1
  126. package/types/map/src/helpers/register-projection-from-code.d.ts +0 -8
  127. package/types/map/src/helpers/register-projection-from-code.d.ts.map +0 -1
  128. package/types/map/src/helpers/register-projection.d.ts +0 -11
  129. package/types/map/src/helpers/register-projection.d.ts.map +0 -1
  130. package/types/map/src/helpers/select.d.ts +0 -95
  131. package/types/map/src/helpers/select.d.ts.map +0 -1
  132. package/types/map/src/helpers/tile-grid.d.ts +0 -10
  133. package/types/map/src/helpers/tile-grid.d.ts.map +0 -1
  134. package/types/map/src/helpers/transform.d.ts +0 -19
  135. package/types/map/src/helpers/transform.d.ts.map +0 -1
  136. package/types/map/src/layers.d.ts +0 -125
  137. package/types/map/src/layers.d.ts.map +0 -1
  138. package/types/map/src/main.d.ts +0 -459
  139. package/types/map/src/main.d.ts.map +0 -1
  140. package/types/map/src/methods/map/add-update-layer.d.ts +0 -13
  141. package/types/map/src/methods/map/add-update-layer.d.ts.map +0 -1
  142. package/types/map/src/methods/map/animate-to-state.d.ts +0 -7
  143. package/types/map/src/methods/map/animate-to-state.d.ts.map +0 -1
  144. package/types/map/src/methods/map/first-updated.d.ts +0 -9
  145. package/types/map/src/methods/map/first-updated.d.ts.map +0 -1
  146. package/types/map/src/methods/map/getters.d.ts +0 -22
  147. package/types/map/src/methods/map/getters.d.ts.map +0 -1
  148. package/types/map/src/methods/map/index.d.ts +0 -7
  149. package/types/map/src/methods/map/index.d.ts.map +0 -1
  150. package/types/map/src/methods/map/remove.d.ts +0 -22
  151. package/types/map/src/methods/map/remove.d.ts.map +0 -1
  152. package/types/map/src/methods/map/setters.d.ts +0 -82
  153. package/types/map/src/methods/map/setters.d.ts.map +0 -1
  154. package/types/map/src/plugins/globe/index.d.ts +0 -6
  155. package/types/map/src/plugins/globe/index.d.ts.map +0 -1
  156. package/types/map/src/plugins/globe/methods.d.ts +0 -8
  157. package/types/map/src/plugins/globe/methods.d.ts.map +0 -1
  158. package/types/map/src/plugins/globe/openglobus.d.ts +0 -16
  159. package/types/map/src/plugins/globe/openglobus.d.ts.map +0 -1
  160. package/types/map/src/types.d.ts +0 -178
  161. package/types/map/src/types.d.ts.map +0 -1
  162. /package/types/{drawtools/src/components → components}/controller.d.ts +0 -0
  163. /package/types/{drawtools/src/enums → enums}/draw.d.ts +0 -0
  164. /package/types/{drawtools/src/enums → enums}/index.d.ts +0 -0
  165. /package/types/{drawtools/src/enums → enums}/stories.d.ts +0 -0
  166. /package/types/{drawtools/src/enums → enums}/test.d.ts +0 -0
  167. /package/types/{drawtools/src/helpers → helpers}/copy-text-to-clipboard.d.ts +0 -0
  168. /package/types/{drawtools/src/helpers → helpers}/features-to-geojson.d.ts +0 -0
  169. /package/types/{drawtools/src/helpers → helpers}/features-to-wkt.d.ts +0 -0
  170. /package/types/{drawtools/src/helpers → helpers}/index.d.ts +0 -0
  171. /package/types/{drawtools/src/methods → methods}/controller/index.d.ts +0 -0
  172. /package/types/{drawtools/src/methods → methods}/controller/update-button-states.d.ts +0 -0
  173. /package/types/{drawtools/src/methods → methods}/draw/create-select-handler.d.ts +0 -0
  174. /package/types/{drawtools/src/methods → methods}/draw/discard-drawing.d.ts +0 -0
  175. /package/types/{drawtools/src/methods → methods}/draw/emit-drawn-features.d.ts +0 -0
  176. /package/types/{drawtools/src/methods → methods}/draw/init-measuring.d.ts +0 -0
  177. /package/types/{drawtools/src/methods → methods}/draw/on-draw-end.d.ts +0 -0
  178. /package/types/{drawtools/src/methods → methods}/draw/start-drawing.d.ts +0 -0
  179. /package/types/{drawtools/src/methods → methods}/list/delete-feature.d.ts +0 -0
  180. /package/types/{drawtools/src/methods → methods}/list/first-update.d.ts +0 -0
  181. /package/types/{drawtools/src/methods → methods}/list/hover-feature.d.ts +0 -0
  182. /package/types/{drawtools/src/methods → methods}/list/index.d.ts +0 -0
  183. /package/types/{drawtools/src/methods → methods}/list/select-deselect-feature.d.ts +0 -0
  184. /package/types/{drawtools/src/style.eox.d.ts → style.eox.d.ts} +0 -0
Binary file
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eox/drawtools",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,11 +8,11 @@
8
8
  },
9
9
  "devDependencies": {
10
10
  "@eox/map": "*",
11
- "vite": "^7.1.12"
11
+ "vite": "^8.0.10"
12
12
  },
13
13
  "engines": {
14
14
  "npm": ">=8.0.0",
15
- "node": ">=18.0.0"
15
+ "node": ">=24.0.0"
16
16
  },
17
17
  "files": [
18
18
  "types",
@@ -20,14 +20,14 @@
20
20
  "src"
21
21
  ],
22
22
  "main": "./src/main.js",
23
- "types": "./types/drawtools/src/main.d.ts",
23
+ "types": "./types/main.d.ts",
24
24
  "typesVersions": {
25
25
  "*": {
26
26
  ".": [
27
- "./types/drawtools/src/main.d.ts"
27
+ "./types/main.d.ts"
28
28
  ],
29
29
  "src/*": [
30
- "./types/drawtools/src/*"
30
+ "./types/*"
31
31
  ]
32
32
  }
33
33
  },
@@ -39,8 +39,8 @@
39
39
  },
40
40
  "dependencies": {
41
41
  "@eox/elements-utils": "^1.1.0",
42
- "@eox/ui": "^0.5.0",
42
+ "@eox/ui": "^1.1.0",
43
43
  "lit": "^3.2.0",
44
- "ol": "^10.4.0"
44
+ "ol": "^10.9.0"
45
45
  }
46
46
  }
@@ -219,9 +219,9 @@ export class EOxDrawToolsController extends LitElement {
219
219
  <i class="small"
220
220
  >${this.select ? pointerIcon : shapeIcons[this.type]}</i
221
221
  >
222
- <div class="tooltip bottom">
222
+ <span class="tooltip bottom">
223
223
  ${this.select ? "Select" : "Draw"}
224
- </div>
224
+ </span>
225
225
  `}
226
226
  </button>
227
227
 
@@ -237,7 +237,7 @@ export class EOxDrawToolsController extends LitElement {
237
237
  ? "discard"
238
238
  : html`
239
239
  <i class="small">${discardIcon}</i>
240
- <div class="tooltip bottom">Discard</div>
240
+ <span class="tooltip bottom">Discard</span>
241
241
  `}
242
242
  </button>
243
243
  </div>
@@ -259,7 +259,7 @@ export class EOxDrawToolsController extends LitElement {
259
259
  ? "import"
260
260
  : html`
261
261
  <i class="small">${editIcon}</i>
262
- <div class="tooltip bottom">Edit features</div>
262
+ <span class="tooltip bottom">Edit features</span>
263
263
  `}
264
264
  </button>
265
265
  `,
@@ -291,7 +291,7 @@ export class EOxDrawToolsController extends LitElement {
291
291
  ? "import"
292
292
  : html`
293
293
  <i class="small">${importIcon}</i>
294
- <div class="tooltip bottom">Import features</div>
294
+ <span class="tooltip bottom">Import features</span>
295
295
  `}
296
296
  </button>
297
297
  `,
@@ -302,7 +302,7 @@ export class EOxDrawToolsController extends LitElement {
302
302
  ${when(
303
303
  this.showEditor,
304
304
  () => html`
305
- <div id="editor" class="field textarea border extra hidden">
305
+ <div id="editor" class="field border extra hidden">
306
306
  <!-- Geo JSON Editor -->
307
307
  <textarea
308
308
  style="font-family: monospace; font-size: small; line-height: 1.4; padding: 0.4rem;"
@@ -322,7 +322,7 @@ export class EOxDrawToolsController extends LitElement {
322
322
  ? "copy"
323
323
  : html`
324
324
  <i class="tiny">${copyIcon}</i>
325
- <div class="tooltip top">Copy</div>
325
+ <span class="tooltip top">Copy</span>
326
326
  `}
327
327
  </button>
328
328
  </div>
package/src/main.js CHANGED
@@ -9,6 +9,9 @@ import {
9
9
  emitDrawnFeaturesMethod,
10
10
  createSelectHandler,
11
11
  handleLayerId,
12
+ onKeyDownMethod,
13
+ removeFeatureMethod,
14
+ removeFeatureByIndexMethod,
12
15
  } from "./methods/draw";
13
16
  import { DUMMY_GEO_JSON } from "./enums/index.js";
14
17
  import {
@@ -35,7 +38,17 @@ import {
35
38
  *
36
39
  * Usage examples and visual demos are available in Storybook stories, including scenarios for multi-feature drawing, feature modification, selection, import/export, continuous drawing, format and projection control, and style customization.
37
40
  *
41
+ * ## Methods
42
+ *
43
+ * - `startDrawing`: Triggers starting the drawing interaction on the map.
44
+ * - `discardDrawing`: Triggers discarding/stopping the drawing interaction and deleting the drawn shapes.
45
+ * - `removeFeature`: Removes a feature from the drawn features.
46
+ * - `removeFeatureByIndex`: Removes a feature from the drawn features by its index.
47
+ *
48
+ * Usage: `document.querySelector("eox-drawtools").startDrawing();`
49
+ *
38
50
  * @element eox-drawtools
51
+ * @fires {CustomEvent} drawupdate - Fires whenever features are added, modified or discarded
39
52
  */
40
53
  export class EOxDrawTools extends LitElement {
41
54
  // Define properties with defaults and types
@@ -85,11 +98,26 @@ export class EOxDrawTools extends LitElement {
85
98
  * @type string
86
99
  */
87
100
  #layerId;
101
+ /**
102
+ * @type boolean
103
+ */
104
+ #internalUpdate = false;
105
+
88
106
  /**
89
107
  * @type boolean
90
108
  */
91
109
  #continuous;
92
110
 
111
+ /**
112
+ * @type Array<import("ol").Feature>
113
+ */
114
+ #drawnFeatures = [];
115
+
116
+ /**
117
+ * @type {(e: KeyboardEvent) => void}
118
+ */
119
+ #onKeyDownListener = (e) => onKeyDownMethod(e, this);
120
+
93
121
  constructor() {
94
122
  super();
95
123
 
@@ -129,12 +157,6 @@ export class EOxDrawTools extends LitElement {
129
157
  */
130
158
  this.layerId = "";
131
159
 
132
- /**
133
- * The array of drawn native OpenLayers features. Normally includes only one feature, until multiple feature drawing is enabled.
134
- * @type Array<import("ol").Feature>
135
- */
136
- this.drawnFeatures = [];
137
-
138
160
  /**
139
161
  * The display name of drawn features, shown e.g. in the feature list.
140
162
  */
@@ -239,6 +261,53 @@ export class EOxDrawTools extends LitElement {
239
261
  return this.#continuous;
240
262
  }
241
263
 
264
+ /**
265
+ * Used internally to update the drawnFeatures state without overwriting the map layer source.
266
+ * @param {Array<import("ol").Feature>} features
267
+ * @ignore
268
+ */
269
+ setDrawnFeaturesInternal(features) {
270
+ this.#internalUpdate = true;
271
+ this.drawnFeatures = features;
272
+ this.#internalUpdate = false;
273
+ }
274
+
275
+ /**
276
+ * The array of drawn native OpenLayers features. Normally includes only one feature, until multiple feature drawing is enabled.
277
+ * Pass features to be drawn on the map by setting this property. The features should be in the same projection as the map, or a projection should be specified via the `projection` property for proper transformation.
278
+ * @type {Array<import("ol").Feature>}
279
+ */
280
+ set drawnFeatures(features) {
281
+ const oldValue = this.#drawnFeatures;
282
+ this.#drawnFeatures = features;
283
+ if (this.drawLayer && !this.#internalUpdate) {
284
+ this.drawLayer.getSource().clear();
285
+ if (features?.length) {
286
+ const source = this.eoxMap?.projection || "EPSG:3857";
287
+ const destination = this.projection || "EPSG:4326";
288
+
289
+ let featuresToAdd = features;
290
+ if (source && destination && source !== destination) {
291
+ featuresToAdd = features.map((feat) => {
292
+ feat = feat.clone();
293
+ const transformed = feat
294
+ .getGeometry()
295
+ .transform(destination, source);
296
+ feat.setGeometry(transformed);
297
+ return feat;
298
+ });
299
+ }
300
+ this.drawLayer.getSource().addFeatures(featuresToAdd);
301
+ }
302
+ this.updateGeoJSON();
303
+ }
304
+ this.requestUpdate("drawnFeatures", oldValue);
305
+ }
306
+
307
+ get drawnFeatures() {
308
+ return this.#drawnFeatures;
309
+ }
310
+
242
311
  /**
243
312
  * Enables selection mode for the passed layer
244
313
  * @type {string}
@@ -253,24 +322,40 @@ export class EOxDrawTools extends LitElement {
253
322
  }
254
323
 
255
324
  /**
256
- * @onClick Event handler triggered to start drawing on the map.
325
+ * Triggers starting the drawing interaction on the map.
257
326
  */
258
327
  startDrawing() {
259
328
  startDrawingMethod(this);
260
329
  }
261
330
 
262
331
  /**
263
- * @onClick Event handler triggered to discard/stop drawing
264
- * on the map and delete the drawn shapes.
332
+ * Triggers discarding/stopping the drawing interaction and deleting the drawn shapes.
265
333
  */
266
334
  discardDrawing() {
267
335
  discardDrawingMethod(this);
268
336
  }
269
337
 
338
+ /**
339
+ * Removes a feature from the drawn features.
340
+ * @param {import("ol").Feature} feature - The feature to remove.
341
+ */
342
+ removeFeature(feature) {
343
+ removeFeatureMethod(this, feature);
344
+ }
345
+
346
+ /**
347
+ * Removes a feature from the drawn features by its index.
348
+ * @param {number} index - The index of the feature to remove.
349
+ */
350
+ removeFeatureByIndex(index) {
351
+ removeFeatureByIndexMethod(this, index);
352
+ }
353
+
270
354
  /**
271
355
  * @param {string} text - The string representation of the features to be parsed.
272
356
  * @param {boolean} replaceFeatures - A boolean flag indicating whether to replace the existing features.
273
357
  * @param {boolean} animate - A boolean flag indicating whether to animate the map on feature change.
358
+ * @ignore
274
359
  */
275
360
  handleFeatureChange(text, replaceFeatures = false, animate = true) {
276
361
  this.eoxMap.parseTextToFeature(
@@ -284,6 +369,7 @@ export class EOxDrawTools extends LitElement {
284
369
 
285
370
  /**
286
371
  * @param {DragEvent | InputEvent & { target: HTMLInputElement }} evt - The event object from the file input interaction.
372
+ * @ignore
287
373
  */
288
374
  handleFilesChange(evt) {
289
375
  handleFiles(evt, this);
@@ -291,6 +377,7 @@ export class EOxDrawTools extends LitElement {
291
377
 
292
378
  /**
293
379
  * @event onModifyEnd triggered when the modification of a shape is completed.
380
+ * @ignore
294
381
  */
295
382
  onModifyEnd() {
296
383
  this.emitDrawnFeatures();
@@ -298,6 +385,7 @@ export class EOxDrawTools extends LitElement {
298
385
 
299
386
  /**
300
387
  * Update #geoJSON with stringify feature.
388
+ * @ignore
301
389
  */
302
390
  updateGeoJSON() {
303
391
  this.#geoJSON = JSON.stringify(
@@ -309,6 +397,7 @@ export class EOxDrawTools extends LitElement {
309
397
 
310
398
  /**
311
399
  * Triggers different events when the drawing of a shape is completed.
400
+ * @ignore
312
401
  */
313
402
  emitDrawnFeatures() {
314
403
  /**
@@ -327,6 +416,7 @@ export class EOxDrawTools extends LitElement {
327
416
 
328
417
  /**
329
418
  * Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
419
+ * @ignore
330
420
  */
331
421
  createRenderRoot() {
332
422
  return this.noShadow ? this : super.createRenderRoot();
@@ -335,9 +425,12 @@ export class EOxDrawTools extends LitElement {
335
425
  /**
336
426
  * initializes the EOxMap and OlMap instances
337
427
  * And stores them in the private properties #eoxMap and #olMap, respectively.
338
- * It then calls requestUpdate to trigger a re-render.
428
+ * @ignore
339
429
  */
340
- firstUpdated() {
430
+ updateLayer() {
431
+ if (this.resetLayer) {
432
+ this.resetLayer(this);
433
+ }
341
434
  const { EoxMap, OlMap, reset } = initLayerMethod(
342
435
  this,
343
436
  this.multipleFeatures,
@@ -345,28 +438,41 @@ export class EOxDrawTools extends LitElement {
345
438
  this.resetLayer = reset;
346
439
  this.eoxMap = EoxMap;
347
440
  this.#olMap = OlMap;
441
+ }
442
+
443
+ /**
444
+ * initializes the EOxMap and OlMap instances
445
+ * And stores them in the private properties #eoxMap and #olMap, respectively.
446
+ * It then calls requestUpdate to trigger a re-render.
447
+ * @ignore
448
+ */
449
+ firstUpdated() {
450
+ this.updateLayer();
348
451
  this.selectionEvents = createSelectHandler(this);
349
452
 
350
453
  if (this.importFeatures) initMapDragDropImport(this, this.eoxMap);
351
454
 
352
- this.updateGeoJSON();
455
+ if (this.drawnFeatures?.length > 0) {
456
+ this.drawnFeatures = [...this.drawnFeatures];
457
+ } else {
458
+ this.updateGeoJSON();
459
+ }
353
460
  this.requestUpdate();
354
461
  }
355
462
 
463
+ /** @ignore */
356
464
  updated(changedProperties) {
357
- if (changedProperties.has("for")) {
358
- const { EoxMap, OlMap } = initLayerMethod(this, this.multipleFeatures);
359
- this.eoxMap = EoxMap;
360
- this.#olMap = OlMap;
361
- }
465
+ const hasOldValue = (prop) =>
466
+ changedProperties.has(prop) && changedProperties.get(prop) !== undefined;
467
+
362
468
  if (
363
- (changedProperties.get("type") &&
469
+ hasOldValue("for") ||
470
+ (changedProperties.has("type") &&
364
471
  changedProperties.get("type") !== this.type) ||
365
472
  (changedProperties.has("measure") &&
366
473
  changedProperties.get("measure") !== this.measure)
367
474
  ) {
368
- this.resetLayer(this);
369
- this.firstUpdated();
475
+ this.updateLayer();
370
476
  this.currentlyDrawing = false;
371
477
  }
372
478
  }
@@ -385,16 +491,20 @@ export class EOxDrawTools extends LitElement {
385
491
  this.requestUpdate("eoxMap", oldValue);
386
492
  }
387
493
 
494
+ /** @ignore */
388
495
  connectedCallback() {
389
496
  super.connectedCallback();
497
+ document.addEventListener("keydown", this.#onKeyDownListener);
390
498
  if (this.drawLayer && this.eoxMap) {
391
499
  const { reset } = initLayerMethod(this, this.multipleFeatures);
392
500
  this.resetLayer = reset;
393
501
  }
394
502
  }
395
503
 
504
+ /** @ignore */
396
505
  disconnectedCallback() {
397
506
  super.disconnectedCallback();
507
+ document.removeEventListener("keydown", this.#onKeyDownListener);
398
508
  this.resetLayer?.(this);
399
509
  }
400
510
  // Render method for UI display
@@ -22,7 +22,7 @@ const emitDrawnFeaturesMethod = (EoxDrawTool, drawUpdateEvent) => {
22
22
  // has a default value of EPSG:4326
23
23
  const destination = EoxDrawTool.projection;
24
24
  // Update drawnFeatures with transformed features if the destination is defined
25
- EoxDrawTool.drawnFeatures = destination
25
+ const newFeatures = destination
26
26
  ? drawnFeatures.map((feat) => {
27
27
  feat = feat.clone();
28
28
  const transformed = feat.getGeometry().transform(source, destination);
@@ -31,6 +31,12 @@ const emitDrawnFeaturesMethod = (EoxDrawTool, drawUpdateEvent) => {
31
31
  })
32
32
  : drawnFeatures;
33
33
 
34
+ if (EoxDrawTool.setDrawnFeaturesInternal) {
35
+ EoxDrawTool.setDrawnFeaturesInternal(newFeatures);
36
+ } else {
37
+ EoxDrawTool.drawnFeatures = newFeatures;
38
+ }
39
+
34
40
  // Emit features based on the format provided
35
41
  let value;
36
42
  switch (EoxDrawTool.format) {
@@ -9,3 +9,8 @@ export { default as createSelectHandler } from "./create-select-handler"; // Fac
9
9
  export { default as initSelection } from "./init-selection"; // Initializes selection interactions
10
10
  export { default as handleLayerId } from "./handle-layer-id"; // handle switching between selection and drawing
11
11
  export { default as initMeasuring, updateMeasure } from "./init-measuring"; // Initializes measuring logic
12
+ export { default as onKeyDownMethod } from "./on-key-down.js"; // Handles keydown events
13
+ export {
14
+ removeFeatureMethod,
15
+ removeFeatureByIndexMethod,
16
+ } from "./remove-feature"; // Handles removing a feature
@@ -73,32 +73,36 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
73
73
  },
74
74
  },
75
75
  },
76
- {
77
- type: "select",
78
- options: {
79
- id: "SelectLayerHoverInteraction",
80
- condition: "pointermove",
81
- style: EoxDrawTool.featureStyles?.["hover"] || {
82
- "fill-color": `rgba(${primaryColor}, 0.2)`,
83
- "stroke-color": `rgba(${primaryColor}, 1)`,
84
- "stroke-width": 2,
85
- },
86
- tooltip: false,
87
- },
88
- },
89
- {
90
- type: "select",
91
- options: {
92
- id: "SelectLayerClickInteraction",
93
- condition: "click",
94
- panIn: true,
95
- style: EoxDrawTool.featureStyles?.["click"] || {
96
- "fill-color": `rgba(${primaryColor}, 0.2)`,
97
- "stroke-color": `rgba(${primaryColor}, 1)`,
98
- "stroke-width": 2,
99
- },
100
- },
101
- },
76
+ ...(!EoxDrawTool.layerId
77
+ ? /** @type {import("@eox/map/src/types").EOxInteraction[]} */ ([
78
+ {
79
+ type: "select",
80
+ options: {
81
+ id: "SelectLayerHoverInteraction",
82
+ condition: "pointermove",
83
+ style: EoxDrawTool.featureStyles?.["hover"] || {
84
+ "fill-color": `rgba(${primaryColor}, 0.2)`,
85
+ "stroke-color": `rgba(${primaryColor}, 1)`,
86
+ "stroke-width": 2,
87
+ },
88
+ tooltip: false,
89
+ },
90
+ },
91
+ {
92
+ type: "select",
93
+ options: {
94
+ id: "SelectLayerClickInteraction",
95
+ condition: "click",
96
+ panIn: true,
97
+ style: EoxDrawTool.featureStyles?.["click"] || {
98
+ "fill-color": `rgba(${primaryColor}, 0.2)`,
99
+ "stroke-color": `rgba(${primaryColor}, 1)`,
100
+ "stroke-width": 2,
101
+ },
102
+ },
103
+ },
104
+ ])
105
+ : []),
102
106
  ],
103
107
  });
104
108
 
@@ -107,7 +111,7 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
107
111
  );
108
112
 
109
113
  EoxDrawTool.modify = /** @type {import("ol/interaction").Modify} */ (
110
- /** @type {unknown} */ (EoxMap.interactions["drawInteractionmodify"])
114
+ /** @type {unknown} */ (EoxMap.interactions["drawInteraction_modify"])
111
115
  );
112
116
 
113
117
  // Initialize selection interactions
@@ -123,19 +127,17 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
123
127
  EoxDrawTool.modify?.on("modifyend", onModifyEnd);
124
128
 
125
129
  if (EoxDrawTool.measure) {
126
- EoxDrawTool.draw?.on("drawstart", (evt) => {
127
- const feature = evt.feature;
128
- updateMeasure(feature);
129
- feature.getGeometry().on("change", () => updateMeasure(feature));
130
- });
130
+ if (EoxDrawTool.draw && typeof EoxDrawTool.draw.on === "function") {
131
+ EoxDrawTool.draw.on("drawstart", (evt) => {
132
+ const feature = evt.feature;
133
+ updateMeasure(feature);
134
+ feature.getGeometry().on("change", () => updateMeasure(feature));
135
+ });
136
+ }
131
137
  }
132
138
 
133
139
  EoxMap.addEventListener("addfeatures", onAddFeatures);
134
140
 
135
- if (EoxDrawTool.drawnFeatures) {
136
- EoxDrawTool.drawLayer.getSource().addFeatures(EoxDrawTool.drawnFeatures);
137
- }
138
-
139
141
  /**
140
142
  * Resets the draw layer, cleaning up interactions and listeners.
141
143
  *
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Handles keydown events for the drawing tool.
3
+ * Specifically, it aborts the drawing process when the Escape key is pressed.
4
+ *
5
+ * @param {KeyboardEvent} event - The keyboard event.
6
+ * @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
7
+ */
8
+ const onKeyDownMethod = (event, EoxDrawTool) => {
9
+ if (event.key === "Escape" && EoxDrawTool.currentlyDrawing) {
10
+ EoxDrawTool.draw?.setActive(false);
11
+ EoxDrawTool.currentlyDrawing = false;
12
+ EoxDrawTool.requestUpdate();
13
+ }
14
+ };
15
+
16
+ export default onKeyDownMethod;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Removes a feature from the drawn features.
3
+ *
4
+ * @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
5
+ * @param {import("ol").Feature} feature - The feature to remove.
6
+ */
7
+ export function removeFeatureMethod(EoxDrawTool, feature) {
8
+ const index = EoxDrawTool.drawnFeatures.indexOf(feature);
9
+ if (index > -1) {
10
+ removeFeatureByIndexMethod(EoxDrawTool, index);
11
+ }
12
+ }
13
+
14
+ /**
15
+ * Removes a feature from the drawn features by its index.
16
+ *
17
+ * @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
18
+ * @param {number} index - The index of the feature to remove.
19
+ */
20
+ export function removeFeatureByIndexMethod(EoxDrawTool, index) {
21
+ if (index > -1 && index < EoxDrawTool.drawnFeatures.length) {
22
+ const newFeatures = [...EoxDrawTool.drawnFeatures];
23
+ newFeatures.splice(index, 1);
24
+ EoxDrawTool.drawnFeatures = newFeatures;
25
+ EoxDrawTool.emitDrawnFeatures();
26
+ }
27
+ }
@@ -23,15 +23,6 @@ const startDrawingMethod = (EoxDrawTool) => {
23
23
  initializeDrawing();
24
24
  // Update the drawing status
25
25
  updateDrawingStatus();
26
-
27
- // Abort drawing on Esc key
28
- document.addEventListener("keydown", ({ key }) => {
29
- if (key === "Escape" && EoxDrawTool.currentlyDrawing) {
30
- EoxDrawTool.draw?.setActive(false);
31
- EoxDrawTool.currentlyDrawing = false;
32
- EoxDrawTool.requestUpdate();
33
- }
34
- });
35
26
  };
36
27
 
37
28
  export default startDrawingMethod;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/components/controller.js"],"names":[],"mappings":"AAKA;;;;GAIG;AACH;IAEE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAWE;IAeA;;OAEG;IACH,0BAA6B;IAE7B;;;;;OAKG;IACH,eAFS,KAAK,CAAC,OAAO,IAAI,EAAE,OAAO,CAAC,CAEb;IAEvB;;;OAGG;IACH,wBAA2B;IAE3B;;;OAGG;IACH,oBAAuB;IAEvB;;OAEG;IACH,0BAA6B;IAE7B;;OAEG;IACH,cAAoB;IAEpB;;;OAGG;IACH,gBAAiB;IAEjB;;;OAGG;IACH,MAFU,SAAS,GAAG,OAAO,GAAG,YAAY,GAAG,QAAQ,GAAG,KAAK,CAE1C;IAErB;;OAEG;IACH,kBAAqB;IAErB;;OAEG;IACH,gBAAmB;IAGrB;;OAEG;IACH,2BAKC;IAED;;OAEG;IACH,yBAEC;IAED,+CA0NC;;CACF;2BA5UyC,KAAK"}
@@ -51,11 +51,11 @@ export class EOxDrawToolsList extends LitElement {
51
51
  /**
52
52
  * @type {import("@eox/map").EOxMap["selectInteractions"][string]}
53
53
  */
54
- hoverInteraction: import("@eox/map").EOxMap["selectInteractions"][string];
54
+ hoverInteraction: any["selectInteractions"][string];
55
55
  /**
56
56
  * @type {import("@eox/map").EOxMap["selectInteractions"][string]}
57
57
  */
58
- clickInteraction: import("@eox/map").EOxMap["selectInteractions"][string];
58
+ clickInteraction: any["selectInteractions"][string];
59
59
  /**
60
60
  * @type string | number
61
61
  */
@@ -71,7 +71,7 @@ export class EOxDrawToolsList extends LitElement {
71
71
  /**
72
72
  * @type import("@eox/map").EOxMap
73
73
  */
74
- eoxMap: import("@eox/map").EOxMap;
74
+ eoxMap: any;
75
75
  /**
76
76
  * @type import("ol").Map
77
77
  */
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/components/list.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH;IACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAWE;IAEF;;OAEG;IACH,kBAFU,GAAyB,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAEhD;IAEjB;;OAEG;IACH,kBAFU,GAAyB,CAAC,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAEhD;IAEjB;;OAEG;IACH,SAFS,MAAM,GAAG,MAAM,CAEhB;IAER;;OAEG;IACH,SAFS,MAAM,GAAG,MAAM,CAEhB;IAKN;;OAEG;IACH,cAFS,OAAO,SAAS,EAAE,YAAY,CAEf;IAExB;;OAEG;IACH,YAAkB;IAElB;;OAEG;IACH,OAFS,OAAO,IAAI,EAAE,GAAG,CAER;IAEjB;;;OAGG;IAEH,MAHS,OAAO,gBAAgB,EAAE,IAAI,CAGtB;IAEhB;;;OAGG;IAEH,WAHS,OAAO,UAAU,EAAE,MAAM,CAAC,OAAO,WAAW,EAAE,MAAM,CAAC,CAGzC;IAErB;;;;;OAKG;IACH,eAFS,KAAK,CAAC,OAAO,IAAI,EAAE,OAAO,CAAC,CAEb;IAEvB;;OAEG;IACH,oBAA4B;IAE5B;;OAEG;IACH,oBAA0B;IAE1B;;;OAGG;IAEH,QAHS,OAAO,gBAAgB,EAAE,MAAM,CAGtB;IAElB;;OAEG;IACH,kBAAqB;IAGvB;;;;OAIG;IACH,mBAFW,KAAK,GAAG;QAAE,MAAM,EAAE,iBAAiB,CAAA;KAAE,QAK/C;IAED;;;;OAIG;IACH,yCAFW,OAAO,IAAI,EAAE,OAAO,QAI9B;IAED;;;;OAIG;IACH,+BAHW,MAAM,GAAG,MAAM,GAAG,SAAS,4BAKrC;IAED;;OAEG;IACH,qBAEC;IAED;;OAEG;IACH,yBAEC;IAED,+CAwEC;CACF;2BAlOyC,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../../../src/enums/draw.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"draw.d.ts","sourceRoot":"","sources":["../../src/enums/draw.js"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/enums/index.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/enums/index.js"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stories.d.ts","sourceRoot":"","sources":["../../src/enums/stories.js"],"names":[],"mappings":"AAAA;;;;;IAOE;AAEF;;;;;;;;;;;;;;;;;IAmBE;AAEF,gCAAiC,8BAA8B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../../../src/enums/test.js"],"names":[],"mappings":""}
1
+ {"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../../src/enums/test.js"],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-text-to-clipboard.d.ts","sourceRoot":"","sources":["../../src/helpers/copy-text-to-clipboard.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kDAFW,MAAM,QAShB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features-to-geojson.d.ts","sourceRoot":"","sources":["../../src/helpers/features-to-geojson.js"],"names":[],"mappings":";AAEA;;;;;GAKG;AACH,6CAHW,OAAO,IAAI,EAAE,OAAO,EAAE,YACrB,UAAU,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAE,GAAG,CAAC;;GAK3D;oBAXmB,mBAAmB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features-to-wkt.d.ts","sourceRoot":"","sources":["../../src/helpers/features-to-wkt.js"],"names":[],"mappings":";AAEA;;;;GAIG;AACH,4BAFU,GAAG,CAAC,eAAe,CAAC,CAK5B;gBAVc,kBAAkB"}