@eox/drawtools 0.10.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.
@@ -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
+ }
@@ -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
- // @ts-expect-error TODO
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,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;
@@ -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 {Number} featureId - The ID of the feature to hover.
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.get("id");
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
  }