@open-pioneer/editing 0.1.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/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # @open-pioneer/editing
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ac7fdd1: Initial release.
8
+ - 9334e81: Update to OpenLayers 9
9
+
10
+ ### Patch Changes
11
+
12
+ - 1a8ad89: Update package.json metadata
13
+ - 6162979: Update versions of core packages
14
+ - Updated dependencies [1a8ad89]
15
+ - Updated dependencies [a11bf72]
16
+ - Updated dependencies [fc6bf82]
17
+ - Updated dependencies [a0d8882]
18
+ - Updated dependencies [6162979]
19
+ - Updated dependencies [9334e81]
20
+ - Updated dependencies [ac7fdd1]
21
+ - Updated dependencies [13ea342]
22
+ - @open-pioneer/map@0.4.0
@@ -0,0 +1,18 @@
1
+ import { MapModel, MapRegistry } from "@open-pioneer/map";
2
+ import { EditingService } from "./api";
3
+ import { EditingWorkflowImpl } from "./EditingWorkflowImpl";
4
+ import { ServiceOptions } from "@open-pioneer/runtime";
5
+ import { HttpService } from "@open-pioneer/http";
6
+ export interface References {
7
+ mapRegistry: MapRegistry;
8
+ httpService: HttpService;
9
+ }
10
+ export declare class EditingServiceImpl implements EditingService {
11
+ private _serviceOptions;
12
+ private _workflows;
13
+ constructor(serviceOptions: ServiceOptions<References>);
14
+ start(map: MapModel, ogcApiFeatureLayerUrl: URL): EditingWorkflowImpl;
15
+ stop(mapId: string): Error | void;
16
+ reset(mapId: string): Error | void;
17
+ _connectToWorkflowComplete(workflow: EditingWorkflowImpl, mapId: string): void;
18
+ }
@@ -0,0 +1,56 @@
1
+ import { EditingWorkflowImpl } from './EditingWorkflowImpl.js';
2
+
3
+ class EditingServiceImpl {
4
+ _serviceOptions;
5
+ _workflows;
6
+ constructor(serviceOptions) {
7
+ this._serviceOptions = serviceOptions;
8
+ this._workflows = /* @__PURE__ */ new Map();
9
+ }
10
+ start(map, ogcApiFeatureLayerUrl) {
11
+ if (!ogcApiFeatureLayerUrl || !map || !map.id) {
12
+ throw new Error("Map, mapId or url is undefined.");
13
+ }
14
+ const mapId = map.id;
15
+ let workflow = this._workflows.get(mapId);
16
+ if (workflow) {
17
+ throw new Error(
18
+ "EditingWorkflow could not be started. EditingWorkflow already in progress for this map."
19
+ );
20
+ }
21
+ workflow = new EditingWorkflowImpl({
22
+ map,
23
+ ogcApiFeatureLayerUrl,
24
+ polygonDrawStyle: this._serviceOptions.properties.polygonDrawStyle,
25
+ httpService: this._serviceOptions.references.httpService,
26
+ intl: this._serviceOptions.intl
27
+ });
28
+ this._workflows.set(mapId, workflow);
29
+ this._connectToWorkflowComplete(workflow, mapId);
30
+ return workflow;
31
+ }
32
+ stop(mapId) {
33
+ const workflow = this._workflows.get(mapId);
34
+ if (workflow) {
35
+ workflow.stop();
36
+ } else {
37
+ return new Error("No workflow found for mapId: " + mapId);
38
+ }
39
+ }
40
+ reset(mapId) {
41
+ const workflow = this._workflows.get(mapId);
42
+ if (workflow) {
43
+ workflow.reset();
44
+ } else {
45
+ return new Error("No workflow found for mapId: " + mapId);
46
+ }
47
+ }
48
+ _connectToWorkflowComplete(workflow, mapId) {
49
+ workflow.whenComplete().finally(() => {
50
+ this._workflows.delete(mapId);
51
+ });
52
+ }
53
+ }
54
+
55
+ export { EditingServiceImpl };
56
+ //# sourceMappingURL=EditingServiceImpl.js.map
@@ -0,0 +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 { EditingWorkflowImpl } from \"./EditingWorkflowImpl\";\nimport { FlatStyleLike } from \"ol/style/flat\";\nimport { ServiceOptions } from \"@open-pioneer/runtime\";\nimport { HttpService } from \"@open-pioneer/http\";\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, EditingWorkflowImpl>;\n\n constructor(serviceOptions: ServiceOptions<References>) {\n this._serviceOptions = serviceOptions;\n this._workflows = new Map();\n }\n\n start(map: MapModel, ogcApiFeatureLayerUrl: URL): EditingWorkflowImpl {\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 EditingWorkflowImpl({\n map,\n ogcApiFeatureLayerUrl,\n polygonDrawStyle: this._serviceOptions.properties.polygonDrawStyle as FlatStyleLike,\n httpService: this._serviceOptions.references.httpService,\n intl: this._serviceOptions.intl\n });\n this._workflows.set(mapId, workflow);\n this._connectToWorkflowComplete(workflow, mapId);\n\n return workflow;\n }\n\n stop(mapId: string): Error | void {\n const workflow = this._workflows.get(mapId);\n if (workflow) {\n workflow.stop();\n } else {\n return new Error(\"No workflow found for mapId: \" + mapId);\n }\n }\n\n reset(mapId: string): Error | void {\n const workflow = this._workflows.get(mapId);\n if (workflow) {\n workflow.reset();\n } else {\n return new Error(\"No workflow found for mapId: \" + mapId);\n }\n }\n\n _connectToWorkflowComplete(workflow: EditingWorkflowImpl, mapId: string) {\n workflow.whenComplete().finally(() => {\n this._workflows.delete(mapId);\n });\n }\n}\n"],"names":[],"mappings":";;AAcO,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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EAAA;AAC/B,IAAA,MAAM,QAAW,GAAA,IAAA,CAAK,UAAW,CAAA,GAAA,CAAI,KAAK,CAAA,CAAA;AAC1C,IAAA,IAAI,QAAU,EAAA;AACV,MAAA,QAAA,CAAS,KAAM,EAAA,CAAA;AAAA,KACZ,MAAA;AACH,MAAO,OAAA,IAAI,KAAM,CAAA,+BAAA,GAAkC,KAAK,CAAA,CAAA;AAAA,KAC5D;AAAA,GACJ;AAAA,EAEA,0BAAA,CAA2B,UAA+B,KAAe,EAAA;AACrE,IAAS,QAAA,CAAA,YAAA,EAAe,CAAA,OAAA,CAAQ,MAAM;AAClC,MAAK,IAAA,CAAA,UAAA,CAAW,OAAO,KAAK,CAAA,CAAA;AAAA,KAC/B,CAAA,CAAA;AAAA,GACL;AACJ;;;;"}
@@ -0,0 +1,44 @@
1
+ import { EventEmitter } from "@open-pioneer/core";
2
+ import { MapModel } from "@open-pioneer/map";
3
+ import { Draw } from "ol/interaction";
4
+ import { HttpService } from "@open-pioneer/http";
5
+ import { PackageIntl } from "@open-pioneer/runtime";
6
+ import { FlatStyleLike } from "ol/style/flat";
7
+ import { EditingWorkflowEvents, EditingWorkflowState, EditingWorkflow } from "./api";
8
+ interface EditingWorkflowProps {
9
+ map: MapModel;
10
+ ogcApiFeatureLayerUrl: URL;
11
+ polygonDrawStyle: FlatStyleLike;
12
+ httpService: HttpService;
13
+ intl: PackageIntl;
14
+ }
15
+ export declare class EditingWorkflowImpl extends EventEmitter<EditingWorkflowEvents> implements EditingWorkflow {
16
+ #private;
17
+ private _httpService;
18
+ private _intl;
19
+ private _map;
20
+ private _polygonDrawStyle;
21
+ private _state;
22
+ private _editLayerURL;
23
+ private _drawSource;
24
+ private _drawLayer;
25
+ private _drawInteraction;
26
+ private _olMap;
27
+ private _mapContainer;
28
+ private _tooltip;
29
+ private _enterHandler;
30
+ private _escapeHandler;
31
+ private _interactionListener;
32
+ private _mapListener;
33
+ constructor(options: EditingWorkflowProps);
34
+ getDrawInteraction(): Draw;
35
+ getState(): EditingWorkflowState;
36
+ private _setState;
37
+ private _start;
38
+ reset(): void;
39
+ stop(): void;
40
+ private _destroy;
41
+ whenComplete(): Promise<string | undefined>;
42
+ private _createTooltip;
43
+ }
44
+ export {};
@@ -0,0 +1,187 @@
1
+ import { EventEmitter, createManualPromise } from '@open-pioneer/core';
2
+ import { TOPMOST_LAYER_Z } from '@open-pioneer/map';
3
+ import { Draw } from 'ol/interaction';
4
+ import VectorLayer from 'ol/layer/Vector';
5
+ import VectorSource from 'ol/source/Vector';
6
+ import GeoJSON from 'ol/format/GeoJSON';
7
+ import { saveCreatedFeature } from './SaveFeaturesHandler.js';
8
+ import Overlay from 'ol/Overlay';
9
+ import { unByKey } from 'ol/Observable';
10
+
11
+ class EditingWorkflowImpl extends EventEmitter {
12
+ #waiter;
13
+ _httpService;
14
+ _intl;
15
+ _map;
16
+ _polygonDrawStyle;
17
+ _state;
18
+ _editLayerURL;
19
+ _drawSource;
20
+ _drawLayer;
21
+ _drawInteraction;
22
+ _olMap;
23
+ _mapContainer;
24
+ _tooltip;
25
+ _enterHandler;
26
+ _escapeHandler;
27
+ _interactionListener;
28
+ _mapListener;
29
+ constructor(options) {
30
+ super();
31
+ this._httpService = options.httpService;
32
+ this._intl = options.intl;
33
+ this._polygonDrawStyle = options.polygonDrawStyle;
34
+ this._map = options.map;
35
+ this._olMap = options.map.olMap;
36
+ this._state = "active:initialized";
37
+ this._editLayerURL = options.ogcApiFeatureLayerUrl;
38
+ this._drawSource = new VectorSource();
39
+ this._drawLayer = new VectorLayer({
40
+ source: this._drawSource,
41
+ zIndex: TOPMOST_LAYER_Z,
42
+ properties: {
43
+ name: "editing-layer"
44
+ }
45
+ });
46
+ this._drawInteraction = new Draw({
47
+ source: this._drawSource,
48
+ type: "Polygon",
49
+ style: this._polygonDrawStyle
50
+ });
51
+ this._tooltip = this._createTooltip(this._olMap);
52
+ this._enterHandler = (e) => {
53
+ if (e.code === "Enter" && e.target === this._olMap.getTargetElement()) {
54
+ const features = this._drawInteraction.getOverlay().getSource().getFeatures();
55
+ if (features[0] && features[0].getGeometry().getCoordinates()[0].length > 4) {
56
+ this._drawInteraction.finishDrawing();
57
+ }
58
+ }
59
+ };
60
+ this._escapeHandler = (e) => {
61
+ if (e.code === "Escape" && e.target === this._olMap.getTargetElement()) {
62
+ this.reset();
63
+ }
64
+ };
65
+ this._interactionListener = [];
66
+ this._mapListener = [];
67
+ this._start();
68
+ }
69
+ getDrawInteraction() {
70
+ return this._drawInteraction;
71
+ }
72
+ getState() {
73
+ return this._state;
74
+ }
75
+ _setState(state) {
76
+ this._state = state;
77
+ this.emit(state);
78
+ }
79
+ _start() {
80
+ this._olMap.addLayer(this._drawLayer);
81
+ this._olMap.addInteraction(this._drawInteraction);
82
+ this._mapContainer = this._olMap.getTargetElement() ?? void 0;
83
+ if (this._mapContainer) {
84
+ this._mapContainer.addEventListener("keydown", this._enterHandler, false);
85
+ this._mapContainer.addEventListener("keydown", this._escapeHandler, false);
86
+ }
87
+ this._tooltip.element.classList.remove("editing-tooltip-hidden");
88
+ const drawStart = this._drawInteraction.on("drawstart", () => {
89
+ this._setState("active:drawing");
90
+ this._tooltip.element.textContent = this._intl.formatMessage({
91
+ id: "tooltip.continue"
92
+ });
93
+ });
94
+ const drawEnd = this._drawInteraction.on("drawend", (e) => {
95
+ this._setState("active:saving");
96
+ const layerUrl = this._editLayerURL;
97
+ const geometry = e.feature.getGeometry();
98
+ if (!geometry) {
99
+ this._destroy();
100
+ this.#waiter?.reject(new Error("no geometry available"));
101
+ return;
102
+ }
103
+ const projection = this._olMap.getView().getProjection();
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
+ });
119
+ });
120
+ const changedContainer = this._map.on("changed:container", () => {
121
+ this._mapContainer?.removeEventListener("keydown", this._enterHandler);
122
+ this._mapContainer?.removeEventListener("keydown", this._escapeHandler);
123
+ this._mapContainer = this._olMap.getTargetElement() ?? void 0;
124
+ if (this._mapContainer) {
125
+ this._mapContainer.addEventListener("keydown", this._enterHandler, false);
126
+ this._mapContainer.addEventListener("keydown", this._escapeHandler, false);
127
+ }
128
+ });
129
+ this._interactionListener.push(drawStart, drawEnd);
130
+ this._mapListener.push(changedContainer);
131
+ }
132
+ reset() {
133
+ this._drawInteraction.abortDrawing();
134
+ this._tooltip.element.textContent = this._intl.formatMessage({ id: "tooltip.begin" });
135
+ this._setState("active:initialized");
136
+ }
137
+ stop() {
138
+ this._destroy();
139
+ this.#waiter?.resolve(void 0);
140
+ }
141
+ _destroy() {
142
+ this._olMap.removeLayer(this._drawLayer);
143
+ this._olMap.removeInteraction(this._drawInteraction);
144
+ this._tooltip.destroy();
145
+ this._interactionListener.map((listener) => {
146
+ unByKey(listener);
147
+ });
148
+ this._mapListener.map((listener) => {
149
+ listener.destroy();
150
+ });
151
+ this._mapContainer?.removeEventListener("keydown", this._enterHandler);
152
+ this._mapContainer?.removeEventListener("keydown", this._escapeHandler);
153
+ this._state = "inactive";
154
+ }
155
+ whenComplete() {
156
+ const manualPromise = this.#waiter ??= createManualPromise();
157
+ return manualPromise.promise;
158
+ }
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
+ }
185
+
186
+ export { EditingWorkflowImpl };
187
+ //# sourceMappingURL=EditingWorkflowImpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EditingWorkflowImpl.js","sources":["EditingWorkflowImpl.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { EventEmitter, ManualPromise, createManualPromise } from \"@open-pioneer/core\";\nimport { MapModel, TOPMOST_LAYER_Z } from \"@open-pioneer/map\";\nimport { Draw } from \"ol/interaction\";\nimport VectorLayer from \"ol/layer/Vector\";\nimport VectorSource from \"ol/source/Vector\";\nimport { HttpService } from \"@open-pioneer/http\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { FlatStyleLike } from \"ol/style/flat\";\nimport GeoJSON from \"ol/format/GeoJSON\";\nimport GeoJSONGeometry from \"ol/format/GeoJSON\";\nimport GeoJSONGeometryCollection from \"ol/format/GeoJSON\";\nimport { saveCreatedFeature } from \"./SaveFeaturesHandler\";\nimport OlMap from \"ol/Map\";\nimport Overlay from \"ol/Overlay\";\nimport { Resource } from \"@open-pioneer/core\";\nimport { unByKey } from \"ol/Observable\";\nimport { EventsKey } from \"ol/events\";\nimport { EditingWorkflowEvents, EditingWorkflowState, EditingWorkflow } from \"./api\";\n\n// Represents a tooltip rendered on the OpenLayers map\ninterface Tooltip extends Resource {\n overlay: Overlay;\n element: HTMLDivElement;\n}\n\ninterface EditingWorkflowProps {\n map: MapModel;\n ogcApiFeatureLayerUrl: URL;\n polygonDrawStyle: FlatStyleLike;\n httpService: HttpService;\n intl: PackageIntl;\n}\n\nexport class EditingWorkflowImpl\n extends EventEmitter<EditingWorkflowEvents>\n implements EditingWorkflow\n{\n #waiter: ManualPromise<string | undefined> | undefined;\n\n private _httpService: HttpService;\n private _intl: PackageIntl;\n\n private _map: MapModel;\n private _polygonDrawStyle: FlatStyleLike;\n private _state: EditingWorkflowState;\n private _editLayerURL: URL;\n\n private _drawSource: VectorSource;\n private _drawLayer: 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 _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._polygonDrawStyle = options.polygonDrawStyle;\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._drawSource = new VectorSource();\n this._drawLayer = new VectorLayer({\n source: this._drawSource,\n zIndex: TOPMOST_LAYER_Z,\n properties: {\n name: \"editing-layer\"\n }\n });\n\n this._drawInteraction = new Draw({\n source: this._drawSource,\n type: \"Polygon\",\n style: this._polygonDrawStyle\n });\n\n this._tooltip = this._createTooltip(this._olMap);\n\n this._enterHandler = (e: KeyboardEvent) => {\n if (e.code === \"Enter\" && e.target === this._olMap.getTargetElement()) {\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._drawInteraction.finishDrawing();\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 _start() {\n this._olMap.addLayer(this._drawLayer);\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.element.classList.remove(\"editing-tooltip-hidden\");\n\n const drawStart = this._drawInteraction.on(\"drawstart\", () => {\n this._setState(\"active:drawing\");\n this._tooltip.element.textContent = this._intl.formatMessage({\n id: \"tooltip.continue\"\n });\n });\n\n const drawEnd = this._drawInteraction.on(\"drawend\", (e) => {\n this._setState(\"active:saving\");\n\n const layerUrl = this._editLayerURL;\n\n const geometry = e.feature.getGeometry();\n if (!geometry) {\n this._destroy();\n this.#waiter?.reject(new Error(\"no geometry available\"));\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 saveCreatedFeature(this._httpService, layerUrl, geoJSONGeometry, projection)\n .then((featureId) => {\n this._destroy();\n this.#waiter?.resolve(featureId);\n })\n .catch((err: Error) => {\n console.log(err);\n this._destroy();\n this.#waiter?.reject(err);\n });\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.element.textContent = this._intl.formatMessage({ id: \"tooltip.begin\" });\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._drawLayer);\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._state = \"inactive\";\n }\n\n whenComplete(): Promise<string | undefined> {\n const manualPromise = (this.#waiter ??= createManualPromise());\n return manualPromise.promise;\n }\n\n private _createTooltip(olMap: OlMap): Tooltip {\n const element = document.createElement(\"div\");\n element.className = \"editing-tooltip editing-tooltip-hidden\";\n element.textContent = this._intl.formatMessage({ id: \"tooltip.begin\" });\n\n const overlay = new Overlay({\n element: element,\n offset: [15, 0],\n positioning: \"center-left\"\n });\n\n const pointerMove = olMap.on(\"pointermove\", (evt) => {\n if (evt.dragging) {\n return;\n }\n\n overlay.setPosition(evt.coordinate);\n });\n\n olMap.addOverlay(overlay);\n\n return {\n overlay,\n element,\n destroy() {\n unByKey(pointerMove);\n olMap.removeOverlay(overlay);\n }\n };\n }\n}\n"],"names":[],"mappings":";;;;;;;;;;AAmCO,MAAM,4BACD,YAEZ,CAAA;AAAA,EACI,OAAA,CAAA;AAAA,EAEQ,YAAA,CAAA;AAAA,EACA,KAAA,CAAA;AAAA,EAEA,IAAA,CAAA;AAAA,EACA,iBAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,aAAA,CAAA;AAAA,EAEA,WAAA,CAAA;AAAA,EACA,UAAA,CAAA;AAAA,EACA,gBAAA,CAAA;AAAA,EACA,MAAA,CAAA;AAAA,EACA,aAA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ACA,OAAU,GAAA;AACN,QAAA,OAAA,CAAQ,WAAW,CAAA,CAAA;AACnB,QAAA,KAAA,CAAM,cAAc,OAAO,CAAA,CAAA;AAAA,OAC/B;AAAA,KACJ,CAAA;AAAA,GACJ;AACJ;;;;"}
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # @open-pioneer/editing
2
+
3
+ This package provides an editing service that allows to start and handle geometry editing workflows.
4
+
5
+ Note: The editing only works with OGC API Feature Services. The editing was only tested using the implementation of the OGC API Features in the XtraServer by interactive instruments. The collection where the geometry will be saved, needs to support the map's coordinate system.
6
+
7
+ ## Usage
8
+
9
+ To use the editing in an app, inject the editing service. Use the `start` method to create a new editing workflow.
10
+
11
+ Example:
12
+
13
+ ```js
14
+ // build.config.mjs
15
+ import { defineBuildConfig } from "@open-pioneer/build-support";
16
+
17
+ export default defineBuildConfig({
18
+ ui: {
19
+ references: ["editing.EditingService"]
20
+ }
21
+ });
22
+ ```
23
+
24
+ ```tsx
25
+ const editingService = useService<EditingService>("editing.EditingService");
26
+ const editingCollectionUrl = new URL("...");
27
+ const workflow = editingService.start(map, editingCollectionUrl);
28
+ ```
29
+
30
+ An editing workflow can be stopped completely or the current drawing can be deleted without leaving the edit mode.
31
+
32
+ Example:
33
+
34
+ ```js
35
+ editingService.reset("mapId");
36
+ editingService.stop("mapId");
37
+ ```
38
+
39
+ ### Watch editing workflow states
40
+
41
+ During an editing workflow different states can occur. Retrieve the current state by calling `getState` method on the workflow.
42
+
43
+ Alternatively, the state can be watched using `on()`.
44
+
45
+ Example:
46
+
47
+ ```js
48
+ workflow.on("active:drawing", () => {
49
+ // ....
50
+ });
51
+ ```
52
+
53
+ ### Finish editing workflow
54
+
55
+ After the editing is finished, a `Promise` will be returned.
56
+
57
+ - The returned promise rejects if saving the feature failed.
58
+ - The promise resolves with `undefined` when the editing was stopped.
59
+ - The promise resolves with the feature ID when saving was successful.
60
+
61
+ Example:
62
+
63
+ ```js
64
+ workflow
65
+ .whenComplete()
66
+ .then((featureId: string | undefined) => {
67
+ // ...
68
+ })
69
+ .catch((error: Error) => {
70
+ console.log(error);
71
+ });
72
+ ```
73
+
74
+ After the editing was successful, the map must be refreshed manually by refreshing the OpenLayers layer instance.
75
+
76
+ Example:
77
+
78
+ ```ts
79
+ const layer = map.layers.getLayerById("") as Layer;
80
+ const vectorLayer = layer?.olLayer as VectorLayer<VectorSource>;
81
+ vectorLayer.getSource()?.refresh();
82
+ ```
83
+
84
+ ### Custom styling
85
+
86
+ The default style of the geometries can be overridden with a custom style.
87
+
88
+ Each geometry type has its own styling property (currently only `polygonDrawStyle`). See OpenLayers [`FlatStyleLike`](https://openlayers.org/en/latest/apidoc/module-ol_style_flat.html) for valid styling options.
89
+
90
+ ```js
91
+ const element = createCustomElement({
92
+ ...,
93
+ config: {
94
+ properties: {
95
+ "@open-pioneer/editing": {
96
+ "polygonDrawStyle": {
97
+ "stroke-color": "red",
98
+ "stroke-width": 2,
99
+ "fill-color": "rgba(0, 0, 0, 0.1)",
100
+ "circle-radius": 5,
101
+ "circle-fill-color": "rgba(255, 0, 0, 0.2)",
102
+ "circle-stroke-color": "rgba(255, 0, 0, 0.7)",
103
+ "circle-stroke-width": 2
104
+ }
105
+ }
106
+ }
107
+ },
108
+ ...
109
+ });
110
+
111
+ customElements.define("ol-map-app", element);
112
+ ```
113
+
114
+ ## License
115
+
116
+ Apache-2.0 (see `LICENSE` file)
@@ -0,0 +1,5 @@
1
+ import { HttpService } from "@open-pioneer/http";
2
+ import GeoJSONGeometry from "ol/format/GeoJSON";
3
+ import GeoJSONGeometryCollection from "ol/format/GeoJSON";
4
+ import { Projection } from "ol/proj";
5
+ export declare function saveCreatedFeature(httpService: HttpService, url: URL, geometry: GeoJSONGeometry | GeoJSONGeometryCollection, projection: Projection): Promise<string>;
@@ -0,0 +1,24 @@
1
+ async function saveCreatedFeature(httpService, url, geometry, projection) {
2
+ const epsgCode = projection.getCode();
3
+ const crs = epsgCode.replace("EPSG:", "http://www.opengis.net/def/crs/EPSG/0/");
4
+ const response = await httpService.fetch(url, {
5
+ method: "POST",
6
+ body: JSON.stringify({ type: "Feature", properties: {}, geometry }),
7
+ headers: {
8
+ "Content-Type": "application/geo+json; charset=utf-8",
9
+ "Content-Crs": `<${crs}>`
10
+ }
11
+ });
12
+ if (!response || !response.ok || response.status !== 201) {
13
+ return Promise.reject(new Error("Request failed: " + response.status));
14
+ }
15
+ const location = response.headers.get("location");
16
+ if (!location) {
17
+ return Promise.reject(new Error("Request failed: no Location response header"));
18
+ }
19
+ const featureId = location.substring(location.lastIndexOf("/") + 1);
20
+ return Promise.resolve(featureId);
21
+ }
22
+
23
+ export { saveCreatedFeature };
24
+ //# sourceMappingURL=SaveFeaturesHandler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SaveFeaturesHandler.js","sources":["SaveFeaturesHandler.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { HttpService } from \"@open-pioneer/http\";\nimport GeoJSONGeometry from \"ol/format/GeoJSON\";\nimport GeoJSONGeometryCollection from \"ol/format/GeoJSON\";\nimport { Projection } from \"ol/proj\";\n\nexport async function saveCreatedFeature(\n httpService: HttpService,\n url: URL,\n geometry: GeoJSONGeometry | GeoJSONGeometryCollection,\n projection: Projection\n) {\n const epsgCode = projection.getCode();\n const crs = epsgCode.replace(\"EPSG:\", \"http://www.opengis.net/def/crs/EPSG/0/\");\n const response = await httpService.fetch(url, {\n method: \"POST\",\n body: JSON.stringify({ type: \"Feature\", properties: {}, geometry: geometry }),\n headers: {\n \"Content-Type\": \"application/geo+json; charset=utf-8\",\n \"Content-Crs\": `<${crs}>`\n }\n });\n\n if (!response || !response.ok || response.status !== 201) {\n return Promise.reject(new Error(\"Request failed: \" + response.status));\n }\n\n const location = response.headers.get(\"location\");\n if (!location) {\n return Promise.reject(new Error(\"Request failed: no Location response header\"));\n }\n\n const featureId = location.substring(location.lastIndexOf(\"/\") + 1);\n\n return Promise.resolve(featureId);\n}\n"],"names":[],"mappings":"AAQA,eAAsB,kBAClB,CAAA,WAAA,EACA,GACA,EAAA,QAAA,EACA,UACF,EAAA;AACE,EAAM,MAAA,QAAA,GAAW,WAAW,OAAQ,EAAA,CAAA;AACpC,EAAA,MAAM,GAAM,GAAA,QAAA,CAAS,OAAQ,CAAA,OAAA,EAAS,wCAAwC,CAAA,CAAA;AAC9E,EAAA,MAAM,QAAW,GAAA,MAAM,WAAY,CAAA,KAAA,CAAM,GAAK,EAAA;AAAA,IAC1C,MAAQ,EAAA,MAAA;AAAA,IACR,IAAA,EAAM,IAAK,CAAA,SAAA,CAAU,EAAE,IAAA,EAAM,WAAW,UAAY,EAAA,EAAI,EAAA,QAAA,EAAoB,CAAA;AAAA,IAC5E,OAAS,EAAA;AAAA,MACL,cAAgB,EAAA,qCAAA;AAAA,MAChB,aAAA,EAAe,IAAI,GAAG,CAAA,CAAA,CAAA;AAAA,KAC1B;AAAA,GACH,CAAA,CAAA;AAED,EAAA,IAAI,CAAC,QAAY,IAAA,CAAC,SAAS,EAAM,IAAA,QAAA,CAAS,WAAW,GAAK,EAAA;AACtD,IAAA,OAAO,QAAQ,MAAO,CAAA,IAAI,MAAM,kBAAqB,GAAA,QAAA,CAAS,MAAM,CAAC,CAAA,CAAA;AAAA,GACzE;AAEA,EAAA,MAAM,QAAW,GAAA,QAAA,CAAS,OAAQ,CAAA,GAAA,CAAI,UAAU,CAAA,CAAA;AAChD,EAAA,IAAI,CAAC,QAAU,EAAA;AACX,IAAA,OAAO,OAAQ,CAAA,MAAA,CAAO,IAAI,KAAA,CAAM,6CAA6C,CAAC,CAAA,CAAA;AAAA,GAClF;AAEA,EAAA,MAAM,YAAY,QAAS,CAAA,SAAA,CAAU,SAAS,WAAY,CAAA,GAAG,IAAI,CAAC,CAAA,CAAA;AAElE,EAAO,OAAA,OAAA,CAAQ,QAAQ,SAAS,CAAA,CAAA;AACpC;;;;"}
package/api.d.ts ADDED
@@ -0,0 +1,61 @@
1
+ import { EventEmitter } from "@open-pioneer/core";
2
+ import { MapModel } from "@open-pioneer/map";
3
+ import type { DeclaredService } from "@open-pioneer/runtime";
4
+ /**
5
+ * State of an editing workflow
6
+ */
7
+ export type EditingWorkflowState = "active:initialized" | "active:drawing" | "active:saving" | "inactive";
8
+ /** Events emitted by the {@link EditingWorkflow}. */
9
+ export interface EditingWorkflowEvents {
10
+ /**
11
+ * Initial state after editing workflow was started but user has not yet started drawing.
12
+ */
13
+ "active:initialized": void;
14
+ /**
15
+ * State while user is drawing a feature. State is entered when user adds the first vertex of the geometry.
16
+ */
17
+ "active:drawing": void;
18
+ /**
19
+ * State while feature is being saved after user finished the geometry drawing.
20
+ */
21
+ "active:saving": void;
22
+ /**
23
+ * State after editing is stopped.
24
+ */
25
+ "inactive": void;
26
+ }
27
+ /**
28
+ * EditingWorkflows are created by the {@link EditingService}
29
+ * and represent a currently ongoing editing workflow.
30
+ */
31
+ export interface EditingWorkflow extends EventEmitter<EditingWorkflowEvents> {
32
+ /**
33
+ * Returns the current state of the editing workflow.
34
+ */
35
+ getState(): EditingWorkflowState;
36
+ /**
37
+ * Wait for the editing to be finished. The returned promise resolves with the
38
+ * feature ID when saving was successful and rejects if saving the feature
39
+ * failed. It resolves with undefined when the editing was stopped.
40
+ */
41
+ whenComplete(): Promise<string | undefined>;
42
+ }
43
+ /**
44
+ * The editing service allows to start and handle editing workflows.
45
+ *
46
+ * Inject an instance of this service by referencing the interface name `"editing.EditingService"`.
47
+ */
48
+ export interface EditingService extends DeclaredService<"editing.EditingService"> {
49
+ /**
50
+ * Creates and initializes a new {@link EditingWorkflow}.
51
+ */
52
+ start(map: MapModel, ogcApiFeatureLayerUrl: URL): EditingWorkflow;
53
+ /**
54
+ * Stops the edit mode and removes an existing {@link EditingWorkflow}.
55
+ */
56
+ stop(mapId: string): void;
57
+ /**
58
+ * Removes the unfinished geometry from an existing {@link EditingWorkflow} without leaving the edit mode.
59
+ */
60
+ reset(mapId: string): void;
61
+ }
package/editing.css ADDED
@@ -0,0 +1,19 @@
1
+ .editing-tooltip {
2
+ position: relative;
3
+ background: rgba(255, 255, 255, 0.8);
4
+ border-radius: 4px;
5
+ color: black;
6
+ padding: 4px 8px;
7
+ opacity: 1;
8
+ white-space: nowrap;
9
+ font-size: 12px;
10
+ cursor: default;
11
+ user-select: none;
12
+ font-weight: bold;
13
+ }
14
+
15
+ .editing-tooltip-hidden {
16
+ visibility: hidden;
17
+ }
18
+
19
+ /*# sourceMappingURL=editing.css.map */
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["editing.css"],"names":[],"mappings":"AAAA;IACI,kBAAkB;IAClB,oCAAoC;IACpC,kBAAkB;IAClB,YAAY;IACZ,gBAAgB;IAChB,UAAU;IACV,mBAAmB;IACnB,eAAe;IACf,eAAe;IACf,iBAAiB;IACjB,iBAAiB;AACrB;;AAEA;IACI,kBAAkB;AACtB","file":"editing.css","sourcesContent":[".editing-tooltip {\n position: relative;\n background: rgba(255, 255, 255, 0.8);\n border-radius: 4px;\n color: black;\n padding: 4px 8px;\n opacity: 1;\n white-space: nowrap;\n font-size: 12px;\n cursor: default;\n user-select: none;\n font-weight: bold;\n}\n\n.editing-tooltip-hidden {\n visibility: hidden;\n}\n"]}
package/i18n/de.yaml ADDED
@@ -0,0 +1,5 @@
1
+ messages:
2
+ title: Editierung von Objekten
3
+ tooltip:
4
+ begin: Klicken, um mit Erstellung der Geometrie zu beginnen
5
+ continue: Doppelt klicken, um Geometrie abzuschließen und Feature zu speichern
package/i18n/en.yaml ADDED
@@ -0,0 +1,5 @@
1
+ messages:
2
+ title: Editing
3
+ tooltip:
4
+ begin: Click to start creating the geometry
5
+ continue: Double click to finish the geometry and save the feature
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { type EditingWorkflowState, type EditingWorkflow, type EditingService } from "./api";
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@open-pioneer/editing",
4
+ "version": "0.1.0",
5
+ "description": "This package provides an editing service that allows to start and handle geometry editing workflows.",
6
+ "keywords": [
7
+ "open-pioneer-trails"
8
+ ],
9
+ "homepage": "https://github.com/open-pioneer",
10
+ "license": "Apache-2.0",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/open-pioneer/trails-openlayers-base-packages",
14
+ "directory": "src/packages/editing"
15
+ },
16
+ "peerDependencies": {
17
+ "@open-pioneer/core": "^1.2.1",
18
+ "@open-pioneer/http": "^2.1.4",
19
+ "@open-pioneer/runtime": "^2.1.2",
20
+ "ol": "^9.0.0",
21
+ "@open-pioneer/map": "^0.4.0"
22
+ },
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "import": "./index.js",
27
+ "types": "./index.d.ts"
28
+ },
29
+ "./services": {
30
+ "import": "./services.js",
31
+ "types": "./services.d.ts"
32
+ },
33
+ "./editing.css": "./editing.css"
34
+ },
35
+ "openPioneerFramework": {
36
+ "styles": "./editing.css",
37
+ "services": [
38
+ {
39
+ "serviceName": "EditingServiceImpl",
40
+ "provides": [
41
+ {
42
+ "interfaceName": "editing.EditingService"
43
+ }
44
+ ],
45
+ "references": [
46
+ {
47
+ "referenceName": "mapRegistry",
48
+ "type": "unique",
49
+ "interfaceName": "map.MapRegistry"
50
+ },
51
+ {
52
+ "referenceName": "httpService",
53
+ "type": "unique",
54
+ "interfaceName": "http.HttpService"
55
+ }
56
+ ]
57
+ }
58
+ ],
59
+ "servicesModule": "./services",
60
+ "i18n": {
61
+ "languages": [
62
+ "en",
63
+ "de"
64
+ ]
65
+ },
66
+ "ui": {
67
+ "references": []
68
+ },
69
+ "properties": [
70
+ {
71
+ "propertyName": "polygonDrawStyle",
72
+ "defaultValue": {
73
+ "stroke-color": "yellow",
74
+ "stroke-width": 2,
75
+ "fill-color": "rgba(0, 0, 0, 0.1)",
76
+ "circle-radius": 5,
77
+ "circle-fill-color": "rgba(0, 0, 255, 0.2)",
78
+ "circle-stroke-color": "rgba(0, 0, 255, 0.7)",
79
+ "circle-stroke-width": 2
80
+ },
81
+ "required": false
82
+ }
83
+ ],
84
+ "packageFormatVersion": "1.0.0"
85
+ }
86
+ }
package/services.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { EditingServiceImpl } from "./EditingServiceImpl";
package/services.js ADDED
@@ -0,0 +1,2 @@
1
+ export { EditingServiceImpl } from './EditingServiceImpl.js';
2
+ //# sourceMappingURL=services.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"services.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}