@eox/drawtools 0.9.0 → 0.10.1-dev.1729494244.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 +319 -207
- package/dist/eox-drawtools.umd.cjs +37 -33
- package/package.json +5 -13
- package/src/components/controller.js +193 -0
- package/src/components/list.js +189 -0
- package/src/enums/draw.js +5 -0
- package/src/enums/index.js +10 -0
- package/src/enums/stories.js +38 -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 +336 -0
- package/src/methods/controller/index.js +3 -0
- package/src/methods/controller/update-button-states.js +23 -0
- package/src/methods/draw/create-select-handler.js +50 -0
- package/src/methods/draw/discard-drawing.js +33 -0
- package/src/methods/draw/emit-drawn-features.js +23 -0
- package/src/methods/draw/handle-layer-id.js +55 -0
- package/src/methods/draw/index.js +10 -0
- package/src/methods/draw/init-layer.js +90 -0
- package/src/methods/draw/init-selection.js +67 -0
- package/src/methods/draw/on-draw-end.js +23 -0
- package/src/methods/draw/start-drawing.js +28 -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 +46 -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
|
@@ -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,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory function to create a select event handler
|
|
3
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
4
|
+
*/
|
|
5
|
+
const createSelectHandler = (EoxDrawTool) => {
|
|
6
|
+
/**
|
|
7
|
+
* Copy the selected feature to the draw layer
|
|
8
|
+
* and dispatches an event to add the feature to the map.
|
|
9
|
+
*
|
|
10
|
+
* @param {*} e
|
|
11
|
+
*/
|
|
12
|
+
const selectHandler = (e) => {
|
|
13
|
+
if (e?.detail.id !== "SelectLayerClickInteraction" || !e.detail.feature) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
EoxDrawTool.drawLayer.getSource().addFeature(e.detail.feature);
|
|
17
|
+
EoxDrawTool.eoxMap.dispatchEvent(
|
|
18
|
+
new CustomEvent("addfeatures", { detail: e.detail }),
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Adds the selection event to the map
|
|
24
|
+
**/
|
|
25
|
+
const addSelectionEvent = () => {
|
|
26
|
+
if (EoxDrawTool.layerId) {
|
|
27
|
+
const hoverInteraction =
|
|
28
|
+
EoxDrawTool.eoxMap.selectInteractions["SelectLayerHoverInteraction"];
|
|
29
|
+
hoverInteraction.setActive(true);
|
|
30
|
+
EoxDrawTool.eoxMap.addEventListener("select", selectHandler);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Removes the selection event from the map and resets the selected features
|
|
36
|
+
**/
|
|
37
|
+
const removeSelectionEvent = () => {
|
|
38
|
+
const hoverInteraction =
|
|
39
|
+
EoxDrawTool.eoxMap.selectInteractions?.["SelectLayerHoverInteraction"];
|
|
40
|
+
if (hoverInteraction) {
|
|
41
|
+
hoverInteraction.selectedFids = [];
|
|
42
|
+
hoverInteraction.setActive(false);
|
|
43
|
+
}
|
|
44
|
+
EoxDrawTool.eoxMap.removeEventListener("select", selectHandler);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return { addSelectionEvent, removeSelectionEvent };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export default createSelectHandler;
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
setTimeout(() => {
|
|
13
|
+
EoxDrawTool.draw.setActive(false);
|
|
14
|
+
EoxDrawTool.selectionEvents.removeSelectionEvent();
|
|
15
|
+
}, 200);
|
|
16
|
+
EoxDrawTool.drawLayer.getSource().clear();
|
|
17
|
+
//@ts-expect-error TODO
|
|
18
|
+
EoxDrawTool.geoJSON = null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// Function to trigger updates after discarding drawing
|
|
22
|
+
const triggerUpdates = () => {
|
|
23
|
+
EoxDrawTool.emitDrawnFeatures();
|
|
24
|
+
EoxDrawTool.currentlyDrawing = false;
|
|
25
|
+
EoxDrawTool.requestUpdate();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// Execute the discard actions and trigger updates
|
|
29
|
+
discardDrawingActions();
|
|
30
|
+
triggerUpdates();
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
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,55 @@
|
|
|
1
|
+
import { getJsonLayer } from "../../../../../utils";
|
|
2
|
+
import { initSelection } from ".";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* handles switching between selection and drawing and updates of the selection layer
|
|
6
|
+
*
|
|
7
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool
|
|
8
|
+
* @param {import("@eox/map/src/main").EOxMap} EoxMap
|
|
9
|
+
* @param {string} oldLayerId
|
|
10
|
+
* @param {string} updatedLayerId
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const handleLayerId = (EoxDrawTool, EoxMap, updatedLayerId, oldLayerId) => {
|
|
14
|
+
if (!EoxMap) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (updatedLayerId) {
|
|
19
|
+
if (oldLayerId && updatedLayerId !== oldLayerId) {
|
|
20
|
+
exitSelection(EoxDrawTool, EoxMap, oldLayerId);
|
|
21
|
+
initSelection(EoxDrawTool, EoxMap, updatedLayerId);
|
|
22
|
+
} else {
|
|
23
|
+
initSelection(EoxDrawTool, EoxMap, updatedLayerId);
|
|
24
|
+
}
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!updatedLayerId && oldLayerId) {
|
|
29
|
+
exitSelection(EoxDrawTool, EoxMap, oldLayerId);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default handleLayerId;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Exits the selection mode and reverts the selection layer to its original state
|
|
38
|
+
*
|
|
39
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool
|
|
40
|
+
* @param {import("@eox/map").EOxMap} EoxMap
|
|
41
|
+
* @param {string} oldLayerId
|
|
42
|
+
*/
|
|
43
|
+
function exitSelection(EoxDrawTool, EoxMap, oldLayerId) {
|
|
44
|
+
if (!EoxMap) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const selectionLayer = getJsonLayer(EoxMap.layers, oldLayerId) || null;
|
|
48
|
+
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
49
|
+
EoxMap.interactions["drawInteraction"]
|
|
50
|
+
);
|
|
51
|
+
if (selectionLayer) {
|
|
52
|
+
delete selectionLayer.interactions;
|
|
53
|
+
EoxMap.addOrUpdateLayer(selectionLayer);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
|
8
|
+
export { default as createSelectHandler } from "./create-select-handler"; // Factory function to create select event handler
|
|
9
|
+
export { default as initSelection } from "./init-selection"; // Initializes selection interactions
|
|
10
|
+
export { default as handleLayerId } from "./handle-layer-id"; // handle switching between selection and drawing
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { onDrawEndMethod, initSelection } 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/src/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/src/main").EOxMap} */ (mapQuery);
|
|
16
|
+
|
|
17
|
+
const OlMap = EoxMap.map;
|
|
18
|
+
|
|
19
|
+
EoxDrawTool.drawLayer = EoxMap.addOrUpdateLayer({
|
|
20
|
+
type: "Vector",
|
|
21
|
+
properties: {
|
|
22
|
+
id: "drawLayer",
|
|
23
|
+
// @ts-expect-error TODO
|
|
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
|
+
//@ts-expect-error TODO
|
|
45
|
+
options: {
|
|
46
|
+
id: "selectHover",
|
|
47
|
+
condition: "pointermove",
|
|
48
|
+
style: {
|
|
49
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
50
|
+
"stroke-color": "#3399CC",
|
|
51
|
+
"stroke-width": 2.5,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
type: "select",
|
|
57
|
+
//@ts-expect-error TODO
|
|
58
|
+
options: {
|
|
59
|
+
id: "selectClick",
|
|
60
|
+
condition: "click",
|
|
61
|
+
panIn: true,
|
|
62
|
+
style: {
|
|
63
|
+
"fill-color": "rgba(51, 153, 204,0.5)",
|
|
64
|
+
"stroke-color": "#3399CC",
|
|
65
|
+
"stroke-width": 2.5,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
73
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteraction"])
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
EoxDrawTool.modify = /** @type {import("ol/interaction").Modify} */ (
|
|
77
|
+
/** @type {unknown} */ (EoxMap.interactions["drawInteractionmodify"])
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// Initialize selection interactions
|
|
81
|
+
initSelection(EoxDrawTool, EoxMap, EoxDrawTool.layerId);
|
|
82
|
+
|
|
83
|
+
EoxDrawTool.modify?.on("modifyend", () => EoxDrawTool.onModifyEnd());
|
|
84
|
+
|
|
85
|
+
EoxMap.addEventListener("addfeatures", () => onDrawEndMethod(EoxDrawTool));
|
|
86
|
+
|
|
87
|
+
return { EoxMap, OlMap };
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default initLayerMethod;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { getJsonLayer } from "../../../../../utils";
|
|
2
|
+
/**
|
|
3
|
+
* Initializes the selection interactions for the given layer ID to the DrawTool.
|
|
4
|
+
*
|
|
5
|
+
* @param {import('../../main').EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
6
|
+
* @param {import("@eox/map/src/main").EOxMap} EoxMap - The map instance.
|
|
7
|
+
*/
|
|
8
|
+
const initSelection = (EoxDrawTool, EoxMap, updatedLayerId) => {
|
|
9
|
+
if (!updatedLayerId || !EoxMap) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const selectionLayer = getJsonLayer(EoxMap.layers, updatedLayerId) || null;
|
|
14
|
+
if (!selectionLayer) {
|
|
15
|
+
console.error(`Layer with id ${updatedLayerId} not found`);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** @type {import("../../../../map/types").EOxInteraction} */
|
|
20
|
+
const hoverInteraction = {
|
|
21
|
+
type: "select",
|
|
22
|
+
active: false,
|
|
23
|
+
//@ts-expect-error TODO
|
|
24
|
+
options: {
|
|
25
|
+
id: "SelectLayerHoverInteraction",
|
|
26
|
+
condition: "pointermove",
|
|
27
|
+
active: false,
|
|
28
|
+
style: {
|
|
29
|
+
"fill-color": "rgba(0, 0, 0,0.0)",
|
|
30
|
+
"stroke-color": "#3399CC",
|
|
31
|
+
"stroke-width": 2.5,
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** @type {import("../../../../map/types").EOxInteraction} */
|
|
37
|
+
const clickInteraction = {
|
|
38
|
+
type: "select",
|
|
39
|
+
//@ts-expect-error TODO
|
|
40
|
+
options: {
|
|
41
|
+
id: "SelectLayerClickInteraction",
|
|
42
|
+
condition: "click",
|
|
43
|
+
multi: EoxDrawTool.multipleFeatures,
|
|
44
|
+
modify: EoxDrawTool.allowModify,
|
|
45
|
+
active: false,
|
|
46
|
+
style: {
|
|
47
|
+
"fill-color": "rgba(0, 0, 0,0.0)",
|
|
48
|
+
"stroke-color": "rgba(0, 0, 0,0.0)",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
selectionLayer.interactions = [hoverInteraction, clickInteraction];
|
|
54
|
+
|
|
55
|
+
EoxMap.addOrUpdateLayer(selectionLayer);
|
|
56
|
+
|
|
57
|
+
const oldDrawInteraction = EoxDrawTool.draw;
|
|
58
|
+
EoxDrawTool.draw = EoxMap.selectInteractions["SelectLayerClickInteraction"];
|
|
59
|
+
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
oldDrawInteraction.setActive(false);
|
|
62
|
+
EoxMap.selectInteractions["SelectLayerClickInteraction"].setActive(false);
|
|
63
|
+
EoxMap.selectInteractions["SelectLayerHoverInteraction"].setActive(false);
|
|
64
|
+
}, 200);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export default initSelection;
|
|
@@ -0,0 +1,23 @@
|
|
|
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.selectionEvents.removeSelectionEvent();
|
|
14
|
+
EoxDrawTool.currentlyDrawing = false; // Update drawing status flag
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Execute actions on draw end
|
|
19
|
+
handleDrawEnd();
|
|
20
|
+
EoxDrawTool.requestUpdate();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default onDrawEndMethod;
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
// Add selection
|
|
13
|
+
EoxDrawTool.selectionEvents.addSelectionEvent();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Function to update the drawing status and request an update
|
|
17
|
+
const updateDrawingStatus = () => {
|
|
18
|
+
EoxDrawTool.currentlyDrawing = true;
|
|
19
|
+
EoxDrawTool.requestUpdate();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Initialize the drawing process
|
|
23
|
+
initializeDrawing();
|
|
24
|
+
// Update the drawing status
|
|
25
|
+
updateDrawingStatus();
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
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 | string | undefined} 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.getId();
|
|
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,46 @@
|
|
|
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.pointer: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%3Ecursor-default-click%3C/title%3E%3Cpath d='M10.76,8.69A0.76,0.76 0 0,0 10,9.45V20.9C10,21.32 10.34,21.66 10.76,21.66C10.95,21.66 11.11,21.6 11.24,21.5L13.15,19.95L14.81,23.57C14.94,23.84 15.21,24 15.5,24C15.61,24 15.72,24 15.83,23.92L18.59,22.64C18.97,22.46 19.15,22 18.95,21.63L17.28,18L19.69,17.55C19.85,17.5 20,17.43 20.12,17.29C20.39,16.97 20.35,16.5 20,16.21L11.26,8.86L11.25,8.87C11.12,8.76 10.95,8.69 10.76,8.69M15,10V8H20V10H15M13.83,4.76L16.66,1.93L18.07,3.34L15.24,6.17L13.83,4.76M10,0H12V5H10V0M3.93,14.66L6.76,11.83L8.17,13.24L5.34,16.07L3.93,14.66M3.93,3.34L5.34,1.93L8.17,4.76L6.76,6.17L3.93,3.34M7,10H2V8H7V10' /%3E%3C/svg%3E");
|
|
7
|
+
}
|
|
8
|
+
button.polygon:before {
|
|
9
|
+
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");
|
|
10
|
+
}
|
|
11
|
+
button.import:before {
|
|
12
|
+
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");
|
|
13
|
+
}
|
|
14
|
+
.wrap-btn {
|
|
15
|
+
display: flex;
|
|
16
|
+
justify-content: space-between;
|
|
17
|
+
}
|
|
18
|
+
eox-drawtools-list {
|
|
19
|
+
width: 100%;
|
|
20
|
+
}
|
|
21
|
+
.json-wrapper {
|
|
22
|
+
margin: 0.4rem 0rem;
|
|
23
|
+
padding: 0.75rem;
|
|
24
|
+
background: var(--secondary-color-hover);
|
|
25
|
+
position: relative;
|
|
26
|
+
}
|
|
27
|
+
.json-wrapper textarea {
|
|
28
|
+
height: 200px;
|
|
29
|
+
}
|
|
30
|
+
.icon-copy {
|
|
31
|
+
position: absolute;
|
|
32
|
+
bottom: 26px;
|
|
33
|
+
right: 26px;
|
|
34
|
+
border-radius: 4px;
|
|
35
|
+
height: 26px;
|
|
36
|
+
padding: 4px 6px;
|
|
37
|
+
}
|
|
38
|
+
.icon-copy:before {
|
|
39
|
+
width: 14px;
|
|
40
|
+
min-width: 14px;
|
|
41
|
+
height: 14px;
|
|
42
|
+
display: flex margin-right: 6px;
|
|
43
|
+
color: white;
|
|
44
|
+
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")
|
|
45
|
+
}
|
|
46
|
+
`;
|
package/test/_mockMap.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Defining a MockMap class extending HTMLElement
|
|
2
|
-
export class MockMap extends HTMLElement {
|
|
3
|
-
constructor() {
|
|
4
|
-
super();
|
|
5
|
-
// Initializing features array
|
|
6
|
-
this.features = [];
|
|
7
|
-
// Simulating a map object with necessary methods
|
|
8
|
-
this.map = {
|
|
9
|
-
// Simulating getLayers method
|
|
10
|
-
getLayers: () => ({
|
|
11
|
-
// Simulating getArray method
|
|
12
|
-
getArray: () => [
|
|
13
|
-
{
|
|
14
|
-
// Simulating get method
|
|
15
|
-
get: () => "draw",
|
|
16
|
-
set: () => "",
|
|
17
|
-
getSource: () => ({
|
|
18
|
-
// Simulating clear method to reset features array
|
|
19
|
-
clear: () => {
|
|
20
|
-
this.features = [];
|
|
21
|
-
},
|
|
22
|
-
// Simulating getFeatures method
|
|
23
|
-
getFeatures: () => this.features,
|
|
24
|
-
}),
|
|
25
|
-
},
|
|
26
|
-
],
|
|
27
|
-
}),
|
|
28
|
-
// Simulating removeLayer method
|
|
29
|
-
removeLayer() {},
|
|
30
|
-
};
|
|
31
|
-
// Simulating addOrUpdateLayer method
|
|
32
|
-
this.addOrUpdateLayer = () => this.map.getLayers().getArray()[0];
|
|
33
|
-
// Simulating interactions object with necessary methods
|
|
34
|
-
this.interactions = {
|
|
35
|
-
drawInteraction: {
|
|
36
|
-
// Simulating on method for drawInteraction
|
|
37
|
-
on: (event, fun) => fun(event),
|
|
38
|
-
// Simulating setActive method for drawInteraction
|
|
39
|
-
setActive() {},
|
|
40
|
-
},
|
|
41
|
-
drawInteraction_modify: {
|
|
42
|
-
// Simulating on method for drawInteraction_modify
|
|
43
|
-
on() {},
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
// Simulating removeInteraction method
|
|
47
|
-
this.removeInteraction = () => {};
|
|
48
|
-
// Simulate parse features
|
|
49
|
-
this.parseFeature = () => {};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Registering the MockMap custom element
|
|
54
|
-
customElements.define("mock-map", MockMap);
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TEST_SELECTORS } from "../../src/enums";
|
|
2
|
-
|
|
3
|
-
// Destructure TEST_SELECTORS object
|
|
4
|
-
const { drawTools, controller, drawBtn, discardBtn } = TEST_SELECTORS;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Clicks the discard button and verifies if drawn features are cleared.
|
|
8
|
-
*/
|
|
9
|
-
const clickDiscardBtnTest = () => {
|
|
10
|
-
cy.get(drawTools)
|
|
11
|
-
.shadow()
|
|
12
|
-
.within(() => {
|
|
13
|
-
cy.get(controller).within(() => {
|
|
14
|
-
// Click the draw button and verify if it is in the 'drawing' state
|
|
15
|
-
cy.get(drawBtn).click();
|
|
16
|
-
cy.get(drawBtn).contains("drawing");
|
|
17
|
-
|
|
18
|
-
// Click the discard button and verify if the 'drawing' state is removed
|
|
19
|
-
cy.get(discardBtn).click();
|
|
20
|
-
cy.get(drawBtn).should("not.contain", "drawing");
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// Verify if drawn features array is empty after discarding
|
|
25
|
-
cy.get(drawTools).should(($el) => {
|
|
26
|
-
expect($el[0].drawnFeatures).to.have.length(0);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export default clickDiscardBtnTest;
|