@eox/drawtools 0.9.0 → 0.10.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.
- package/README.md +4 -0
- package/dist/eox-drawtools.js +81 -81
- package/dist/eox-drawtools.umd.cjs +9 -9
- package/package.json +5 -13
- package/src/components/controller.js +187 -0
- package/src/components/list.js +189 -0
- package/src/enums/draw.js +5 -0
- package/src/enums/index.js +9 -0
- package/src/enums/stories.js +17 -0
- package/src/enums/test.js +7 -0
- package/src/helpers/copy-text-to-clipboard.js +13 -0
- package/src/helpers/generate-upload-events.js +82 -0
- package/src/helpers/index.js +3 -0
- package/src/main.js +302 -0
- package/src/methods/controller/index.js +3 -0
- package/src/methods/controller/update-button-states.js +23 -0
- package/src/methods/draw/discard-drawing.js +29 -0
- package/src/methods/draw/emit-drawn-features.js +23 -0
- package/src/methods/draw/index.js +7 -0
- package/src/methods/draw/init-layer.js +83 -0
- package/src/methods/draw/on-draw-end.js +22 -0
- package/src/methods/draw/start-drawing.js +27 -0
- package/src/methods/list/delete-feature.js +24 -0
- package/src/methods/list/first-update.js +31 -0
- package/src/methods/list/hover-feature.js +17 -0
- package/src/methods/list/index.js +6 -0
- package/src/methods/list/select-deselect-feature.js +31 -0
- package/src/style.eox.js +43 -0
- package/test/_mockMap.js +0 -54
- package/test/cases/click-discard-btn.js +0 -30
- package/test/cases/click-draw-btn.js +0 -27
- package/test/cases/copy-geo-json-editor.js +0 -37
- package/test/cases/index.js +0 -6
- package/test/cases/load-drawtool.js +0 -14
- package/test/general.cy.js +0 -39
package/src/main.js
ADDED
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import "./components/list";
|
|
3
|
+
import "./components/controller";
|
|
4
|
+
import { styleEOX } from "./style.eox";
|
|
5
|
+
import {
|
|
6
|
+
startDrawingMethod,
|
|
7
|
+
initLayerMethod,
|
|
8
|
+
discardDrawingMethod,
|
|
9
|
+
emitDrawnFeaturesMethod,
|
|
10
|
+
} from "./methods/draw";
|
|
11
|
+
import mainStyle from "@eox/elements-utils/styles/dist/main.style";
|
|
12
|
+
import { DUMMY_GEO_JSON } from "./enums/index.js";
|
|
13
|
+
import {
|
|
14
|
+
initMapDragDropImport,
|
|
15
|
+
handleFiles,
|
|
16
|
+
} from "./helpers/generate-upload-events.js";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Manage drawn features on a map
|
|
20
|
+
*
|
|
21
|
+
* @element eox-drawtools
|
|
22
|
+
*/
|
|
23
|
+
export class EOxDrawTools extends LitElement {
|
|
24
|
+
// Define properties with defaults and types
|
|
25
|
+
static get properties() {
|
|
26
|
+
return {
|
|
27
|
+
allowModify: { attribute: "allow-modify", type: Boolean },
|
|
28
|
+
for: { type: String },
|
|
29
|
+
currentlyDrawing: { attribute: false, state: true, type: Boolean },
|
|
30
|
+
draw: { attribute: false, state: true },
|
|
31
|
+
drawLayer: { attribute: false, state: true },
|
|
32
|
+
drawnFeatures: { attribute: false, state: true, type: Array },
|
|
33
|
+
modify: { attribute: false, state: true },
|
|
34
|
+
multipleFeatures: { attribute: "multiple-features", type: Boolean },
|
|
35
|
+
importFeatures: { attribute: "import-features", type: Boolean },
|
|
36
|
+
showEditor: { attribute: "show-editor", type: Boolean },
|
|
37
|
+
showList: { attribute: "show-list", type: Boolean },
|
|
38
|
+
noShadow: { type: Boolean },
|
|
39
|
+
type: { type: String },
|
|
40
|
+
unstyled: { type: Boolean },
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @type import("../../map/main").EOxMap
|
|
46
|
+
*/
|
|
47
|
+
#eoxMap;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @type import("ol").Map
|
|
51
|
+
*/
|
|
52
|
+
#olMap;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @type string
|
|
56
|
+
*/
|
|
57
|
+
#geoJSON;
|
|
58
|
+
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Allow modifying the drawn feature(s)
|
|
64
|
+
*/
|
|
65
|
+
this.allowModify = false;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Query selector of an `eox-map` (`String`, passed as an attribute or property)
|
|
69
|
+
* or an `eox-map` DOM element (`HTMLElement`, passed as property)
|
|
70
|
+
*
|
|
71
|
+
* @type {String|HTMLElement}
|
|
72
|
+
*/
|
|
73
|
+
this.for = "eox-map";
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Whether the user is currently in the process of drawing or not
|
|
77
|
+
*/
|
|
78
|
+
this.currentlyDrawing = false;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The current native OpenLayers `draw` interaction
|
|
82
|
+
* @type import("ol/interaction").Draw
|
|
83
|
+
*/
|
|
84
|
+
this.draw = null;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The current native OpenLayers draw `layer`
|
|
88
|
+
* @type import("ol/layer/Vector").default<import("ol/Feature").default>
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
this.drawLayer = null;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The array of drawn native OpenLayers features. Normally includes only one feature, until multiple feature drawing is enabled.
|
|
95
|
+
* @type Array<import("ol").Feature>
|
|
96
|
+
*/
|
|
97
|
+
this.drawnFeatures = [];
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The current native OpenLayers `modify` interaction
|
|
101
|
+
* @type import("ol/interaction").Modify
|
|
102
|
+
*/
|
|
103
|
+
this.modify = null;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Allow adding more than one feature at a time
|
|
107
|
+
*/
|
|
108
|
+
this.multipleFeatures = false;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Allow import features using drag-drop and upload button
|
|
112
|
+
*/
|
|
113
|
+
this.importFeatures = false;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Show geo-json editor for draw tool
|
|
117
|
+
*/
|
|
118
|
+
this.showEditor = false;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Show list of features
|
|
122
|
+
*/
|
|
123
|
+
this.showList = false;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Type of the drawn feature
|
|
127
|
+
* @type {"Polygon" | "Point" | "LineString" | "Circle" | "Box"}
|
|
128
|
+
*/
|
|
129
|
+
this.type = "Polygon";
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Render the element without additional styles
|
|
133
|
+
*/
|
|
134
|
+
this.unstyled = false;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Renders the element without a shadow root
|
|
138
|
+
*
|
|
139
|
+
* @type {Boolean}
|
|
140
|
+
*/
|
|
141
|
+
this.noShadow = false;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @onClick Event handler triggered to start drawing on the map.
|
|
146
|
+
*/
|
|
147
|
+
handleStartDrawing() {
|
|
148
|
+
startDrawingMethod(this);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @onClick Event handler triggered to discard/stop drawing
|
|
153
|
+
* on the map and delete the drawn shapes.
|
|
154
|
+
*/
|
|
155
|
+
handleDiscardDrawing() {
|
|
156
|
+
discardDrawingMethod(this);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param {string} text - The string representation of the features to be parsed.
|
|
161
|
+
* @param {boolean} replaceFeatures - A boolean flag indicating whether to replace the existing features.
|
|
162
|
+
*/
|
|
163
|
+
handleFeatureChange(text, replaceFeatures = false) {
|
|
164
|
+
this.eoxMap.parseTextToFeature(
|
|
165
|
+
text || JSON.stringify(DUMMY_GEO_JSON),
|
|
166
|
+
this.drawLayer,
|
|
167
|
+
replaceFeatures,
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @param {DragEvent | Event} evt - The event object from the file input interaction.
|
|
173
|
+
*/
|
|
174
|
+
handleFilesChange(evt) {
|
|
175
|
+
handleFiles(evt, this);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @event onModifyEnd triggered when the modification of a shape is completed.
|
|
180
|
+
*/
|
|
181
|
+
onModifyEnd() {
|
|
182
|
+
this.emitDrawnFeatures();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Update #geoJSON with stringify feature.
|
|
187
|
+
*/
|
|
188
|
+
updateGeoJSON() {
|
|
189
|
+
this.#geoJSON = JSON.stringify(
|
|
190
|
+
this.eoxMap.parseFeature(this.drawnFeatures) || DUMMY_GEO_JSON,
|
|
191
|
+
undefined,
|
|
192
|
+
2,
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Triggers different events when the drawing of a shape is completed.
|
|
198
|
+
*/
|
|
199
|
+
emitDrawnFeatures() {
|
|
200
|
+
const drawUpdateEvent = () => {
|
|
201
|
+
/**
|
|
202
|
+
* Fires whenever features are added, modified or discarded, where the event detail
|
|
203
|
+
* is the `drawnFeatures` array
|
|
204
|
+
* @type Array<import("ol").Feature>
|
|
205
|
+
*/
|
|
206
|
+
this.dispatchEvent(
|
|
207
|
+
new CustomEvent("drawupdate", { detail: this.drawnFeatures }),
|
|
208
|
+
);
|
|
209
|
+
};
|
|
210
|
+
emitDrawnFeaturesMethod(this, drawUpdateEvent);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
|
|
215
|
+
*/
|
|
216
|
+
createRenderRoot() {
|
|
217
|
+
return this.noShadow ? this : super.createRenderRoot();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* initializes the EOxMap and OlMap instances
|
|
222
|
+
* And stores them in the private properties #eoxMap and #olMap, respectively.
|
|
223
|
+
* It then calls requestUpdate to trigger a re-render.
|
|
224
|
+
*/
|
|
225
|
+
firstUpdated() {
|
|
226
|
+
const { EoxMap, OlMap } = initLayerMethod(this, this.multipleFeatures);
|
|
227
|
+
this.eoxMap = EoxMap;
|
|
228
|
+
this.#olMap = OlMap;
|
|
229
|
+
|
|
230
|
+
if (this.importFeatures) initMapDragDropImport(this, this.eoxMap);
|
|
231
|
+
|
|
232
|
+
this.updateGeoJSON();
|
|
233
|
+
this.requestUpdate();
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
updated(changedProperties) {
|
|
237
|
+
if (changedProperties.has("for")) {
|
|
238
|
+
const { EoxMap, OlMap } = initLayerMethod(this, this.multipleFeatures);
|
|
239
|
+
this.eoxMap = EoxMap;
|
|
240
|
+
this.#olMap = OlMap;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
get eoxMap() {
|
|
245
|
+
return this.#eoxMap;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
set eoxMap(value) {
|
|
249
|
+
const oldValue = this.#eoxMap;
|
|
250
|
+
this.#eoxMap = value;
|
|
251
|
+
this.requestUpdate("eoxMap", oldValue);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Render method for UI display
|
|
255
|
+
render() {
|
|
256
|
+
return html`
|
|
257
|
+
<style>
|
|
258
|
+
:host { display: block; }
|
|
259
|
+
${!this.unstyled && mainStyle}
|
|
260
|
+
${!this.unstyled && styleEOX}
|
|
261
|
+
</style>
|
|
262
|
+
|
|
263
|
+
<!-- Controller Component -->
|
|
264
|
+
<eox-drawtools-controller
|
|
265
|
+
.drawFunc=${{
|
|
266
|
+
start: () => this.handleStartDrawing(),
|
|
267
|
+
discard: () => this.handleDiscardDrawing(),
|
|
268
|
+
editor: (/** @type {{ target: { value: string; }; }} */ evt) =>
|
|
269
|
+
this.handleFeatureChange(evt.target.value, true),
|
|
270
|
+
import: (/** @type {DragEvent | Event} */ evt) =>
|
|
271
|
+
this.handleFilesChange(evt),
|
|
272
|
+
}}
|
|
273
|
+
.unstyled=${this.unstyled}
|
|
274
|
+
.drawnFeatures=${this.drawnFeatures}
|
|
275
|
+
.currentlyDrawing=${this.currentlyDrawing}
|
|
276
|
+
.multipleFeatures=${this.multipleFeatures}
|
|
277
|
+
.importFeatures=${this.importFeatures}
|
|
278
|
+
.showEditor=${this.showEditor}
|
|
279
|
+
.geoJSON=${this.#geoJSON}
|
|
280
|
+
></eox-drawtools-controller>
|
|
281
|
+
|
|
282
|
+
<!-- List Component -->
|
|
283
|
+
${this.showList && this.drawnFeatures?.length
|
|
284
|
+
? html`<eox-drawtools-list
|
|
285
|
+
.eoxMap=${this.eoxMap}
|
|
286
|
+
.olMap=${this.#olMap}
|
|
287
|
+
.draw=${this.draw}
|
|
288
|
+
.drawLayer=${this.drawLayer}
|
|
289
|
+
.drawnFeatures=${this.drawnFeatures}
|
|
290
|
+
.modify=${this.modify}
|
|
291
|
+
.unstyled=${this.unstyled}
|
|
292
|
+
@changed=${() => {
|
|
293
|
+
this.updateGeoJSON();
|
|
294
|
+
this.requestUpdate();
|
|
295
|
+
}}
|
|
296
|
+
></eox-drawtools-list>`
|
|
297
|
+
: nothing}
|
|
298
|
+
`;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
customElements.define("eox-drawtools", EOxDrawTools);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Update button state of draw and discard buttons based on specific conditions.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../components/controller").EOxDrawToolsController} EoxDrawToolController - The controller instance.
|
|
5
|
+
* @returns {{ drawDisabled: boolean | import("lit").nothing, discardDisabled: boolean | import("lit").nothing }} - The updated button states.
|
|
6
|
+
*/
|
|
7
|
+
const updateButtonStatesMethod = (EoxDrawToolController) => {
|
|
8
|
+
// Destructure relevant properties from the controller
|
|
9
|
+
const { multipleFeatures, drawnFeatures, currentlyDrawing } =
|
|
10
|
+
EoxDrawToolController;
|
|
11
|
+
|
|
12
|
+
// Determine draw button's disabled state based on conditions
|
|
13
|
+
const drawDisabled =
|
|
14
|
+
(!multipleFeatures && drawnFeatures?.length > 0) || currentlyDrawing;
|
|
15
|
+
|
|
16
|
+
// Determine discard button's disabled state based on conditions
|
|
17
|
+
const discardDisabled = !drawnFeatures?.length && !currentlyDrawing;
|
|
18
|
+
|
|
19
|
+
// Return the updated button states
|
|
20
|
+
return { drawDisabled, discardDisabled };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default updateButtonStatesMethod;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Discards drawing on the map, resets drawing interactions and features,
|
|
3
|
+
* clears the source, and triggers updates.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
*/
|
|
7
|
+
const discardDrawingMethod = (EoxDrawTool) => {
|
|
8
|
+
// Function to discard drawing interactions and features
|
|
9
|
+
const discardDrawingActions = () => {
|
|
10
|
+
// Reset drawnFeatures, deactivate drawing, and clear drawLayer's source
|
|
11
|
+
EoxDrawTool.drawnFeatures = [];
|
|
12
|
+
EoxDrawTool.draw.setActive(false);
|
|
13
|
+
EoxDrawTool.drawLayer.getSource().clear();
|
|
14
|
+
EoxDrawTool.geoJSON = null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Function to trigger updates after discarding drawing
|
|
18
|
+
const triggerUpdates = () => {
|
|
19
|
+
EoxDrawTool.emitDrawnFeatures();
|
|
20
|
+
EoxDrawTool.currentlyDrawing = false;
|
|
21
|
+
EoxDrawTool.requestUpdate();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// Execute the discard actions and trigger updates
|
|
25
|
+
discardDrawingActions();
|
|
26
|
+
triggerUpdates();
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default discardDrawingMethod;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emits drawn features after a timeout to allow updating drawn features.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
5
|
+
* @param {Function} drawUpdateEvent - event to be triggered after drawFeature is updated
|
|
6
|
+
*/
|
|
7
|
+
const emitDrawnFeaturesMethod = (EoxDrawTool, drawUpdateEvent) => {
|
|
8
|
+
// Function to emit features after a timeout (ensures update)
|
|
9
|
+
const emitFeatures = () => {
|
|
10
|
+
// Update drawnFeatures with features from drawLayer's source
|
|
11
|
+
EoxDrawTool.drawnFeatures = EoxDrawTool.drawLayer.getSource().getFeatures();
|
|
12
|
+
EoxDrawTool.updateGeoJSON();
|
|
13
|
+
EoxDrawTool.requestUpdate();
|
|
14
|
+
|
|
15
|
+
// Triggering `drawupdate` event after drawFeature is updated
|
|
16
|
+
drawUpdateEvent();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Emit features after a timeout (ensures update)
|
|
20
|
+
setTimeout(emitFeatures, 0);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default emitDrawnFeaturesMethod;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Import and export methods
|
|
2
|
+
|
|
3
|
+
export { default as onDrawEndMethod } from "./on-draw-end"; // Handles actions after drawing ends
|
|
4
|
+
export { default as startDrawingMethod } from "./start-drawing"; // Initializes the drawing process
|
|
5
|
+
export { default as initLayerMethod } from "./init-layer.js"; // Initializes layer and map interactions
|
|
6
|
+
export { default as discardDrawingMethod } from "./discard-drawing"; // Handles discarding the drawing process
|
|
7
|
+
export { default as emitDrawnFeaturesMethod } from "./emit-drawn-features"; // Emits drawn features
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { onDrawEndMethod } from "./";
|
|
2
|
+
|
|
3
|
+
import { getElement } from "@eox/elements-utils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Initializes the draw layer, interacts with the map, and returns map instances.
|
|
7
|
+
*
|
|
8
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
9
|
+
* @param {Boolean} multipleFeatures - Allow adding more than one feature at a time
|
|
10
|
+
* @returns {{EoxMap: import("@eox/map/main").EOxMap, OlMap: import("ol").Map}} - The map instances.
|
|
11
|
+
*/
|
|
12
|
+
const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
13
|
+
const mapQuery = getElement(EoxDrawTool.for);
|
|
14
|
+
|
|
15
|
+
const EoxMap = /** @type {import("@eox/map/main").EOxMap} */ (mapQuery);
|
|
16
|
+
// @ts-expect-error TODO
|
|
17
|
+
const OlMap = EoxMap.map;
|
|
18
|
+
|
|
19
|
+
// @ts-expect-error TODO
|
|
20
|
+
EoxDrawTool.drawLayer = EoxMap.addOrUpdateLayer({
|
|
21
|
+
type: "Vector",
|
|
22
|
+
properties: {
|
|
23
|
+
id: "drawLayer",
|
|
24
|
+
layerControlHide: true,
|
|
25
|
+
isDrawingEnabled: false,
|
|
26
|
+
multipleFeatures: multipleFeatures,
|
|
27
|
+
},
|
|
28
|
+
source: {
|
|
29
|
+
type: "Vector",
|
|
30
|
+
},
|
|
31
|
+
interactions: [
|
|
32
|
+
{
|
|
33
|
+
type: "draw",
|
|
34
|
+
options: {
|
|
35
|
+
active: false,
|
|
36
|
+
id: "drawInteraction",
|
|
37
|
+
type: EoxDrawTool.type,
|
|
38
|
+
modify: EoxDrawTool.allowModify,
|
|
39
|
+
stopClick: true,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: "select",
|
|
44
|
+
options: {
|
|
45
|
+
id: "selectHover",
|
|
46
|
+
condition: "pointermove",
|
|
47
|
+
style: {
|
|
48
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
49
|
+
"stroke-color": "#3399CC",
|
|
50
|
+
"stroke-width": 2.5,
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: "select",
|
|
56
|
+
options: {
|
|
57
|
+
id: "selectClick",
|
|
58
|
+
condition: "click",
|
|
59
|
+
panIn: true,
|
|
60
|
+
style: {
|
|
61
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
62
|
+
"stroke-color": "#3399CC",
|
|
63
|
+
"stroke-width": 2.5,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
71
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteraction"])
|
|
72
|
+
);
|
|
73
|
+
EoxDrawTool.modify = /** @type {import("ol/interaction").Modify} */ (
|
|
74
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteractionmodify"])
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
EoxDrawTool.modify?.on("modifyend", () => EoxDrawTool.onModifyEnd());
|
|
78
|
+
EoxMap.addEventListener("addfeatures", () => onDrawEndMethod(EoxDrawTool));
|
|
79
|
+
|
|
80
|
+
return { EoxMap, OlMap };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default initLayerMethod;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles actions after drawing ends -
|
|
3
|
+
* emits drawn features, deactivates drawing, and requests an update.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
*/
|
|
7
|
+
const onDrawEndMethod = (EoxDrawTool) => {
|
|
8
|
+
// Function to handle actions when drawing ends
|
|
9
|
+
const handleDrawEnd = () => {
|
|
10
|
+
EoxDrawTool.emitDrawnFeatures(); // Emit drawn features
|
|
11
|
+
if (!EoxDrawTool.multipleFeatures) {
|
|
12
|
+
EoxDrawTool.draw.setActive(false); // Deactivate drawing
|
|
13
|
+
EoxDrawTool.currentlyDrawing = false; // Update drawing status flag
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// Execute actions on draw end
|
|
18
|
+
handleDrawEnd();
|
|
19
|
+
EoxDrawTool.requestUpdate();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default onDrawEndMethod;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initiates the drawing process by initializing the draw layer,
|
|
3
|
+
* activating drawing, and updating the drawing status.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
*/
|
|
7
|
+
const startDrawingMethod = (EoxDrawTool) => {
|
|
8
|
+
// Function to initialize the drawing process
|
|
9
|
+
const initializeDrawing = () => {
|
|
10
|
+
EoxDrawTool.drawLayer.set("isDrawingEnabled", true);
|
|
11
|
+
EoxDrawTool.draw.setActive(true);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Function to update the drawing status and request an update
|
|
15
|
+
const updateDrawingStatus = () => {
|
|
16
|
+
EoxDrawTool.currentlyDrawing = true;
|
|
17
|
+
EoxDrawTool.requestUpdate();
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Initialize the drawing process
|
|
21
|
+
initializeDrawing();
|
|
22
|
+
|
|
23
|
+
// Update the drawing status
|
|
24
|
+
updateDrawingStatus();
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default startDrawingMethod;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deletes a feature when clicked on the delete button.
|
|
3
|
+
*
|
|
4
|
+
* @param {Event & { target: HTMLButtonElement }} evt - Event object containing button target.
|
|
5
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
6
|
+
*/
|
|
7
|
+
const deleteFeatureMethod = (evt, EoxDrawToolList) => {
|
|
8
|
+
evt.stopPropagation();
|
|
9
|
+
|
|
10
|
+
// Extract the index of the feature to delete from the button's attribute
|
|
11
|
+
const index = Number(evt.target.getAttribute("index"));
|
|
12
|
+
|
|
13
|
+
// Retrieve the feature to be deleted from the drawnFeatures array
|
|
14
|
+
const feature = EoxDrawToolList.drawnFeatures[index];
|
|
15
|
+
|
|
16
|
+
// Remove the feature from the draw layer and update the drawnFeatures array
|
|
17
|
+
EoxDrawToolList.drawLayer.getSource().removeFeature(feature);
|
|
18
|
+
EoxDrawToolList.drawnFeatures.splice(index, 1);
|
|
19
|
+
|
|
20
|
+
// Request an update to reflect the changes
|
|
21
|
+
EoxDrawToolList.requestUpdate();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default deleteFeatureMethod;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles initial settings and event triggers upon the component's first update.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
5
|
+
*/
|
|
6
|
+
const firstUpdatedMethod = (EoxDrawToolList) => {
|
|
7
|
+
// Set hover and click interactions
|
|
8
|
+
// Assign the hover and click interactions from eoxMap to respective variables in EoxDrawToolList
|
|
9
|
+
EoxDrawToolList.hoverInteraction =
|
|
10
|
+
EoxDrawToolList.eoxMap.selectInteractions["selectHover"];
|
|
11
|
+
EoxDrawToolList.clickInteraction =
|
|
12
|
+
EoxDrawToolList.eoxMap.selectInteractions["selectClick"];
|
|
13
|
+
|
|
14
|
+
// Function to trigger an update when the style changes due to interaction
|
|
15
|
+
const handleInteractionStyleChange = () => {
|
|
16
|
+
EoxDrawToolList.requestUpdate();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Event triggers for style change due to interaction
|
|
20
|
+
// Add listeners for style change in both hover and click interactions
|
|
21
|
+
EoxDrawToolList.hoverInteraction.selectStyleLayer.on(
|
|
22
|
+
"change",
|
|
23
|
+
handleInteractionStyleChange,
|
|
24
|
+
);
|
|
25
|
+
EoxDrawToolList.clickInteraction.selectStyleLayer.on(
|
|
26
|
+
"change",
|
|
27
|
+
handleInteractionStyleChange,
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default firstUpdatedMethod;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles the hover effect on a feature within the list.
|
|
3
|
+
*
|
|
4
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
5
|
+
* @param {Number} featureId - The ID of the feature to hover.
|
|
6
|
+
* @param {Boolean} mouseOut - Flag indicating mouse out event.
|
|
7
|
+
*/
|
|
8
|
+
const hoverFeatureMethod = (EoxDrawToolList, featureId, mouseOut) => {
|
|
9
|
+
// Check if the feature is currently clicked; if so, don't perform hover effect
|
|
10
|
+
if (EoxDrawToolList.clickId === featureId) return;
|
|
11
|
+
|
|
12
|
+
// Apply or remove hover effect based on mouse in/out event
|
|
13
|
+
const featuresToHighlight = mouseOut ? [] : [featureId]; // Create an array of feature IDs to highlight
|
|
14
|
+
EoxDrawToolList.hoverInteraction.highlightById(featuresToHighlight); // Apply hover effect
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default hoverFeatureMethod;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Importing methods from respective files and exporting them
|
|
2
|
+
|
|
3
|
+
export { default as firstUpdatedMethod } from "./first-update"; // Method for initial update
|
|
4
|
+
export { default as hoverFeatureMethod } from "./hover-feature"; // Method for hovering a feature
|
|
5
|
+
export { default as deleteFeatureMethod } from "./delete-feature"; // Method for deleting a feature
|
|
6
|
+
export { default as selectAndDeselectFeatureMethod } from "./select-deselect-feature"; // Method for selecting and deselecting a feature
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FIT_OPTIONS } from "../../enums";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Handles selecting and deselecting a feature on the map.
|
|
5
|
+
*
|
|
6
|
+
* @param {import("ol").Feature} feature - The selected feature.
|
|
7
|
+
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
8
|
+
*/
|
|
9
|
+
const selectAndDeselectFeature = (feature, EoxDrawToolList) => {
|
|
10
|
+
const selectedFeatureId = feature.get("id");
|
|
11
|
+
const { clickId, drawLayer, olMap, clickInteraction } = EoxDrawToolList;
|
|
12
|
+
|
|
13
|
+
const isSelectedFeature = clickId === selectedFeatureId;
|
|
14
|
+
const featureGeometry = feature.getGeometry();
|
|
15
|
+
|
|
16
|
+
if (isSelectedFeature) {
|
|
17
|
+
// Deselect the selected feature and fit the view to its extent
|
|
18
|
+
const newExtent = drawLayer.getSource().getExtent();
|
|
19
|
+
olMap.getView().fit(newExtent, FIT_OPTIONS);
|
|
20
|
+
clickInteraction.highlightById([]);
|
|
21
|
+
} else {
|
|
22
|
+
// Select the clicked feature and fit the view to its extent
|
|
23
|
+
const featureExtent = featureGeometry.getExtent();
|
|
24
|
+
clickInteraction.highlightById([selectedFeatureId]);
|
|
25
|
+
olMap.getView().fit(featureExtent, FIT_OPTIONS);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
EoxDrawToolList.requestUpdate();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export default selectAndDeselectFeature;
|
package/src/style.eox.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const styleEOX = `
|
|
2
|
+
button.discard:before {
|
|
3
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23FF5252' viewBox='0 0 24 24'%3E%3Ctitle%3Etrash-can-outline%3C/title%3E%3Cpath d='M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z' /%3E%3C/svg%3E")
|
|
4
|
+
}
|
|
5
|
+
button.polygon:before {
|
|
6
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='%23004170' viewBox='0 0 24 24'%3E%3Ctitle%3Eshape-polygon-plus%3C/title%3E%3Cpath d='M17,15.7V13H19V17L10,21L3,14L7,5H11V7H8.3L5.4,13.6L10.4,18.6L17,15.7M22,5V7H19V10H17V7H14V5H17V2H19V5H22Z' /%3E%3C/svg%3E");
|
|
7
|
+
}
|
|
8
|
+
button.import:before {
|
|
9
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Eupload%3C/title%3E%3Cpath fill='%23004170' d='M9,16V10H5L12,3L19,10H15V16H9M5,20V18H19V20H5Z' /%3E%3C/svg%3E");
|
|
10
|
+
}
|
|
11
|
+
.wrap-btn {
|
|
12
|
+
display: flex;
|
|
13
|
+
justify-content: space-between;
|
|
14
|
+
}
|
|
15
|
+
eox-drawtools-list {
|
|
16
|
+
width: 100%;
|
|
17
|
+
}
|
|
18
|
+
.json-wrapper {
|
|
19
|
+
margin: 0.4rem 0rem;
|
|
20
|
+
padding: 0.75rem;
|
|
21
|
+
background: var(--secondary-color-hover);
|
|
22
|
+
position: relative;
|
|
23
|
+
}
|
|
24
|
+
.json-wrapper textarea {
|
|
25
|
+
height: 200px;
|
|
26
|
+
}
|
|
27
|
+
.icon-copy {
|
|
28
|
+
position: absolute;
|
|
29
|
+
bottom: 26px;
|
|
30
|
+
right: 26px;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
height: 26px;
|
|
33
|
+
padding: 4px 6px;
|
|
34
|
+
}
|
|
35
|
+
.icon-copy:before {
|
|
36
|
+
width: 14px;
|
|
37
|
+
min-width: 14px;
|
|
38
|
+
height: 14px;
|
|
39
|
+
display: flex margin-right: 6px;
|
|
40
|
+
color: white;
|
|
41
|
+
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ctitle%3Econtent-copy%3C/title%3E%3Cpath d='M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z' fill='white' /%3E%3C/svg%3E")
|
|
42
|
+
}
|
|
43
|
+
`;
|