@open-pioneer/editing 0.1.0 → 0.2.1
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/CHANGELOG.md +26 -0
- package/EditingCreateWorkflowImpl.d.ts +36 -0
- package/{EditingWorkflowImpl.js → EditingCreateWorkflowImpl.js} +93 -73
- package/EditingCreateWorkflowImpl.js.map +1 -0
- package/EditingServiceImpl.d.ts +8 -5
- package/EditingServiceImpl.js +37 -11
- package/EditingServiceImpl.js.map +1 -1
- package/EditingUpdateWorkflowImpl.d.ts +41 -0
- package/EditingUpdateWorkflowImpl.js +236 -0
- package/EditingUpdateWorkflowImpl.js.map +1 -0
- package/README.md +76 -11
- package/SaveFeaturesHandler.d.ts +9 -0
- package/SaveFeaturesHandler.js +20 -3
- package/SaveFeaturesHandler.js.map +1 -1
- package/Tooltip.d.ts +17 -0
- package/Tooltip.js +35 -0
- package/Tooltip.js.map +1 -0
- package/api.d.ts +42 -9
- package/i18n/de.yaml +5 -3
- package/i18n/en.yaml +5 -3
- package/package.json +23 -13
- package/style-utils.d.ts +17 -0
- package/style-utils.js +55 -0
- package/style-utils.js.map +1 -0
- package/EditingWorkflowImpl.d.ts +0 -44
- package/EditingWorkflowImpl.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @open-pioneer/editing
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 4140646: Update trails dependencies
|
|
8
|
+
- 4140646: Update to react 18.3.1
|
|
9
|
+
- 81bc7da: Update trails dependencies
|
|
10
|
+
- 2c092dc: Update dependencies
|
|
11
|
+
- Updated dependencies [4140646]
|
|
12
|
+
- Updated dependencies [4140646]
|
|
13
|
+
- Updated dependencies [b5bb7a1]
|
|
14
|
+
- Updated dependencies [81bc7da]
|
|
15
|
+
- Updated dependencies [2c092dc]
|
|
16
|
+
- @open-pioneer/map@0.5.1
|
|
17
|
+
|
|
18
|
+
## 0.2.0
|
|
19
|
+
|
|
20
|
+
### Minor Changes
|
|
21
|
+
|
|
22
|
+
- 434fd3e: Implemented update feature workflow in EditingService
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- Updated dependencies [520a97b]
|
|
27
|
+
- @open-pioneer/map@0.5.0
|
|
28
|
+
|
|
3
29
|
## 0.1.0
|
|
4
30
|
|
|
5
31
|
### Minor Changes
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EventEmitter } from "@open-pioneer/core";
|
|
2
|
+
import { Draw } from "ol/interaction";
|
|
3
|
+
import { EditingWorkflow, EditingWorkflowEvents, EditingWorkflowProps, EditingWorkflowState } from "./api";
|
|
4
|
+
export declare class EditingCreateWorkflowImpl extends EventEmitter<EditingWorkflowEvents> implements EditingWorkflow {
|
|
5
|
+
#private;
|
|
6
|
+
private _httpService;
|
|
7
|
+
private _intl;
|
|
8
|
+
private _map;
|
|
9
|
+
private _polygonStyle;
|
|
10
|
+
private _vertexStyle;
|
|
11
|
+
private _state;
|
|
12
|
+
private _editLayerURL;
|
|
13
|
+
private _featureId;
|
|
14
|
+
private _editingSource;
|
|
15
|
+
private _editingLayer;
|
|
16
|
+
private _drawInteraction;
|
|
17
|
+
private _olMap;
|
|
18
|
+
private _mapContainer;
|
|
19
|
+
private _tooltip;
|
|
20
|
+
private _enterHandler;
|
|
21
|
+
private _escapeHandler;
|
|
22
|
+
private _error;
|
|
23
|
+
private _interactionListener;
|
|
24
|
+
private _mapListener;
|
|
25
|
+
constructor(options: EditingWorkflowProps);
|
|
26
|
+
getDrawInteraction(): Draw;
|
|
27
|
+
getState(): EditingWorkflowState;
|
|
28
|
+
private _setState;
|
|
29
|
+
private _save;
|
|
30
|
+
private _start;
|
|
31
|
+
reset(): void;
|
|
32
|
+
stop(): void;
|
|
33
|
+
private _destroy;
|
|
34
|
+
triggerSave(): void;
|
|
35
|
+
whenComplete(): Promise<Record<string, string> | undefined>;
|
|
36
|
+
}
|
|
@@ -1,59 +1,71 @@
|
|
|
1
|
-
import { EventEmitter, createManualPromise } from '@open-pioneer/core';
|
|
1
|
+
import { createLogger, EventEmitter, createManualPromise } from '@open-pioneer/core';
|
|
2
2
|
import { TOPMOST_LAYER_Z } from '@open-pioneer/map';
|
|
3
|
+
import { unByKey } from 'ol/Observable';
|
|
4
|
+
import GeoJSON from 'ol/format/GeoJSON';
|
|
3
5
|
import { Draw } from 'ol/interaction';
|
|
4
6
|
import VectorLayer from 'ol/layer/Vector';
|
|
5
7
|
import VectorSource from 'ol/source/Vector';
|
|
6
|
-
import GeoJSON from 'ol/format/GeoJSON';
|
|
7
8
|
import { saveCreatedFeature } from './SaveFeaturesHandler.js';
|
|
8
|
-
import
|
|
9
|
-
import {
|
|
9
|
+
import { createTooltip } from './Tooltip.js';
|
|
10
|
+
import { createStyles } from './style-utils.js';
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
const LOG = createLogger("editing:EditingCreateWorkflowImpl");
|
|
13
|
+
class EditingCreateWorkflowImpl extends EventEmitter {
|
|
12
14
|
#waiter;
|
|
13
15
|
_httpService;
|
|
14
16
|
_intl;
|
|
15
17
|
_map;
|
|
16
|
-
|
|
18
|
+
_polygonStyle;
|
|
19
|
+
_vertexStyle;
|
|
17
20
|
_state;
|
|
18
21
|
_editLayerURL;
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
_featureId;
|
|
23
|
+
_editingSource;
|
|
24
|
+
_editingLayer;
|
|
21
25
|
_drawInteraction;
|
|
22
26
|
_olMap;
|
|
23
27
|
_mapContainer;
|
|
24
28
|
_tooltip;
|
|
25
29
|
_enterHandler;
|
|
26
30
|
_escapeHandler;
|
|
31
|
+
_error;
|
|
27
32
|
_interactionListener;
|
|
28
33
|
_mapListener;
|
|
29
34
|
constructor(options) {
|
|
30
35
|
super();
|
|
31
36
|
this._httpService = options.httpService;
|
|
32
37
|
this._intl = options.intl;
|
|
33
|
-
this.
|
|
38
|
+
this._polygonStyle = options.polygonStyle;
|
|
39
|
+
this._vertexStyle = options.vertexStyle;
|
|
34
40
|
this._map = options.map;
|
|
35
41
|
this._olMap = options.map.olMap;
|
|
36
42
|
this._state = "active:initialized";
|
|
37
43
|
this._editLayerURL = options.ogcApiFeatureLayerUrl;
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
source: this.
|
|
44
|
+
this._editingSource = new VectorSource();
|
|
45
|
+
this._editingLayer = new VectorLayer({
|
|
46
|
+
source: this._editingSource,
|
|
41
47
|
zIndex: TOPMOST_LAYER_Z,
|
|
42
48
|
properties: {
|
|
43
49
|
name: "editing-layer"
|
|
44
50
|
}
|
|
45
51
|
});
|
|
46
52
|
this._drawInteraction = new Draw({
|
|
47
|
-
source: this.
|
|
53
|
+
source: this._editingSource,
|
|
48
54
|
type: "Polygon",
|
|
49
|
-
style:
|
|
55
|
+
style: createStyles({
|
|
56
|
+
polygon: this._polygonStyle,
|
|
57
|
+
vertex: this._vertexStyle
|
|
58
|
+
})
|
|
50
59
|
});
|
|
51
|
-
this._tooltip =
|
|
60
|
+
this._tooltip = createTooltip(
|
|
61
|
+
this._olMap,
|
|
62
|
+
this._intl.formatMessage({ id: "create.tooltip.begin" })
|
|
63
|
+
);
|
|
52
64
|
this._enterHandler = (e) => {
|
|
53
|
-
if (e.code === "Enter" && e.target === this._olMap.getTargetElement()) {
|
|
65
|
+
if ((e.code === "Enter" || e.code === "NumpadEnter") && e.target === this._olMap.getTargetElement()) {
|
|
54
66
|
const features = this._drawInteraction.getOverlay().getSource().getFeatures();
|
|
55
67
|
if (features[0] && features[0].getGeometry().getCoordinates()[0].length > 4) {
|
|
56
|
-
this.
|
|
68
|
+
this.triggerSave();
|
|
57
69
|
}
|
|
58
70
|
}
|
|
59
71
|
};
|
|
@@ -76,46 +88,61 @@ class EditingWorkflowImpl extends EventEmitter {
|
|
|
76
88
|
this._state = state;
|
|
77
89
|
this.emit(state);
|
|
78
90
|
}
|
|
91
|
+
_save(feature) {
|
|
92
|
+
this._setState("active:saving");
|
|
93
|
+
const layerUrl = this._editLayerURL;
|
|
94
|
+
const geometry = feature.getGeometry();
|
|
95
|
+
if (!geometry) {
|
|
96
|
+
this._destroy();
|
|
97
|
+
this._error = new Error("no geometry available");
|
|
98
|
+
this.#waiter?.reject(this._error);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const projection = this._olMap.getView().getProjection();
|
|
102
|
+
const geoJson = new GeoJSON({
|
|
103
|
+
dataProjection: projection
|
|
104
|
+
});
|
|
105
|
+
const geoJSONGeometry = geoJson.writeGeometryObject(geometry, {
|
|
106
|
+
rightHanded: true,
|
|
107
|
+
decimals: 10
|
|
108
|
+
});
|
|
109
|
+
saveCreatedFeature(this._httpService, layerUrl, geoJSONGeometry, projection).then((featureId) => {
|
|
110
|
+
this._featureId = featureId;
|
|
111
|
+
this._destroy();
|
|
112
|
+
this.#waiter?.resolve({ featureId: this._featureId });
|
|
113
|
+
}).catch((err) => {
|
|
114
|
+
LOG.error(err);
|
|
115
|
+
this._destroy();
|
|
116
|
+
this._error = new Error("Failed to save feature", { cause: err });
|
|
117
|
+
this.#waiter?.reject(this._error);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
79
120
|
_start() {
|
|
80
|
-
this._olMap.addLayer(this.
|
|
121
|
+
this._olMap.addLayer(this._editingLayer);
|
|
81
122
|
this._olMap.addInteraction(this._drawInteraction);
|
|
82
123
|
this._mapContainer = this._olMap.getTargetElement() ?? void 0;
|
|
83
124
|
if (this._mapContainer) {
|
|
84
125
|
this._mapContainer.addEventListener("keydown", this._enterHandler, false);
|
|
85
126
|
this._mapContainer.addEventListener("keydown", this._escapeHandler, false);
|
|
86
127
|
}
|
|
87
|
-
this._tooltip.
|
|
128
|
+
this._tooltip.setVisible(true);
|
|
88
129
|
const drawStart = this._drawInteraction.on("drawstart", () => {
|
|
89
130
|
this._setState("active:drawing");
|
|
90
|
-
this._tooltip.
|
|
91
|
-
|
|
92
|
-
|
|
131
|
+
this._tooltip.setText(
|
|
132
|
+
this._intl.formatMessage({
|
|
133
|
+
id: "create.tooltip.continue"
|
|
134
|
+
})
|
|
135
|
+
);
|
|
93
136
|
});
|
|
94
137
|
const drawEnd = this._drawInteraction.on("drawend", (e) => {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const geometry = e.feature.getGeometry();
|
|
98
|
-
if (!geometry) {
|
|
138
|
+
const feature = e.feature;
|
|
139
|
+
if (!feature) {
|
|
99
140
|
this._destroy();
|
|
100
|
-
this
|
|
141
|
+
this._error = new Error("no feature available");
|
|
142
|
+
this.#waiter?.reject(this._error);
|
|
101
143
|
return;
|
|
102
144
|
}
|
|
103
|
-
|
|
104
|
-
const geoJson = new GeoJSON({
|
|
105
|
-
dataProjection: projection
|
|
106
|
-
});
|
|
107
|
-
const geoJSONGeometry = geoJson.writeGeometryObject(geometry, {
|
|
108
|
-
rightHanded: true,
|
|
109
|
-
decimals: 10
|
|
110
|
-
});
|
|
111
|
-
saveCreatedFeature(this._httpService, layerUrl, geoJSONGeometry, projection).then((featureId) => {
|
|
112
|
-
this._destroy();
|
|
113
|
-
this.#waiter?.resolve(featureId);
|
|
114
|
-
}).catch((err) => {
|
|
115
|
-
console.log(err);
|
|
116
|
-
this._destroy();
|
|
117
|
-
this.#waiter?.reject(err);
|
|
118
|
-
});
|
|
145
|
+
this._save(feature);
|
|
119
146
|
});
|
|
120
147
|
const changedContainer = this._map.on("changed:container", () => {
|
|
121
148
|
this._mapContainer?.removeEventListener("keydown", this._enterHandler);
|
|
@@ -131,7 +158,11 @@ class EditingWorkflowImpl extends EventEmitter {
|
|
|
131
158
|
}
|
|
132
159
|
reset() {
|
|
133
160
|
this._drawInteraction.abortDrawing();
|
|
134
|
-
this._tooltip.
|
|
161
|
+
this._tooltip.setText(
|
|
162
|
+
this._intl.formatMessage({
|
|
163
|
+
id: "create.tooltip.begin"
|
|
164
|
+
})
|
|
165
|
+
);
|
|
135
166
|
this._setState("active:initialized");
|
|
136
167
|
}
|
|
137
168
|
stop() {
|
|
@@ -139,7 +170,7 @@ class EditingWorkflowImpl extends EventEmitter {
|
|
|
139
170
|
this.#waiter?.resolve(void 0);
|
|
140
171
|
}
|
|
141
172
|
_destroy() {
|
|
142
|
-
this._olMap.removeLayer(this.
|
|
173
|
+
this._olMap.removeLayer(this._editingLayer);
|
|
143
174
|
this._olMap.removeInteraction(this._drawInteraction);
|
|
144
175
|
this._tooltip.destroy();
|
|
145
176
|
this._interactionListener.map((listener) => {
|
|
@@ -150,38 +181,27 @@ class EditingWorkflowImpl extends EventEmitter {
|
|
|
150
181
|
});
|
|
151
182
|
this._mapContainer?.removeEventListener("keydown", this._enterHandler);
|
|
152
183
|
this._mapContainer?.removeEventListener("keydown", this._escapeHandler);
|
|
153
|
-
this.
|
|
184
|
+
this._setState("destroyed");
|
|
185
|
+
}
|
|
186
|
+
triggerSave() {
|
|
187
|
+
this._drawInteraction.finishDrawing();
|
|
154
188
|
}
|
|
155
189
|
whenComplete() {
|
|
190
|
+
if (this._state === "destroyed") {
|
|
191
|
+
if (this._error) {
|
|
192
|
+
return Promise.reject(this._error);
|
|
193
|
+
} else {
|
|
194
|
+
if (this._featureId) {
|
|
195
|
+
return Promise.resolve({ featureId: this._featureId });
|
|
196
|
+
} else {
|
|
197
|
+
return Promise.resolve(void 0);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
156
201
|
const manualPromise = this.#waiter ??= createManualPromise();
|
|
157
202
|
return manualPromise.promise;
|
|
158
203
|
}
|
|
159
|
-
_createTooltip(olMap) {
|
|
160
|
-
const element = document.createElement("div");
|
|
161
|
-
element.className = "editing-tooltip editing-tooltip-hidden";
|
|
162
|
-
element.textContent = this._intl.formatMessage({ id: "tooltip.begin" });
|
|
163
|
-
const overlay = new Overlay({
|
|
164
|
-
element,
|
|
165
|
-
offset: [15, 0],
|
|
166
|
-
positioning: "center-left"
|
|
167
|
-
});
|
|
168
|
-
const pointerMove = olMap.on("pointermove", (evt) => {
|
|
169
|
-
if (evt.dragging) {
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
overlay.setPosition(evt.coordinate);
|
|
173
|
-
});
|
|
174
|
-
olMap.addOverlay(overlay);
|
|
175
|
-
return {
|
|
176
|
-
overlay,
|
|
177
|
-
element,
|
|
178
|
-
destroy() {
|
|
179
|
-
unByKey(pointerMove);
|
|
180
|
-
olMap.removeOverlay(overlay);
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
204
|
}
|
|
185
205
|
|
|
186
|
-
export {
|
|
187
|
-
//# sourceMappingURL=
|
|
206
|
+
export { EditingCreateWorkflowImpl };
|
|
207
|
+
//# sourceMappingURL=EditingCreateWorkflowImpl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EditingCreateWorkflowImpl.js","sources":["EditingCreateWorkflowImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n EventEmitter,\n ManualPromise,\n Resource,\n createLogger,\n createManualPromise\n} from \"@open-pioneer/core\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport { MapModel, TOPMOST_LAYER_Z } from \"@open-pioneer/map\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport Feature from \"ol/Feature\";\nimport OlMap from \"ol/Map\";\nimport { unByKey } from \"ol/Observable\";\nimport { EventsKey } from \"ol/events\";\nimport {\n default as GeoJSON,\n default as GeoJSONGeometry,\n default as GeoJSONGeometryCollection\n} from \"ol/format/GeoJSON\";\nimport { Draw } from \"ol/interaction\";\nimport VectorLayer from \"ol/layer/Vector\";\nimport VectorSource from \"ol/source/Vector\";\nimport { FlatStyle } from \"ol/style/flat\";\nimport { saveCreatedFeature } from \"./SaveFeaturesHandler\";\nimport { Tooltip, createTooltip } from \"./Tooltip\";\nimport {\n EditingWorkflow,\n EditingWorkflowEvents,\n EditingWorkflowProps,\n EditingWorkflowState\n} from \"./api\";\nimport { createStyles } from \"./style-utils\";\n\nconst LOG = createLogger(\"editing:EditingCreateWorkflowImpl\");\n\nexport class EditingCreateWorkflowImpl\n extends EventEmitter<EditingWorkflowEvents>\n implements EditingWorkflow\n{\n #waiter: ManualPromise<Record<string, string> | undefined> | undefined;\n\n private _httpService: HttpService;\n private _intl: PackageIntl;\n\n private _map: MapModel;\n private _polygonStyle: FlatStyle;\n private _vertexStyle: FlatStyle;\n private _state: EditingWorkflowState;\n private _editLayerURL: URL;\n private _featureId: string | undefined;\n\n private _editingSource: VectorSource;\n private _editingLayer: VectorLayer<VectorSource>;\n private _drawInteraction: Draw;\n private _olMap: OlMap;\n private _mapContainer: HTMLElement | undefined;\n private _tooltip: Tooltip;\n private _enterHandler: (e: KeyboardEvent) => void;\n private _escapeHandler: (e: KeyboardEvent) => void;\n\n private _error: Error | undefined;\n\n private _interactionListener: Array<EventsKey>;\n private _mapListener: Array<Resource>;\n\n constructor(options: EditingWorkflowProps) {\n super();\n this._httpService = options.httpService;\n this._intl = options.intl;\n\n this._polygonStyle = options.polygonStyle;\n this._vertexStyle = options.vertexStyle;\n\n this._map = options.map;\n this._olMap = options.map.olMap;\n this._state = \"active:initialized\";\n this._editLayerURL = options.ogcApiFeatureLayerUrl;\n\n this._editingSource = new VectorSource();\n this._editingLayer = new VectorLayer({\n source: this._editingSource,\n zIndex: TOPMOST_LAYER_Z,\n properties: {\n name: \"editing-layer\"\n }\n });\n\n this._drawInteraction = new Draw({\n source: this._editingSource,\n type: \"Polygon\",\n style: createStyles({\n polygon: this._polygonStyle,\n vertex: this._vertexStyle\n })\n });\n\n this._tooltip = createTooltip(\n this._olMap,\n this._intl.formatMessage({ id: \"create.tooltip.begin\" })\n );\n\n this._enterHandler = (e: KeyboardEvent) => {\n if (\n (e.code === \"Enter\" || e.code === \"NumpadEnter\") &&\n e.target === this._olMap.getTargetElement()\n ) {\n const features = this._drawInteraction.getOverlay().getSource().getFeatures();\n\n /**\n * Get the first linear ring of the polygon\n * Coordinates include closing vertex, so a triangle has 4, while drawing the\n * actual mouse position is an extra vertex, therefor we have to check\n * \"length > 4\" instead of \"length >= 4\"\n */\n if (features[0] && features[0].getGeometry().getCoordinates()[0].length > 4) {\n this.triggerSave();\n }\n }\n };\n\n this._escapeHandler = (e: KeyboardEvent) => {\n if (e.code === \"Escape\" && e.target === this._olMap.getTargetElement()) {\n this.reset();\n }\n };\n\n this._interactionListener = [];\n this._mapListener = [];\n\n this._start();\n }\n\n getDrawInteraction() {\n return this._drawInteraction;\n }\n\n getState() {\n return this._state;\n }\n\n private _setState(state: EditingWorkflowState) {\n this._state = state;\n this.emit(state);\n }\n\n private _save(feature: Feature) {\n this._setState(\"active:saving\");\n\n const layerUrl = this._editLayerURL;\n\n const geometry = feature.getGeometry();\n if (!geometry) {\n this._destroy();\n this._error = new Error(\"no geometry available\");\n this.#waiter?.reject(this._error);\n return;\n }\n const projection = this._olMap.getView().getProjection();\n const geoJson = new GeoJSON({\n dataProjection: projection\n });\n const geoJSONGeometry: GeoJSONGeometry | GeoJSONGeometryCollection =\n geoJson.writeGeometryObject(geometry, {\n rightHanded: true,\n decimals: 10\n });\n\n saveCreatedFeature(this._httpService, layerUrl, geoJSONGeometry, projection)\n .then((featureId) => {\n this._featureId = featureId;\n this._destroy();\n this.#waiter?.resolve({ featureId: this._featureId });\n })\n .catch((err: Error) => {\n LOG.error(err);\n this._destroy();\n this._error = new Error(\"Failed to save feature\", { cause: err });\n this.#waiter?.reject(this._error);\n });\n }\n\n private _start() {\n this._olMap.addLayer(this._editingLayer);\n this._olMap.addInteraction(this._drawInteraction);\n\n // Add EventListener on focused map to abort actual interaction via `Escape`\n this._mapContainer = this._olMap.getTargetElement() ?? undefined;\n if (this._mapContainer) {\n this._mapContainer.addEventListener(\"keydown\", this._enterHandler, false);\n this._mapContainer.addEventListener(\"keydown\", this._escapeHandler, false);\n }\n\n this._tooltip.setVisible(true);\n\n const drawStart = this._drawInteraction.on(\"drawstart\", () => {\n this._setState(\"active:drawing\");\n this._tooltip.setText(\n this._intl.formatMessage({\n id: \"create.tooltip.continue\"\n })\n );\n });\n\n const drawEnd = this._drawInteraction.on(\"drawend\", (e) => {\n const feature = e.feature;\n if (!feature) {\n this._destroy();\n this._error = new Error(\"no feature available\");\n this.#waiter?.reject(this._error);\n return;\n }\n this._save(feature);\n });\n\n // update event handler when container changes\n const changedContainer = this._map.on(\"changed:container\", () => {\n this._mapContainer?.removeEventListener(\"keydown\", this._enterHandler);\n this._mapContainer?.removeEventListener(\"keydown\", this._escapeHandler);\n\n this._mapContainer = this._olMap.getTargetElement() ?? undefined;\n if (this._mapContainer) {\n this._mapContainer.addEventListener(\"keydown\", this._enterHandler, false);\n this._mapContainer.addEventListener(\"keydown\", this._escapeHandler, false);\n }\n });\n\n this._interactionListener.push(drawStart, drawEnd);\n this._mapListener.push(changedContainer);\n }\n\n reset() {\n this._drawInteraction.abortDrawing();\n this._tooltip.setText(\n this._intl.formatMessage({\n id: \"create.tooltip.begin\"\n })\n );\n this._setState(\"active:initialized\");\n }\n\n stop() {\n this._destroy();\n this.#waiter?.resolve(undefined);\n }\n\n private _destroy() {\n this._olMap.removeLayer(this._editingLayer);\n this._olMap.removeInteraction(this._drawInteraction);\n this._tooltip.destroy();\n\n // Remove event listener on interaction and on map\n this._interactionListener.map((listener) => {\n unByKey(listener);\n });\n this._mapListener.map((listener) => {\n listener.destroy();\n });\n\n // Remove event escape listener\n this._mapContainer?.removeEventListener(\"keydown\", this._enterHandler);\n this._mapContainer?.removeEventListener(\"keydown\", this._escapeHandler);\n\n this._setState(\"destroyed\");\n }\n\n triggerSave() {\n // Stop drawing - the `drawend` event is dispatched before inserting the feature.\n this._drawInteraction.finishDrawing();\n }\n\n whenComplete(): Promise<Record<string, string> | undefined> {\n if (this._state === \"destroyed\") {\n if (this._error) {\n return Promise.reject(this._error);\n } else {\n if (this._featureId) {\n return Promise.resolve({ featureId: this._featureId });\n } else {\n return Promise.resolve(undefined);\n }\n }\n }\n\n const manualPromise = (this.#waiter ??= createManualPromise());\n return manualPromise.promise;\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;;AAmCA,MAAM,GAAA,GAAM,aAAa,mCAAmC,CAAA,CAAA;AAErD,MAAM,kCACD,YAEZ,CAAA;AAAA,EACI,OAAA,CAAA;AAAA,EAEQ,YAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EAEA,IAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EAEA,cAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,gBAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,QAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EACA,cAAA,CAAA;AAAA,EAEA,MAAA,CAAA;AAAA,EAEA,oBAAA,CAAA;AAAA,EACA,YAAA,CAAA;AAAA,EAER,YAAY,OAA+B,EAAA;AACvC,IAAM,KAAA,EAAA,CAAA;AACN,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,WAAA,CAAA;AAC5B,IAAA,IAAA,CAAK,QAAQ,OAAQ,CAAA,IAAA,CAAA;AAErB,IAAA,IAAA,CAAK,gBAAgB,OAAQ,CAAA,YAAA,CAAA;AAC7B,IAAA,IAAA,CAAK,eAAe,OAAQ,CAAA,WAAA,CAAA;AAE5B,IAAA,IAAA,CAAK,OAAO,OAAQ,CAAA,GAAA,CAAA;AACpB,IAAK,IAAA,CAAA,MAAA,GAAS,QAAQ,GAAI,CAAA,KAAA,CAAA;AAC1B,IAAA,IAAA,CAAK,MAAS,GAAA,oBAAA,CAAA;AACd,IAAA,IAAA,CAAK,gBAAgB,OAAQ,CAAA,qBAAA,CAAA;AAE7B,IAAK,IAAA,CAAA,cAAA,GAAiB,IAAI,YAA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{ MapModel, MapRegistry } from "@open-pioneer/map";
|
|
2
2
|
import { EditingService } from "./api";
|
|
3
|
-
import {
|
|
3
|
+
import { EditingCreateWorkflowImpl } from "./EditingCreateWorkflowImpl";
|
|
4
|
+
import { EditingUpdateWorkflowImpl } from "./EditingUpdateWorkflowImpl";
|
|
4
5
|
import { ServiceOptions } from "@open-pioneer/runtime";
|
|
5
6
|
import { HttpService } from "@open-pioneer/http";
|
|
7
|
+
import { Feature } from "ol";
|
|
6
8
|
export interface References {
|
|
7
9
|
mapRegistry: MapRegistry;
|
|
8
10
|
httpService: HttpService;
|
|
@@ -11,8 +13,9 @@ export declare class EditingServiceImpl implements EditingService {
|
|
|
11
13
|
private _serviceOptions;
|
|
12
14
|
private _workflows;
|
|
13
15
|
constructor(serviceOptions: ServiceOptions<References>);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
createFeature(map: MapModel, ogcApiFeatureLayerUrl: URL): EditingCreateWorkflowImpl;
|
|
17
|
+
updateFeature(map: MapModel, ogcApiFeatureLayerUrl: URL, feature: Feature): EditingUpdateWorkflowImpl;
|
|
18
|
+
stop(mapId: string): void;
|
|
19
|
+
reset(mapId: string): void;
|
|
20
|
+
_connectToWorkflowDestroyEvent(workflow: EditingCreateWorkflowImpl | EditingUpdateWorkflowImpl, mapId: string): void;
|
|
18
21
|
}
|
package/EditingServiceImpl.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EditingCreateWorkflowImpl } from './EditingCreateWorkflowImpl.js';
|
|
2
|
+
import { EditingUpdateWorkflowImpl } from './EditingUpdateWorkflowImpl.js';
|
|
2
3
|
|
|
3
4
|
class EditingServiceImpl {
|
|
4
5
|
_serviceOptions;
|
|
@@ -7,7 +8,7 @@ class EditingServiceImpl {
|
|
|
7
8
|
this._serviceOptions = serviceOptions;
|
|
8
9
|
this._workflows = /* @__PURE__ */ new Map();
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
createFeature(map, ogcApiFeatureLayerUrl) {
|
|
11
12
|
if (!ogcApiFeatureLayerUrl || !map || !map.id) {
|
|
12
13
|
throw new Error("Map, mapId or url is undefined.");
|
|
13
14
|
}
|
|
@@ -18,23 +19,46 @@ class EditingServiceImpl {
|
|
|
18
19
|
"EditingWorkflow could not be started. EditingWorkflow already in progress for this map."
|
|
19
20
|
);
|
|
20
21
|
}
|
|
21
|
-
workflow = new
|
|
22
|
+
workflow = new EditingCreateWorkflowImpl({
|
|
22
23
|
map,
|
|
23
24
|
ogcApiFeatureLayerUrl,
|
|
24
|
-
|
|
25
|
+
polygonStyle: this._serviceOptions.properties.polygonStyle,
|
|
26
|
+
vertexStyle: this._serviceOptions.properties.vertexStyle,
|
|
25
27
|
httpService: this._serviceOptions.references.httpService,
|
|
26
28
|
intl: this._serviceOptions.intl
|
|
27
29
|
});
|
|
28
30
|
this._workflows.set(mapId, workflow);
|
|
29
|
-
this.
|
|
31
|
+
this._connectToWorkflowDestroyEvent(workflow, mapId);
|
|
32
|
+
return workflow;
|
|
33
|
+
}
|
|
34
|
+
updateFeature(map, ogcApiFeatureLayerUrl, feature) {
|
|
35
|
+
if (!ogcApiFeatureLayerUrl || !map || !map.id) {
|
|
36
|
+
throw new Error("Map, mapId or url is undefined.");
|
|
37
|
+
}
|
|
38
|
+
const mapId = map.id;
|
|
39
|
+
let workflow = this._workflows.get(mapId);
|
|
40
|
+
if (workflow) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"EditingWorkflow could not be started. EditingWorkflow already in progress for this map."
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
workflow = new EditingUpdateWorkflowImpl({
|
|
46
|
+
map,
|
|
47
|
+
ogcApiFeatureLayerUrl,
|
|
48
|
+
feature,
|
|
49
|
+
polygonStyle: this._serviceOptions.properties.polygonStyle,
|
|
50
|
+
vertexStyle: this._serviceOptions.properties.vertexStyle,
|
|
51
|
+
httpService: this._serviceOptions.references.httpService,
|
|
52
|
+
intl: this._serviceOptions.intl
|
|
53
|
+
});
|
|
54
|
+
this._workflows.set(mapId, workflow);
|
|
55
|
+
this._connectToWorkflowDestroyEvent(workflow, mapId);
|
|
30
56
|
return workflow;
|
|
31
57
|
}
|
|
32
58
|
stop(mapId) {
|
|
33
59
|
const workflow = this._workflows.get(mapId);
|
|
34
60
|
if (workflow) {
|
|
35
61
|
workflow.stop();
|
|
36
|
-
} else {
|
|
37
|
-
return new Error("No workflow found for mapId: " + mapId);
|
|
38
62
|
}
|
|
39
63
|
}
|
|
40
64
|
reset(mapId) {
|
|
@@ -42,12 +66,14 @@ class EditingServiceImpl {
|
|
|
42
66
|
if (workflow) {
|
|
43
67
|
workflow.reset();
|
|
44
68
|
} else {
|
|
45
|
-
|
|
69
|
+
throw new Error("No workflow found for mapId: " + mapId);
|
|
46
70
|
}
|
|
47
71
|
}
|
|
48
|
-
|
|
49
|
-
workflow.
|
|
50
|
-
this._workflows.
|
|
72
|
+
_connectToWorkflowDestroyEvent(workflow, mapId) {
|
|
73
|
+
workflow.on("destroyed", () => {
|
|
74
|
+
if (this._workflows.get(mapId) === workflow) {
|
|
75
|
+
this._workflows.delete(mapId);
|
|
76
|
+
}
|
|
51
77
|
});
|
|
52
78
|
}
|
|
53
79
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditingServiceImpl.js","sources":["EditingServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModel, MapRegistry } from \"@open-pioneer/map\";\nimport { EditingService } from \"./api\";\nimport {
|
|
1
|
+
{"version":3,"file":"EditingServiceImpl.js","sources":["EditingServiceImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModel, MapRegistry } from \"@open-pioneer/map\";\nimport { EditingService } from \"./api\";\nimport { EditingCreateWorkflowImpl } from \"./EditingCreateWorkflowImpl\";\nimport { EditingUpdateWorkflowImpl } from \"./EditingUpdateWorkflowImpl\";\nimport { FlatStyle } from \"ol/style/flat\";\nimport { ServiceOptions } from \"@open-pioneer/runtime\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport { Feature } from \"ol\";\n\nexport interface References {\n mapRegistry: MapRegistry;\n httpService: HttpService;\n}\n\nexport class EditingServiceImpl implements EditingService {\n private _serviceOptions: ServiceOptions<References>;\n private _workflows: Map<string, EditingCreateWorkflowImpl | EditingUpdateWorkflowImpl>;\n\n constructor(serviceOptions: ServiceOptions<References>) {\n this._serviceOptions = serviceOptions;\n this._workflows = new Map();\n }\n\n createFeature(map: MapModel, ogcApiFeatureLayerUrl: URL): EditingCreateWorkflowImpl {\n if (!ogcApiFeatureLayerUrl || !map || !map.id) {\n throw new Error(\"Map, mapId or url is undefined.\");\n }\n\n const mapId = map.id;\n\n let workflow = this._workflows.get(mapId);\n if (workflow) {\n throw new Error(\n \"EditingWorkflow could not be started. EditingWorkflow already in progress for this map.\"\n );\n }\n\n workflow = new EditingCreateWorkflowImpl({\n map,\n ogcApiFeatureLayerUrl,\n polygonStyle: this._serviceOptions.properties.polygonStyle as FlatStyle,\n vertexStyle: this._serviceOptions.properties.vertexStyle as FlatStyle,\n httpService: this._serviceOptions.references.httpService,\n intl: this._serviceOptions.intl\n });\n this._workflows.set(mapId, workflow);\n this._connectToWorkflowDestroyEvent(workflow, mapId);\n\n return workflow;\n }\n\n updateFeature(\n map: MapModel,\n ogcApiFeatureLayerUrl: URL,\n feature: Feature\n ): EditingUpdateWorkflowImpl {\n if (!ogcApiFeatureLayerUrl || !map || !map.id) {\n throw new Error(\"Map, mapId or url is undefined.\");\n }\n\n const mapId = map.id;\n\n let workflow = this._workflows.get(mapId);\n if (workflow) {\n throw new Error(\n \"EditingWorkflow could not be started. EditingWorkflow already in progress for this map.\"\n );\n }\n\n workflow = new EditingUpdateWorkflowImpl({\n map,\n ogcApiFeatureLayerUrl,\n feature,\n polygonStyle: this._serviceOptions.properties.polygonStyle as FlatStyle,\n vertexStyle: this._serviceOptions.properties.vertexStyle as FlatStyle,\n httpService: this._serviceOptions.references.httpService,\n intl: this._serviceOptions.intl\n });\n this._workflows.set(mapId, workflow);\n this._connectToWorkflowDestroyEvent(workflow, mapId);\n\n return workflow;\n }\n\n stop(mapId: string): void {\n const workflow = this._workflows.get(mapId);\n if (workflow) {\n workflow.stop();\n }\n // A missing workflow is not an error if all we want to do is stop it.\n }\n\n reset(mapId: string): void {\n const workflow = this._workflows.get(mapId);\n if (workflow) {\n workflow.reset();\n } else {\n throw new Error(\"No workflow found for mapId: \" + mapId);\n }\n }\n\n _connectToWorkflowDestroyEvent(\n workflow: EditingCreateWorkflowImpl | EditingUpdateWorkflowImpl,\n mapId: string\n ) {\n workflow.on(\"destroyed\", () => {\n if (this._workflows.get(mapId) === workflow) {\n this._workflows.delete(mapId);\n }\n });\n }\n}\n"],"names":[],"mappings":";;;AAgBO,MAAM,kBAA6C,CAAA;AAAA,EAC9C,eAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EAER,YAAY,cAA4C,EAAA;AACpD,IAAA,IAAA,CAAK,eAAkB,GAAA,cAAA,CAAA;AACvB,IAAK,IAAA,CAAA,UAAA,uBAAiB,GAAI,EAAA,CAAA;AAAA,GAC9B;AAAA,EAEA,aAAA,CAAc,KAAe,qBAAuD,EAAA;AAChF,IAAA,IAAI,CAAC,qBAAyB,IAAA,CAAC,GAAO,IAAA,CAAC,IAAI,EAAI,EAAA;AAC3C,MAAM,MAAA,IAAI,MAAM,iCAAiC,CAAA,CAAA;AAAA,KACrD;AAEA,IAAA,MAAM,QAAQ,GAAI,CAAA,EAAA,CAAA;AAElB,IAAA,IAAI,QAAW,GAAA,IAAA,CAAK,UAAW,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AACxC,IAAA,IAAI,QAAU,EAAA;AACV,MAAA,MAAM,IAAI,KAAA;AAAA,QAC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} from "ol/interaction";
|
|
3
|
+
import Feature from "ol/Feature";
|
|
4
|
+
import { EditingWorkflowEvents, EditingWorkflowState, EditingWorkflow, EditingWorkflowProps } from "./api";
|
|
5
|
+
export declare class EditingUpdateWorkflowImpl extends EventEmitter<EditingWorkflowEvents> implements EditingWorkflow {
|
|
6
|
+
#private;
|
|
7
|
+
private _httpService;
|
|
8
|
+
private _intl;
|
|
9
|
+
private _map;
|
|
10
|
+
private _polygonStyle;
|
|
11
|
+
private _vertexStyle;
|
|
12
|
+
private _state;
|
|
13
|
+
private _editLayerURL;
|
|
14
|
+
private _featureId;
|
|
15
|
+
private _initialFeature;
|
|
16
|
+
private _editFeature;
|
|
17
|
+
private _editingSource;
|
|
18
|
+
private _editingLayer;
|
|
19
|
+
private _modifyInteraction;
|
|
20
|
+
private _olMap;
|
|
21
|
+
private _mapContainer;
|
|
22
|
+
private _tooltip;
|
|
23
|
+
private _enterHandler;
|
|
24
|
+
private _escapeHandler;
|
|
25
|
+
private _error;
|
|
26
|
+
private _interactionListener;
|
|
27
|
+
private _mapListener;
|
|
28
|
+
constructor(options: {
|
|
29
|
+
feature: Feature;
|
|
30
|
+
} & EditingWorkflowProps);
|
|
31
|
+
getModifyInteraction(): Modify;
|
|
32
|
+
getState(): EditingWorkflowState;
|
|
33
|
+
private _setState;
|
|
34
|
+
private _save;
|
|
35
|
+
private _start;
|
|
36
|
+
reset(): void;
|
|
37
|
+
stop(): void;
|
|
38
|
+
private _destroy;
|
|
39
|
+
triggerSave(): void;
|
|
40
|
+
whenComplete(): Promise<Record<string, string> | undefined>;
|
|
41
|
+
}
|