@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,189 @@
|
|
|
1
|
+
import { LitElement, html, nothing } from "lit";
|
|
2
|
+
import { keyed } from "lit/directives/keyed.js";
|
|
3
|
+
import {
|
|
4
|
+
deleteFeatureMethod,
|
|
5
|
+
firstUpdatedMethod,
|
|
6
|
+
hoverFeatureMethod,
|
|
7
|
+
selectAndDeselectFeatureMethod,
|
|
8
|
+
} from "../methods/list";
|
|
9
|
+
import listStyle from "@eox/elements-utils/styles/dist/list.style";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Display list of features
|
|
13
|
+
*
|
|
14
|
+
* @element eox-drawtools-list
|
|
15
|
+
*/
|
|
16
|
+
export class EOxDrawToolsList extends LitElement {
|
|
17
|
+
static properties = {
|
|
18
|
+
eoxMap: { attribute: false, state: true },
|
|
19
|
+
olMap: { attribute: false, state: true },
|
|
20
|
+
draw: { attribute: false, state: true },
|
|
21
|
+
drawLayer: { attribute: false, state: true },
|
|
22
|
+
drawnFeatures: { attribute: false, state: true, type: Array },
|
|
23
|
+
modify: { attribute: false, state: true },
|
|
24
|
+
unstyled: { type: Boolean },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @type import("../../../map/src/select").EOxSelectInteraction
|
|
29
|
+
*/
|
|
30
|
+
hoverInteraction;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @type import("../../../map/src/select").EOxSelectInteraction
|
|
34
|
+
*/
|
|
35
|
+
clickInteraction;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @type string | number
|
|
39
|
+
*/
|
|
40
|
+
hoverId;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @type string | number
|
|
44
|
+
*/
|
|
45
|
+
clickId;
|
|
46
|
+
|
|
47
|
+
constructor() {
|
|
48
|
+
super();
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @type import("../../../map/main").EOxMap
|
|
52
|
+
*/
|
|
53
|
+
this.eoxMap = null;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @type import("ol").Map
|
|
57
|
+
*/
|
|
58
|
+
this.olMap = null;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The current native OpenLayers `draw` interaction
|
|
62
|
+
* @type import("ol/interaction").Draw
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
this.draw = null;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The current native OpenLayers draw `layer`
|
|
69
|
+
* @type import("ol/layer").Vector<import("ol/source").Vector>
|
|
70
|
+
*/
|
|
71
|
+
|
|
72
|
+
this.drawLayer = null;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The array of drawn native OpenLayers features. Normally includes only one feature,
|
|
76
|
+
* until multiple feature drawing is enabled.
|
|
77
|
+
*
|
|
78
|
+
* @type Array<import("ol").Feature>
|
|
79
|
+
*/
|
|
80
|
+
this.drawnFeatures = [];
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The current native OpenLayers `modify` interaction
|
|
84
|
+
* @type import("ol/interaction").Modify
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
this.modify = null;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Render the element without additional styles
|
|
91
|
+
*/
|
|
92
|
+
this.unstyled = false;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Handles the deletion of an individual feature.
|
|
97
|
+
*
|
|
98
|
+
* @param {Event & { target: HTMLButtonElement }} evt - Event object containing button target.
|
|
99
|
+
*/
|
|
100
|
+
_handleDelete(evt) {
|
|
101
|
+
deleteFeatureMethod(evt, this);
|
|
102
|
+
this.dispatchEvent(new CustomEvent("changed", { bubbles: true }));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Handles the selection and deselection of a feature from the list.
|
|
107
|
+
*
|
|
108
|
+
* @param {import("ol").Feature} feature - The selected feature.
|
|
109
|
+
*/
|
|
110
|
+
_handleFeatureSelectAndDeselect(feature) {
|
|
111
|
+
selectAndDeselectFeatureMethod(feature, this);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @param {number | string | undefined} featureId - The ID of the feature to hover.
|
|
117
|
+
* @param {Boolean} mouseOut - Flag indicating mouse out event.
|
|
118
|
+
*/
|
|
119
|
+
_handleHoverFeature(featureId, mouseOut = false) {
|
|
120
|
+
hoverFeatureMethod(this, featureId, mouseOut);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Initiates initial settings and event triggers upon the component's first update.
|
|
125
|
+
*/
|
|
126
|
+
firstUpdated() {
|
|
127
|
+
firstUpdatedMethod(this);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Overrides createRenderRoot to handle shadow DOM.
|
|
132
|
+
*/
|
|
133
|
+
createRenderRoot() {
|
|
134
|
+
return this;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
render() {
|
|
138
|
+
// Update hover and click IDs
|
|
139
|
+
this.hoverId = this.hoverInteraction?.selectedFids[0];
|
|
140
|
+
this.clickId = this.clickInteraction?.selectedFids[0];
|
|
141
|
+
|
|
142
|
+
return html`
|
|
143
|
+
<style>
|
|
144
|
+
${!this.unstyled && listStyle}
|
|
145
|
+
</style>
|
|
146
|
+
<ul class="list-wrap">
|
|
147
|
+
${this.drawnFeatures.map((feature, i) => {
|
|
148
|
+
// Determine feature number and ID
|
|
149
|
+
const featureNumber = i + 1;
|
|
150
|
+
const featureId = feature.getId();
|
|
151
|
+
|
|
152
|
+
// Check if the feature is hovered or clicked
|
|
153
|
+
const isFeatureHovered = this.hoverId === featureId;
|
|
154
|
+
const isFeatureClicked = this.clickId === featureId;
|
|
155
|
+
const isSelected = isFeatureHovered || isFeatureClicked;
|
|
156
|
+
const selectionClass = isSelected ? "selected" : nothing;
|
|
157
|
+
|
|
158
|
+
return keyed(
|
|
159
|
+
featureNumber,
|
|
160
|
+
html`
|
|
161
|
+
<li
|
|
162
|
+
class="${selectionClass}"
|
|
163
|
+
@mouseover=${() => this._handleHoverFeature(featureId)}
|
|
164
|
+
@mouseout=${() => this._handleHoverFeature(featureId, true)}
|
|
165
|
+
>
|
|
166
|
+
<div
|
|
167
|
+
class="list"
|
|
168
|
+
@click="${() =>
|
|
169
|
+
this._handleFeatureSelectAndDeselect(feature)}"
|
|
170
|
+
>
|
|
171
|
+
<span class="title">Feature #${featureNumber}</span>
|
|
172
|
+
<button
|
|
173
|
+
index=${i}
|
|
174
|
+
class="icon smallest discard"
|
|
175
|
+
@click="${this._handleDelete}"
|
|
176
|
+
>
|
|
177
|
+
x
|
|
178
|
+
</button>
|
|
179
|
+
</div>
|
|
180
|
+
</li>
|
|
181
|
+
`,
|
|
182
|
+
);
|
|
183
|
+
})}
|
|
184
|
+
</ul>
|
|
185
|
+
`;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
customElements.define("eox-drawtools-list", EOxDrawToolsList);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export const STORIES_LAYERS_ARRAY = [
|
|
2
|
+
{
|
|
3
|
+
type: "Tile",
|
|
4
|
+
source: {
|
|
5
|
+
type: "OSM",
|
|
6
|
+
},
|
|
7
|
+
},
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
export const STORIES_VECTOR_LAYERS = [
|
|
11
|
+
{
|
|
12
|
+
type: "Vector",
|
|
13
|
+
background: "lightgrey",
|
|
14
|
+
properties: {
|
|
15
|
+
id: "regions",
|
|
16
|
+
},
|
|
17
|
+
source: {
|
|
18
|
+
type: "Vector",
|
|
19
|
+
url: "https://openlayers.org/data/vector/ecoregions.json",
|
|
20
|
+
format: "GeoJSON",
|
|
21
|
+
attributions: "Regions: @ openlayers.org",
|
|
22
|
+
},
|
|
23
|
+
style: {
|
|
24
|
+
"stroke-color": "black",
|
|
25
|
+
"stroke-width": 1,
|
|
26
|
+
"fill-color": "darkgrey",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
export const STORIES_MAP_STYLE = "width: 400px; height: 300px;";
|
|
32
|
+
|
|
33
|
+
export const STORIES_DRAW_TYPES = [
|
|
34
|
+
{ id: "box", type: "Box" },
|
|
35
|
+
{ id: "point", type: "Point" },
|
|
36
|
+
{ id: "circle", type: "Circle" },
|
|
37
|
+
{ id: "linestring", type: "LineString" },
|
|
38
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copy a given text string to the clipboard
|
|
3
|
+
*
|
|
4
|
+
* @param {string} text - The text to be copied to the clipboard.
|
|
5
|
+
*/
|
|
6
|
+
export default function copyTextToClipboard(text) {
|
|
7
|
+
navigator.clipboard.writeText(text).then(
|
|
8
|
+
function () {},
|
|
9
|
+
function (err) {
|
|
10
|
+
console.error("Could not copy text: ", err);
|
|
11
|
+
},
|
|
12
|
+
);
|
|
13
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initializes upload-related event listeners for drag-and-drop interactions on a map element.
|
|
3
|
+
* It configures the map to react visually to drag-and-drop actions and processes dropped files.
|
|
4
|
+
*
|
|
5
|
+
* @param {import("../main.js").EOxDrawTools} EOxDrawTool - The drawing tool instance.
|
|
6
|
+
* @param {import("@eox/map/main").EOxMap} EOxMap - The EOx Map instance.
|
|
7
|
+
*/
|
|
8
|
+
export function initMapDragDropImport(EOxDrawTool, EOxMap) {
|
|
9
|
+
// Helper function to prevent default behavior for drag and drop events
|
|
10
|
+
function preventDefaults(e) {
|
|
11
|
+
e.preventDefault();
|
|
12
|
+
e.stopPropagation();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Changes the opacity of the map element to indicate a drag-and-drop action is in progress
|
|
16
|
+
function highlight(e) {
|
|
17
|
+
e.srcElement.style.opacity = "0.4";
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Reverts the opacity of the map element back to normal
|
|
21
|
+
function unHighlight(e) {
|
|
22
|
+
e.srcElement.style.opacity = "1";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Attaches event listeners for drag-and-drop actions
|
|
26
|
+
["dragenter", "dragover", "dragleave", "drop"].forEach((eventName) => {
|
|
27
|
+
EOxMap.addEventListener(eventName, preventDefaults, false);
|
|
28
|
+
if (["dragenter", "dragover"].includes(eventName))
|
|
29
|
+
EOxMap.addEventListener(eventName, highlight, false);
|
|
30
|
+
else EOxMap.addEventListener(eventName, unHighlight, false);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Handle dropped files specifically
|
|
34
|
+
EOxMap.addEventListener("drop", (e) => handleFiles(e, EOxDrawTool), false);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Prevents the default action of an event from occurring
|
|
39
|
+
* and stops it from propagating further.
|
|
40
|
+
*
|
|
41
|
+
* @param {Event} e - The event object to be handled.
|
|
42
|
+
*/
|
|
43
|
+
function preventDefaults(e) {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Handles file input from drag-and-drop or file selection events,
|
|
50
|
+
* forwarding each file to a specified processing function.
|
|
51
|
+
*
|
|
52
|
+
* @param {DragEvent | Event} e - The event object from the file input interaction.
|
|
53
|
+
* @param {import("../main.js").EOxDrawTools} EOxDrawTool - The drawing tool instance.
|
|
54
|
+
*/
|
|
55
|
+
export function handleFiles(e, EOxDrawTool) {
|
|
56
|
+
preventDefaults(e);
|
|
57
|
+
|
|
58
|
+
// Extract files from the event, supporting both drag-and-drop and file input sources
|
|
59
|
+
const files = e.dataTransfer ? e.dataTransfer.files : e.target.files;
|
|
60
|
+
|
|
61
|
+
Array.from(files).forEach((file) => importFile(file, EOxDrawTool));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Reads the content of a provided file as text and
|
|
66
|
+
* then triggers a specified handling function
|
|
67
|
+
*
|
|
68
|
+
* @param {File} file - The file object to be read.
|
|
69
|
+
* @param {import("../main.js").EOxDrawTools} EOxDrawTool - The drawing tool instance.
|
|
70
|
+
*/
|
|
71
|
+
function importFile(file, EOxDrawTool) {
|
|
72
|
+
const reader = new FileReader();
|
|
73
|
+
|
|
74
|
+
// Initiate reading the file's content as text
|
|
75
|
+
reader.readAsText(file);
|
|
76
|
+
|
|
77
|
+
// Define the onloadend event handler
|
|
78
|
+
reader.onloadend = function () {
|
|
79
|
+
if (typeof reader.result === "string")
|
|
80
|
+
EOxDrawTool.handleFeatureChange(reader.result);
|
|
81
|
+
};
|
|
82
|
+
}
|
package/src/main.js
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
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
|
+
createSelectHandler,
|
|
11
|
+
handleLayerId,
|
|
12
|
+
} from "./methods/draw";
|
|
13
|
+
import mainStyle from "@eox/elements-utils/styles/dist/main.style";
|
|
14
|
+
import { DUMMY_GEO_JSON } from "./enums/index.js";
|
|
15
|
+
import {
|
|
16
|
+
initMapDragDropImport,
|
|
17
|
+
handleFiles,
|
|
18
|
+
} from "./helpers/generate-upload-events.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Manage drawn features on a map
|
|
22
|
+
*
|
|
23
|
+
* @element eox-drawtools
|
|
24
|
+
*/
|
|
25
|
+
export class EOxDrawTools extends LitElement {
|
|
26
|
+
// Define properties with defaults and types
|
|
27
|
+
static get properties() {
|
|
28
|
+
return {
|
|
29
|
+
allowModify: { attribute: "allow-modify", type: Boolean },
|
|
30
|
+
for: { type: String },
|
|
31
|
+
currentlyDrawing: { attribute: false, state: true, type: Boolean },
|
|
32
|
+
draw: { attribute: false, state: true },
|
|
33
|
+
drawLayer: { attribute: false, state: true },
|
|
34
|
+
layerId: { attribute: "layer-id", type: String },
|
|
35
|
+
drawnFeatures: { attribute: false, state: true, type: Array },
|
|
36
|
+
modify: { attribute: false, state: true },
|
|
37
|
+
multipleFeatures: { attribute: "multiple-features", type: Boolean },
|
|
38
|
+
importFeatures: { attribute: "import-features", type: Boolean },
|
|
39
|
+
showEditor: { attribute: "show-editor", type: Boolean },
|
|
40
|
+
showList: { attribute: "show-list", type: Boolean },
|
|
41
|
+
noShadow: { type: Boolean },
|
|
42
|
+
type: { type: String },
|
|
43
|
+
unstyled: { type: Boolean },
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @type import("../../map/src/main").EOxMap
|
|
49
|
+
*/
|
|
50
|
+
#eoxMap;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @type import("ol").Map
|
|
54
|
+
*/
|
|
55
|
+
#olMap;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @type string
|
|
59
|
+
*/
|
|
60
|
+
#geoJSON;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @type string
|
|
64
|
+
*/
|
|
65
|
+
#layerId;
|
|
66
|
+
|
|
67
|
+
constructor() {
|
|
68
|
+
super();
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Allow modifying the drawn feature(s)
|
|
72
|
+
*/
|
|
73
|
+
this.allowModify = false;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Query selector of an `eox-map` (`String`, passed as an attribute or property)
|
|
77
|
+
* or an `eox-map` DOM element (`HTMLElement`, passed as property)
|
|
78
|
+
*
|
|
79
|
+
* @type {String|HTMLElement}
|
|
80
|
+
*/
|
|
81
|
+
this.for = "eox-map";
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Whether the user is currently in the process of drawing or not
|
|
85
|
+
*/
|
|
86
|
+
this.currentlyDrawing = false;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The current native OpenLayers `draw` interaction
|
|
90
|
+
* @type import("ol/interaction").Draw | import("@eox/map/src/helpers").EOxSelectInteraction
|
|
91
|
+
*/
|
|
92
|
+
this.draw = null;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* The current native OpenLayers draw `layer`
|
|
96
|
+
* @type import("ol/layer/Vector").default
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
this.drawLayer = null;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The ID of the Vector/Vector Tile Layer that contains features to be selected
|
|
103
|
+
*/
|
|
104
|
+
this.layerId = "";
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The array of drawn native OpenLayers features. Normally includes only one feature, until multiple feature drawing is enabled.
|
|
108
|
+
* @type Array<import("ol").Feature>
|
|
109
|
+
*/
|
|
110
|
+
this.drawnFeatures = [];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* The current native OpenLayers `modify` interaction
|
|
114
|
+
* @type import("ol/interaction").Modify
|
|
115
|
+
*/
|
|
116
|
+
this.modify = null;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Allow adding more than one feature at a time
|
|
120
|
+
*/
|
|
121
|
+
this.multipleFeatures = false;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Allow import features using drag-drop and upload button
|
|
125
|
+
*/
|
|
126
|
+
this.importFeatures = false;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Show geo-json editor for draw tool
|
|
130
|
+
*/
|
|
131
|
+
this.showEditor = false;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Show list of features
|
|
135
|
+
*/
|
|
136
|
+
this.showList = false;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Type of the drawn feature
|
|
140
|
+
* @type {"Polygon" | "Point" | "LineString" | "Circle" | "Box"}
|
|
141
|
+
*/
|
|
142
|
+
this.type = "Polygon";
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Render the element without additional styles
|
|
146
|
+
*/
|
|
147
|
+
this.unstyled = false;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Renders the element without a shadow root
|
|
151
|
+
*
|
|
152
|
+
* @type {Boolean}
|
|
153
|
+
*/
|
|
154
|
+
this.noShadow = false;
|
|
155
|
+
/**
|
|
156
|
+
* @type {ReturnType<typeof import("./methods/draw/create-select-handler").default>}
|
|
157
|
+
*/
|
|
158
|
+
this.selectionEvents = null;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
*
|
|
163
|
+
*
|
|
164
|
+
* @type {string}
|
|
165
|
+
*/
|
|
166
|
+
set layerId(value) {
|
|
167
|
+
handleLayerId(this, this.eoxMap, value, this.#layerId);
|
|
168
|
+
this.#layerId = value;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get layerId() {
|
|
172
|
+
return this.#layerId;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* @onClick Event handler triggered to start drawing on the map.
|
|
177
|
+
*/
|
|
178
|
+
startDrawing() {
|
|
179
|
+
startDrawingMethod(this);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @onClick Event handler triggered to discard/stop drawing
|
|
184
|
+
* on the map and delete the drawn shapes.
|
|
185
|
+
*/
|
|
186
|
+
discardDrawing() {
|
|
187
|
+
discardDrawingMethod(this);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {string} text - The string representation of the features to be parsed.
|
|
192
|
+
* @param {boolean} replaceFeatures - A boolean flag indicating whether to replace the existing features.
|
|
193
|
+
*/
|
|
194
|
+
handleFeatureChange(text, replaceFeatures = false) {
|
|
195
|
+
this.eoxMap.parseTextToFeature(
|
|
196
|
+
text || JSON.stringify(DUMMY_GEO_JSON),
|
|
197
|
+
this.drawLayer,
|
|
198
|
+
this.eoxMap,
|
|
199
|
+
replaceFeatures,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @param {DragEvent | Event} evt - The event object from the file input interaction.
|
|
205
|
+
*/
|
|
206
|
+
handleFilesChange(evt) {
|
|
207
|
+
handleFiles(evt, this);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @event onModifyEnd triggered when the modification of a shape is completed.
|
|
212
|
+
*/
|
|
213
|
+
onModifyEnd() {
|
|
214
|
+
this.emitDrawnFeatures();
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Update #geoJSON with stringify feature.
|
|
219
|
+
*/
|
|
220
|
+
updateGeoJSON() {
|
|
221
|
+
this.#geoJSON = JSON.stringify(
|
|
222
|
+
this.eoxMap.parseFeature(this.drawnFeatures) || DUMMY_GEO_JSON,
|
|
223
|
+
undefined,
|
|
224
|
+
2,
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Triggers different events when the drawing of a shape is completed.
|
|
230
|
+
*/
|
|
231
|
+
emitDrawnFeatures() {
|
|
232
|
+
const drawUpdateEvent = () => {
|
|
233
|
+
/**
|
|
234
|
+
* Fires whenever features are added, modified or discarded, where the event detail
|
|
235
|
+
* is the `drawnFeatures` array
|
|
236
|
+
* @type Array<import("ol").Feature>
|
|
237
|
+
*/
|
|
238
|
+
this.dispatchEvent(
|
|
239
|
+
new CustomEvent("drawupdate", { detail: this.drawnFeatures }),
|
|
240
|
+
);
|
|
241
|
+
};
|
|
242
|
+
emitDrawnFeaturesMethod(this, drawUpdateEvent);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Overrides createRenderRoot to handle shadow DOM creation based on the noShadow property.
|
|
247
|
+
*/
|
|
248
|
+
createRenderRoot() {
|
|
249
|
+
return this.noShadow ? this : super.createRenderRoot();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* initializes the EOxMap and OlMap instances
|
|
254
|
+
* And stores them in the private properties #eoxMap and #olMap, respectively.
|
|
255
|
+
* It then calls requestUpdate to trigger a re-render.
|
|
256
|
+
*/
|
|
257
|
+
firstUpdated() {
|
|
258
|
+
const { EoxMap, OlMap } = initLayerMethod(this, this.multipleFeatures);
|
|
259
|
+
this.eoxMap = EoxMap;
|
|
260
|
+
this.#olMap = OlMap;
|
|
261
|
+
this.selectionEvents = createSelectHandler(this);
|
|
262
|
+
|
|
263
|
+
if (this.importFeatures) initMapDragDropImport(this, this.eoxMap);
|
|
264
|
+
|
|
265
|
+
this.updateGeoJSON();
|
|
266
|
+
this.requestUpdate();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
updated(changedProperties) {
|
|
270
|
+
if (changedProperties.has("for")) {
|
|
271
|
+
const { EoxMap, OlMap } = initLayerMethod(this, this.multipleFeatures);
|
|
272
|
+
this.eoxMap = EoxMap;
|
|
273
|
+
this.#olMap = OlMap;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
get eoxMap() {
|
|
278
|
+
return this.#eoxMap;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
set eoxMap(value) {
|
|
282
|
+
const oldValue = this.#eoxMap;
|
|
283
|
+
this.#eoxMap = value;
|
|
284
|
+
this.requestUpdate("eoxMap", oldValue);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// Render method for UI display
|
|
288
|
+
render() {
|
|
289
|
+
return html`
|
|
290
|
+
<style>
|
|
291
|
+
:host { display: block; }
|
|
292
|
+
${!this.unstyled && mainStyle}
|
|
293
|
+
${!this.unstyled && styleEOX}
|
|
294
|
+
</style>
|
|
295
|
+
|
|
296
|
+
<!-- Controller Component -->
|
|
297
|
+
<eox-drawtools-controller
|
|
298
|
+
.drawFunc=${{
|
|
299
|
+
start: () => this.startDrawing(),
|
|
300
|
+
discard: () => this.discardDrawing(),
|
|
301
|
+
editor: (/** @type {{ target: { value: string; }; }} */ evt) =>
|
|
302
|
+
this.handleFeatureChange(evt.target.value, true),
|
|
303
|
+
import: (/** @type {DragEvent | Event} */ evt) =>
|
|
304
|
+
this.handleFilesChange(evt),
|
|
305
|
+
}}
|
|
306
|
+
?select=${!!this.layerId}
|
|
307
|
+
.unstyled=${this.unstyled}
|
|
308
|
+
.drawnFeatures=${this.drawnFeatures}
|
|
309
|
+
.currentlyDrawing=${this.currentlyDrawing}
|
|
310
|
+
.multipleFeatures=${this.multipleFeatures}
|
|
311
|
+
.importFeatures=${this.importFeatures}
|
|
312
|
+
.showEditor=${this.showEditor}
|
|
313
|
+
.geoJSON=${this.#geoJSON}
|
|
314
|
+
></eox-drawtools-controller>
|
|
315
|
+
|
|
316
|
+
<!-- List Component -->
|
|
317
|
+
${this.showList && this.drawnFeatures?.length
|
|
318
|
+
? html`<eox-drawtools-list
|
|
319
|
+
.eoxMap=${this.eoxMap}
|
|
320
|
+
.olMap=${this.#olMap}
|
|
321
|
+
.draw=${this.draw}
|
|
322
|
+
.drawLayer=${this.drawLayer}
|
|
323
|
+
.drawnFeatures=${this.drawnFeatures}
|
|
324
|
+
.modify=${this.modify}
|
|
325
|
+
.unstyled=${this.unstyled}
|
|
326
|
+
@changed=${() => {
|
|
327
|
+
this.updateGeoJSON();
|
|
328
|
+
this.requestUpdate();
|
|
329
|
+
}}
|
|
330
|
+
></eox-drawtools-list>`
|
|
331
|
+
: nothing}
|
|
332
|
+
`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
customElements.define("eox-drawtools", EOxDrawTools);
|