@eox/drawtools 0.10.0 → 0.11.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/dist/eox-drawtools.js +324 -221
- package/dist/eox-drawtools.umd.cjs +37 -33
- package/package.json +1 -1
- package/src/components/controller.js +7 -1
- package/src/components/list.js +2 -2
- package/src/enums/index.js +1 -0
- package/src/enums/stories.js +21 -0
- package/src/main.js +41 -7
- package/src/methods/draw/create-select-handler.js +50 -0
- package/src/methods/draw/discard-drawing.js +5 -1
- package/src/methods/draw/handle-layer-id.js +52 -0
- package/src/methods/draw/index.js +3 -0
- package/src/methods/draw/init-layer.js +12 -5
- package/src/methods/draw/init-selection.js +73 -0
- package/src/methods/draw/on-draw-end.js +1 -0
- package/src/methods/draw/start-drawing.js +2 -1
- package/src/methods/list/hover-feature.js +1 -1
- package/src/methods/list/select-deselect-feature.js +1 -1
- package/src/style.eox.js +3 -0
|
@@ -9,8 +9,12 @@ const discardDrawingMethod = (EoxDrawTool) => {
|
|
|
9
9
|
const discardDrawingActions = () => {
|
|
10
10
|
// Reset drawnFeatures, deactivate drawing, and clear drawLayer's source
|
|
11
11
|
EoxDrawTool.drawnFeatures = [];
|
|
12
|
-
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
EoxDrawTool.draw.setActive(false);
|
|
14
|
+
EoxDrawTool.selectionEvents.removeSelectionEvent();
|
|
15
|
+
}, 200);
|
|
13
16
|
EoxDrawTool.drawLayer.getSource().clear();
|
|
17
|
+
//@ts-expect-error TODO
|
|
14
18
|
EoxDrawTool.geoJSON = null;
|
|
15
19
|
};
|
|
16
20
|
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { initSelection } from ".";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* handles switching between selection and drawing and updates of the selection layer
|
|
5
|
+
*
|
|
6
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool
|
|
7
|
+
* @param {import("@eox/map/src/main").EOxMap} EoxMap
|
|
8
|
+
* @param {string} oldLayerId
|
|
9
|
+
* @param {string} updatedLayerId
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const handleLayerId = (EoxDrawTool, EoxMap, updatedLayerId, oldLayerId) => {
|
|
13
|
+
if (!EoxMap) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (updatedLayerId) {
|
|
18
|
+
if (oldLayerId && updatedLayerId !== oldLayerId) {
|
|
19
|
+
exitSelection(EoxDrawTool, EoxMap);
|
|
20
|
+
initSelection(EoxDrawTool, EoxMap, updatedLayerId);
|
|
21
|
+
} else {
|
|
22
|
+
initSelection(EoxDrawTool, EoxMap, updatedLayerId);
|
|
23
|
+
}
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!updatedLayerId && oldLayerId) {
|
|
28
|
+
exitSelection(EoxDrawTool, EoxMap);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default handleLayerId;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Exits the selection mode and reverts the selection layer to its original state
|
|
37
|
+
*
|
|
38
|
+
* @param {import("../../main").EOxDrawTools} EoxDrawTool
|
|
39
|
+
* @param {import("@eox/map").EOxMap} EoxMap
|
|
40
|
+
*/
|
|
41
|
+
function exitSelection(EoxDrawTool, EoxMap) {
|
|
42
|
+
if (!EoxMap) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
EoxDrawTool.discardDrawing();
|
|
46
|
+
EoxDrawTool.selectionEvents.removeSelectionEvent();
|
|
47
|
+
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
48
|
+
EoxMap.interactions["drawInteraction"]
|
|
49
|
+
);
|
|
50
|
+
EoxMap.selectInteractions["SelectLayerClickInteraction"].remove();
|
|
51
|
+
EoxMap.selectInteractions["SelectLayerHoverInteraction"].remove();
|
|
52
|
+
}
|
|
@@ -5,3 +5,6 @@ export { default as startDrawingMethod } from "./start-drawing"; // Initializes
|
|
|
5
5
|
export { default as initLayerMethod } from "./init-layer.js"; // Initializes layer and map interactions
|
|
6
6
|
export { default as discardDrawingMethod } from "./discard-drawing"; // Handles discarding the drawing process
|
|
7
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
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { onDrawEndMethod } from "./";
|
|
1
|
+
import { onDrawEndMethod, initSelection } from "./";
|
|
2
2
|
|
|
3
3
|
import { getElement } from "@eox/elements-utils";
|
|
4
4
|
|
|
@@ -7,20 +7,20 @@ import { getElement } from "@eox/elements-utils";
|
|
|
7
7
|
*
|
|
8
8
|
* @param {import("../../main").EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
9
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.
|
|
10
|
+
* @returns {{EoxMap: import("@eox/map/src/main").EOxMap, OlMap: import("ol").Map}} - The map instances.
|
|
11
11
|
*/
|
|
12
12
|
const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
13
13
|
const mapQuery = getElement(EoxDrawTool.for);
|
|
14
14
|
|
|
15
|
-
const EoxMap = /** @type {import("@eox/map/main").EOxMap} */ (mapQuery);
|
|
16
|
-
|
|
15
|
+
const EoxMap = /** @type {import("@eox/map/src/main").EOxMap} */ (mapQuery);
|
|
16
|
+
|
|
17
17
|
const OlMap = EoxMap.map;
|
|
18
18
|
|
|
19
|
-
// @ts-expect-error TODO
|
|
20
19
|
EoxDrawTool.drawLayer = EoxMap.addOrUpdateLayer({
|
|
21
20
|
type: "Vector",
|
|
22
21
|
properties: {
|
|
23
22
|
id: "drawLayer",
|
|
23
|
+
// @ts-expect-error TODO
|
|
24
24
|
layerControlHide: true,
|
|
25
25
|
isDrawingEnabled: false,
|
|
26
26
|
multipleFeatures: multipleFeatures,
|
|
@@ -41,6 +41,7 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
|
41
41
|
},
|
|
42
42
|
{
|
|
43
43
|
type: "select",
|
|
44
|
+
//@ts-expect-error TODO
|
|
44
45
|
options: {
|
|
45
46
|
id: "selectHover",
|
|
46
47
|
condition: "pointermove",
|
|
@@ -53,6 +54,7 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
|
53
54
|
},
|
|
54
55
|
{
|
|
55
56
|
type: "select",
|
|
57
|
+
//@ts-expect-error TODO
|
|
56
58
|
options: {
|
|
57
59
|
id: "selectClick",
|
|
58
60
|
condition: "click",
|
|
@@ -70,11 +72,16 @@ const initLayerMethod = (EoxDrawTool, multipleFeatures) => {
|
|
|
70
72
|
EoxDrawTool.draw = /** @type {import("ol/interaction").Draw} */ (
|
|
71
73
|
/** @type {unknown} */ (EoxMap.interactions["drawInteraction"])
|
|
72
74
|
);
|
|
75
|
+
|
|
73
76
|
EoxDrawTool.modify = /** @type {import("ol/interaction").Modify} */ (
|
|
74
77
|
/** @type {unknown} */ (EoxMap.interactions["drawInteractionmodify"])
|
|
75
78
|
);
|
|
76
79
|
|
|
80
|
+
// Initialize selection interactions
|
|
81
|
+
initSelection(EoxDrawTool, EoxMap, EoxDrawTool.layerId);
|
|
82
|
+
|
|
77
83
|
EoxDrawTool.modify?.on("modifyend", () => EoxDrawTool.onModifyEnd());
|
|
84
|
+
|
|
78
85
|
EoxMap.addEventListener("addfeatures", () => onDrawEndMethod(EoxDrawTool));
|
|
79
86
|
|
|
80
87
|
return { EoxMap, OlMap };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes the selection interactions for the given layer ID to the DrawTool.
|
|
3
|
+
*
|
|
4
|
+
* @param {import('../../main').EOxDrawTools} EoxDrawTool - The drawing tool instance.
|
|
5
|
+
* @param {import("@eox/map/src/main").EOxMap} EoxMap - The map instance.
|
|
6
|
+
*/
|
|
7
|
+
const initSelection = (EoxDrawTool, EoxMap, updatedLayerId) => {
|
|
8
|
+
if (!updatedLayerId || !EoxMap) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const selectionLayer =
|
|
13
|
+
JSON.parse(
|
|
14
|
+
JSON.stringify(
|
|
15
|
+
/** @type {import("../../../../map/src/main").EoxLayer} */ (
|
|
16
|
+
EoxMap.getLayerById(updatedLayerId).get("_jsonDefinition")
|
|
17
|
+
),
|
|
18
|
+
),
|
|
19
|
+
) || null;
|
|
20
|
+
if (!selectionLayer) {
|
|
21
|
+
console.error(`Layer with id ${updatedLayerId} not found`);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @type {import("../../../../map/types").EOxInteraction} */
|
|
26
|
+
const hoverInteraction = {
|
|
27
|
+
type: "select",
|
|
28
|
+
active: false,
|
|
29
|
+
//@ts-expect-error TODO
|
|
30
|
+
options: {
|
|
31
|
+
id: "SelectLayerHoverInteraction",
|
|
32
|
+
condition: "pointermove",
|
|
33
|
+
active: false,
|
|
34
|
+
style: {
|
|
35
|
+
"fill-color": "rgba(0, 0, 0,0.0)",
|
|
36
|
+
"stroke-color": "#3399CC",
|
|
37
|
+
"stroke-width": 2.5,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** @type {import("../../../../map/types").EOxInteraction} */
|
|
43
|
+
const clickInteraction = {
|
|
44
|
+
type: "select",
|
|
45
|
+
//@ts-expect-error TODO
|
|
46
|
+
options: {
|
|
47
|
+
id: "SelectLayerClickInteraction",
|
|
48
|
+
condition: "click",
|
|
49
|
+
multi: EoxDrawTool.multipleFeatures,
|
|
50
|
+
modify: EoxDrawTool.allowModify,
|
|
51
|
+
active: false,
|
|
52
|
+
style: {
|
|
53
|
+
"fill-color": "rgba(0, 0, 0,0.0)",
|
|
54
|
+
"stroke-color": "rgba(0, 0, 0,0.0)",
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
selectionLayer.interactions = [hoverInteraction, clickInteraction];
|
|
60
|
+
|
|
61
|
+
EoxMap.addOrUpdateLayer(selectionLayer);
|
|
62
|
+
|
|
63
|
+
const oldDrawInteraction = EoxDrawTool.draw;
|
|
64
|
+
EoxDrawTool.draw = EoxMap.selectInteractions["SelectLayerClickInteraction"];
|
|
65
|
+
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
oldDrawInteraction.setActive(false);
|
|
68
|
+
EoxMap.selectInteractions["SelectLayerClickInteraction"].setActive(false);
|
|
69
|
+
EoxMap.selectInteractions["SelectLayerHoverInteraction"].setActive(false);
|
|
70
|
+
}, 200);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export default initSelection;
|
|
@@ -10,6 +10,7 @@ const onDrawEndMethod = (EoxDrawTool) => {
|
|
|
10
10
|
EoxDrawTool.emitDrawnFeatures(); // Emit drawn features
|
|
11
11
|
if (!EoxDrawTool.multipleFeatures) {
|
|
12
12
|
EoxDrawTool.draw.setActive(false); // Deactivate drawing
|
|
13
|
+
EoxDrawTool.selectionEvents.removeSelectionEvent();
|
|
13
14
|
EoxDrawTool.currentlyDrawing = false; // Update drawing status flag
|
|
14
15
|
}
|
|
15
16
|
};
|
|
@@ -9,6 +9,8 @@ const startDrawingMethod = (EoxDrawTool) => {
|
|
|
9
9
|
const initializeDrawing = () => {
|
|
10
10
|
EoxDrawTool.drawLayer.set("isDrawingEnabled", true);
|
|
11
11
|
EoxDrawTool.draw.setActive(true);
|
|
12
|
+
// Add selection
|
|
13
|
+
EoxDrawTool.selectionEvents.addSelectionEvent();
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
// Function to update the drawing status and request an update
|
|
@@ -19,7 +21,6 @@ const startDrawingMethod = (EoxDrawTool) => {
|
|
|
19
21
|
|
|
20
22
|
// Initialize the drawing process
|
|
21
23
|
initializeDrawing();
|
|
22
|
-
|
|
23
24
|
// Update the drawing status
|
|
24
25
|
updateDrawingStatus();
|
|
25
26
|
};
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Handles the hover effect on a feature within the list.
|
|
3
3
|
*
|
|
4
4
|
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
5
|
-
* @param {
|
|
5
|
+
* @param {number | string | undefined} featureId - The ID of the feature to hover.
|
|
6
6
|
* @param {Boolean} mouseOut - Flag indicating mouse out event.
|
|
7
7
|
*/
|
|
8
8
|
const hoverFeatureMethod = (EoxDrawToolList, featureId, mouseOut) => {
|
|
@@ -7,7 +7,7 @@ import { FIT_OPTIONS } from "../../enums";
|
|
|
7
7
|
* @param {import("../../components/list").EOxDrawToolsList} EoxDrawToolList - The list of drawn features.
|
|
8
8
|
*/
|
|
9
9
|
const selectAndDeselectFeature = (feature, EoxDrawToolList) => {
|
|
10
|
-
const selectedFeatureId = feature.
|
|
10
|
+
const selectedFeatureId = feature.getId();
|
|
11
11
|
const { clickId, drawLayer, olMap, clickInteraction } = EoxDrawToolList;
|
|
12
12
|
|
|
13
13
|
const isSelectedFeature = clickId === selectedFeatureId;
|
package/src/style.eox.js
CHANGED
|
@@ -2,6 +2,9 @@ export const styleEOX = `
|
|
|
2
2
|
button.discard:before {
|
|
3
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
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
|
+
}
|
|
5
8
|
button.polygon:before {
|
|
6
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");
|
|
7
10
|
}
|