@open-pioneer/selection 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,20 @@
1
+ # @open-pioneer/selection
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ee7c2d4: Update runtime version.
8
+ - 61d3e0e: Initial release.
9
+ - 0456500: Add interface `BaseFeature` to Map API.
10
+ - 35be8ef: Introduction of `SelectionSourceFactory` for creating selection sources of an OpenLayers VectorLayer.
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [ee7c2d4]
15
+ - Updated dependencies [a582e5e]
16
+ - Updated dependencies [0456500]
17
+ - Updated dependencies [762e7b9]
18
+ - @open-pioneer/map@0.3.0
19
+ - @open-pioneer/notifier@0.3.0
20
+ - @open-pioneer/react-utils@0.2.1
@@ -0,0 +1,45 @@
1
+ import { Resource } from "@open-pioneer/core/resources";
2
+ import OlMap from "ol/Map";
3
+ import Geometry from "ol/geom/Geometry";
4
+ import PointerInteraction from "ol/interaction/Pointer";
5
+ interface InteractionResource extends Resource {
6
+ interaction: PointerInteraction;
7
+ }
8
+ export declare class DragController {
9
+ private tooltip;
10
+ private interactionResources;
11
+ private olMap;
12
+ private isActive;
13
+ private tooltipMessage;
14
+ private tooltipDisabledMessage;
15
+ constructor(olMap: OlMap, selectMethode: string, tooltipMessage: string, tooltipDisabledMessage: string, onExtentSelected: (geometry: Geometry) => void);
16
+ initViewport(olMap: OlMap): HTMLElement;
17
+ /**
18
+ * Method for destroying the controller when it is no longer needed
19
+ */
20
+ destroy(): void;
21
+ setActive(isActive: boolean): void;
22
+ /**
23
+ * Method to create a simple extent-selection
24
+ */
25
+ private createDragBox;
26
+ /**
27
+ * Method to activate pan with right-mouse-click
28
+ */
29
+ private createDrag;
30
+ /**
31
+ * Method to generate a tooltip on the mouse cursor
32
+ */
33
+ private createHelpTooltip;
34
+ /**
35
+ * Method for testing purposes only
36
+ * @returns InteractionResource of class DragBox
37
+ */
38
+ getDragboxInteraction(): InteractionResource | undefined;
39
+ /**
40
+ * Method for testing purposes only
41
+ * @returns InteractionResource of class DragPan
42
+ */
43
+ getDragPanInteraction(): InteractionResource | undefined;
44
+ }
45
+ export {};
@@ -0,0 +1,175 @@
1
+ import { unByKey } from 'ol/Observable';
2
+ import Overlay from 'ol/Overlay';
3
+ import { mouseActionButton } from 'ol/events/condition';
4
+ import { SelectionMethods } from './Selection.js';
5
+ import { DragBox, DragPan } from 'ol/interaction';
6
+
7
+ const ACTIVE_CLASS = "selection-active";
8
+ const INACTIVE_CLASS = "selection-inactive";
9
+ class DragController {
10
+ tooltip;
11
+ interactionResources = [];
12
+ olMap;
13
+ isActive = true;
14
+ tooltipMessage;
15
+ tooltipDisabledMessage;
16
+ constructor(olMap, selectMethode, tooltipMessage, tooltipDisabledMessage, onExtentSelected) {
17
+ let viewPort;
18
+ switch (selectMethode) {
19
+ case SelectionMethods.extent:
20
+ default:
21
+ viewPort = this.initViewport(olMap);
22
+ this.interactionResources.push(
23
+ this.createDragBox(olMap, onExtentSelected, viewPort, this.interactionResources)
24
+ );
25
+ this.interactionResources.push(
26
+ this.createDrag(olMap, viewPort, this.interactionResources)
27
+ );
28
+ break;
29
+ }
30
+ this.tooltip = this.createHelpTooltip(olMap, tooltipMessage);
31
+ this.olMap = olMap;
32
+ this.tooltipMessage = tooltipMessage;
33
+ this.tooltipDisabledMessage = tooltipDisabledMessage;
34
+ }
35
+ initViewport(olMap) {
36
+ const viewPort = olMap.getViewport();
37
+ viewPort.classList.add(ACTIVE_CLASS);
38
+ viewPort.oncontextmenu = (e) => {
39
+ e.preventDefault();
40
+ return false;
41
+ };
42
+ return viewPort;
43
+ }
44
+ /**
45
+ * Method for destroying the controller when it is no longer needed
46
+ */
47
+ destroy() {
48
+ this.tooltip.destroy();
49
+ this.interactionResources.forEach((interaction) => {
50
+ interaction.destroy();
51
+ });
52
+ }
53
+ setActive(isActive) {
54
+ if (this.isActive === isActive)
55
+ return;
56
+ const viewPort = this.olMap.getViewport();
57
+ if (isActive) {
58
+ this.interactionResources.forEach(
59
+ (interaction) => this.olMap.addInteraction(interaction.interaction)
60
+ );
61
+ this.tooltip.element.textContent = this.tooltipMessage;
62
+ viewPort.classList.remove(INACTIVE_CLASS);
63
+ viewPort.classList.add(ACTIVE_CLASS);
64
+ this.isActive = true;
65
+ } else {
66
+ this.interactionResources.forEach(
67
+ (interaction) => this.olMap.removeInteraction(interaction.interaction)
68
+ );
69
+ this.tooltip.element.textContent = this.tooltipDisabledMessage;
70
+ viewPort.classList.remove(ACTIVE_CLASS);
71
+ viewPort.classList.add(INACTIVE_CLASS);
72
+ this.isActive = false;
73
+ }
74
+ }
75
+ /**
76
+ * Method to create a simple extent-selection
77
+ */
78
+ createDragBox(olMap, onExtentSelected, viewPort, interactionResources) {
79
+ const dragBox = new DragBox({
80
+ className: "selection-drag-box",
81
+ condition: mouseActionButton
82
+ });
83
+ olMap.addInteraction(dragBox);
84
+ dragBox.on("boxend", function() {
85
+ onExtentSelected(dragBox.getGeometry());
86
+ });
87
+ const interactionResource = {
88
+ interaction: dragBox,
89
+ destroy() {
90
+ olMap.removeInteraction(dragBox);
91
+ interactionResources.splice(interactionResources.indexOf(this));
92
+ dragBox.dispose();
93
+ viewPort.classList.remove(ACTIVE_CLASS);
94
+ viewPort.classList.remove(INACTIVE_CLASS);
95
+ viewPort.oncontextmenu = null;
96
+ }
97
+ };
98
+ return interactionResource;
99
+ }
100
+ /**
101
+ * Method to activate pan with right-mouse-click
102
+ */
103
+ createDrag(olMap, viewPort, interactionResources) {
104
+ const condition = function(mapBrowserEvent) {
105
+ const originalEvent = (
106
+ /** @type {MouseEvent} */
107
+ mapBrowserEvent.originalEvent
108
+ );
109
+ return originalEvent.button == 2;
110
+ };
111
+ const drag = new DragPan({
112
+ condition
113
+ });
114
+ olMap.addInteraction(drag);
115
+ const interactionResource = {
116
+ interaction: drag,
117
+ destroy() {
118
+ olMap.removeInteraction(drag);
119
+ interactionResources.splice(interactionResources.indexOf(this));
120
+ drag.dispose();
121
+ viewPort.classList.remove(ACTIVE_CLASS);
122
+ viewPort.classList.remove(INACTIVE_CLASS);
123
+ viewPort.oncontextmenu = null;
124
+ }
125
+ };
126
+ return interactionResource;
127
+ }
128
+ /**
129
+ * Method to generate a tooltip on the mouse cursor
130
+ */
131
+ createHelpTooltip(olMap, message) {
132
+ const element = document.createElement("div");
133
+ element.className = "selection-tooltip";
134
+ element.textContent = message;
135
+ const overlay = new Overlay({
136
+ element,
137
+ offset: [15, 0],
138
+ positioning: "center-left"
139
+ });
140
+ const pointHandler = olMap.on("pointermove", (evt) => {
141
+ overlay.setPosition(evt.coordinate);
142
+ });
143
+ olMap.addOverlay(overlay);
144
+ return {
145
+ overlay,
146
+ element,
147
+ destroy() {
148
+ olMap.removeOverlay(overlay);
149
+ overlay.dispose();
150
+ unByKey(pointHandler);
151
+ }
152
+ };
153
+ }
154
+ /**
155
+ * Method for testing purposes only
156
+ * @returns InteractionResource of class DragBox
157
+ */
158
+ getDragboxInteraction() {
159
+ return this.interactionResources.find(
160
+ (interactionResource) => interactionResource.interaction instanceof DragBox
161
+ );
162
+ }
163
+ /**
164
+ * Method for testing purposes only
165
+ * @returns InteractionResource of class DragPan
166
+ */
167
+ getDragPanInteraction() {
168
+ return this.interactionResources.find(
169
+ (interactionResource) => interactionResource.interaction instanceof DragPan
170
+ );
171
+ }
172
+ }
173
+
174
+ export { DragController };
175
+ //# sourceMappingURL=DragController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DragController.js","sources":["DragController.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Resource } from \"@open-pioneer/core/resources\";\nimport OlMap from \"ol/Map\";\nimport { unByKey } from \"ol/Observable\";\nimport Overlay from \"ol/Overlay\";\nimport { mouseActionButton } from \"ol/events/condition\";\nimport Geometry from \"ol/geom/Geometry\";\nimport { SelectionMethods } from \"./Selection\";\nimport { DragBox, DragPan } from \"ol/interaction\";\nimport PointerInteraction from \"ol/interaction/Pointer\";\n\ninterface InteractionResource extends Resource {\n interaction: PointerInteraction;\n}\n/** Represents a tooltip rendered on the OpenLayers map. */\ninterface Tooltip extends Resource {\n overlay: Overlay;\n element: HTMLDivElement;\n}\n\nconst ACTIVE_CLASS = \"selection-active\";\nconst INACTIVE_CLASS = \"selection-inactive\";\n\nexport class DragController {\n private tooltip: Tooltip;\n private interactionResources: InteractionResource[] = [];\n private olMap: OlMap;\n private isActive: boolean = true;\n private tooltipMessage: string;\n private tooltipDisabledMessage: string;\n\n constructor(\n olMap: OlMap,\n selectMethode: string,\n tooltipMessage: string,\n tooltipDisabledMessage: string,\n onExtentSelected: (geometry: Geometry) => void\n ) {\n let viewPort;\n /**\n * Notice for Projectdeveloper\n * Add cases for more Selectionmethods\n */\n switch (selectMethode) {\n case SelectionMethods.extent:\n default:\n viewPort = this.initViewport(olMap);\n this.interactionResources.push(\n this.createDragBox(olMap, onExtentSelected, viewPort, this.interactionResources)\n );\n this.interactionResources.push(\n this.createDrag(olMap, viewPort, this.interactionResources)\n );\n break;\n }\n\n this.tooltip = this.createHelpTooltip(olMap, tooltipMessage);\n this.olMap = olMap;\n this.tooltipMessage = tooltipMessage;\n this.tooltipDisabledMessage = tooltipDisabledMessage;\n }\n\n initViewport(olMap: OlMap) {\n const viewPort = olMap.getViewport();\n viewPort.classList.add(ACTIVE_CLASS);\n\n viewPort.oncontextmenu = (e) => {\n e.preventDefault();\n return false;\n };\n return viewPort;\n }\n\n /**\n * Method for destroying the controller when it is no longer needed\n */\n destroy() {\n this.tooltip.destroy();\n this.interactionResources.forEach((interaction) => {\n interaction.destroy();\n });\n }\n\n setActive(isActive: boolean) {\n if (this.isActive === isActive) return;\n const viewPort = this.olMap.getViewport();\n if (isActive) {\n this.interactionResources.forEach((interaction) =>\n this.olMap.addInteraction(interaction.interaction)\n );\n this.tooltip.element.textContent = this.tooltipMessage;\n viewPort.classList.remove(INACTIVE_CLASS);\n viewPort.classList.add(ACTIVE_CLASS);\n this.isActive = true;\n } else {\n this.interactionResources.forEach((interaction) =>\n this.olMap.removeInteraction(interaction.interaction)\n );\n this.tooltip.element.textContent = this.tooltipDisabledMessage;\n viewPort.classList.remove(ACTIVE_CLASS);\n viewPort.classList.add(INACTIVE_CLASS);\n this.isActive = false;\n }\n }\n\n /**\n * Method to create a simple extent-selection\n */\n private createDragBox(\n olMap: OlMap,\n onExtentSelected: (geometry: Geometry) => void,\n viewPort: HTMLElement,\n interactionResources: InteractionResource[]\n ): InteractionResource {\n const dragBox = new DragBox({\n className: \"selection-drag-box\",\n condition: mouseActionButton\n });\n\n olMap.addInteraction(dragBox);\n dragBox.on(\"boxend\", function () {\n onExtentSelected(dragBox.getGeometry());\n });\n\n const interactionResource: InteractionResource = {\n interaction: dragBox,\n destroy() {\n olMap.removeInteraction(dragBox);\n interactionResources.splice(interactionResources.indexOf(this));\n dragBox.dispose();\n viewPort.classList.remove(ACTIVE_CLASS);\n viewPort.classList.remove(INACTIVE_CLASS);\n viewPort.oncontextmenu = null;\n }\n };\n return interactionResource;\n }\n\n /**\n * Method to activate pan with right-mouse-click\n */\n private createDrag(\n olMap: OlMap,\n viewPort: HTMLElement,\n interactionResources: InteractionResource[]\n ): InteractionResource {\n const condition = function (mapBrowserEvent: {\n originalEvent: MouseEvent;\n dragging: unknown;\n }) {\n const originalEvent = /** @type {MouseEvent} */ mapBrowserEvent.originalEvent;\n return originalEvent.button == 2;\n };\n const drag = new DragPan({\n condition: condition\n });\n\n olMap.addInteraction(drag);\n\n const interactionResource: InteractionResource = {\n interaction: drag,\n destroy() {\n olMap.removeInteraction(drag);\n interactionResources.splice(interactionResources.indexOf(this));\n drag.dispose();\n viewPort.classList.remove(ACTIVE_CLASS);\n viewPort.classList.remove(INACTIVE_CLASS);\n viewPort.oncontextmenu = null;\n }\n };\n\n return interactionResource;\n }\n\n /**\n * Method to generate a tooltip on the mouse cursor\n */\n private createHelpTooltip(olMap: OlMap, message: string) {\n const element = document.createElement(\"div\");\n element.className = \"selection-tooltip\";\n element.textContent = message;\n\n const overlay = new Overlay({\n element: element,\n offset: [15, 0],\n positioning: \"center-left\"\n });\n\n const pointHandler = olMap.on(\"pointermove\", (evt) => {\n overlay.setPosition(evt.coordinate);\n });\n\n olMap.addOverlay(overlay);\n return {\n overlay,\n element,\n destroy() {\n olMap.removeOverlay(overlay);\n overlay.dispose();\n unByKey(pointHandler);\n }\n };\n }\n\n /**\n * Method for testing purposes only\n * @returns InteractionResource of class DragBox\n */\n getDragboxInteraction() {\n return this.interactionResources.find(\n (interactionResource) => interactionResource.interaction instanceof DragBox\n );\n }\n\n /**\n * Method for testing purposes only\n * @returns InteractionResource of class DragPan\n */\n getDragPanInteraction() {\n return this.interactionResources.find(\n (interactionResource) => interactionResource.interaction instanceof DragPan\n );\n }\n}\n"],"names":[],"mappings":";;;;;;AAqBA,MAAM,YAAe,GAAA,kBAAA,CAAA;AACrB,MAAM,cAAiB,GAAA,oBAAA,CAAA;AAEhB,MAAM,cAAe,CAAA;AAAA,EAChB,OAAA,CAAA;AAAA,EACA,uBAA8C,EAAC,CAAA;AAAA,EAC/C,KAAA,CAAA;AAAA,EACA,QAAoB,GAAA,IAAA,CAAA;AAAA,EACpB,cAAA,CAAA;AAAA,EACA,sBAAA,CAAA;AAAA,EAER,WACI,CAAA,KAAA,EACA,aACA,EAAA,cAAA,EACA,wBACA,gBACF,EAAA;AACE,IAAI,IAAA,QAAA,CAAA;AAKJ,IAAA,QAAQ,aAAe;AAAA,MACnB,KAAK,gBAAiB,CAAA,MAAA,CAAA;AAAA,MACtB;AACI,QAAW,QAAA,GAAA,IAAA,CAAK,aAAa,KAAK,CAAA,CAAA;AAClC,QAAA,IAAA,CAAK,oBAAqB,CAAA,IAAA;AAAA,UACtB,KAAK,aAAc,CAAA,KAAA,EAAO,gBAAkB,EAAA,QAAA,EAAU,KAAK,o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AAA,CAAoB,WAAuB,YAAA,OAAA;AAAA,KACxE,CAAA;AAAA,GACJ;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,qBAAwB,GAAA;AACpB,IAAA,OAAO,KAAK,oBAAqB,CAAA,IAAA;AAAA,MAC7B,CAAC,mBAAwB,KAAA,mBAAA,CAAoB,WAAuB,YAAA,OAAA;AAAA,KACxE,CAAA;AAAA,GACJ;AACJ;;;;"}
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,117 @@
1
+ # @open-pioneer/selection
2
+
3
+ This package provides a UI component to perform a selection on given selection sources from the map.
4
+
5
+ ## Usage
6
+
7
+ To add the component to your app, import `Selection` from `@open-pioneer/selection`. The `@open-pioneer/notifier` package is required too.
8
+
9
+ The mandatory properties are `mapId` and `sources` (layer source to be selected on).
10
+ The limit per selection is 10.000 items.
11
+
12
+ ```tsx
13
+ <Selection mapId={MAP_ID} sources={selectionsources} />
14
+ ```
15
+
16
+ ### Listening to events
17
+
18
+ To listen to the events `onSelectionComplete` and `onSelectionSourceChanged`, provide optional callback functions to the component.
19
+
20
+ In case of the `onSelectionComplete` event, you can access the selection result (and its source) from the parameter `SelectionCompleteEvent`.
21
+ In case of the `onSelectionSourceChanged` event, you can access the selected selection source from the parameter `SelectionSourceChangedEvent`.
22
+
23
+ ```tsx
24
+ import { Search, SearchSelectEvent } from "@open-pioneer/search";
25
+ <Selection
26
+ mapId={MAP_ID}
27
+ sources={datasources}
28
+ onSelectionComplete={(event: SelectionCompleteEvent) => {
29
+ // do something
30
+ }}
31
+ onSelectionSourceChanged={(event: SelectionSourceChangedEvent) => {
32
+ // do something
33
+ }}
34
+ />;
35
+ ```
36
+
37
+ ### Implementing a selection source
38
+
39
+ To provide the selection sources that are used by the selection-UI component, implement the function `select` for each selection source:
40
+
41
+ ```tsx
42
+ import {
43
+ Selection,
44
+ SelectionResult,
45
+ SelectionSource,
46
+ SelectionSourceStatus
47
+ } from "@open-pioneer/selection";
48
+ import { MAP_ID } from "./MapConfigProviderImpl";
49
+
50
+ class MySelectionSource implements SelectionSource {
51
+ // The label of this source, used as a title for this source's results.
52
+ label = "My sample REST-Service";
53
+
54
+ // The optional status of this source. If there is no status defined, it is assumed that the source is always available.
55
+ status?: SelectionSourceStatus;
56
+
57
+ // The reason that the source is not available. If it is not defined, the i18n value for "sourceNotAvailable" will be displayed
58
+ unavailableStatusReason?: string;
59
+
60
+ // Performs a selection with a given selectionKind and returns a list of selection results.
61
+ // see the API documentation of `SelectionSource`.
62
+ select(selectionKind: SelectionKind, options: SelectionOptions): Promise<SelectionResult[]> {}
63
+ }
64
+
65
+ const selectionsources: SelectionSource[] = [new MySelectionSource()];
66
+
67
+ // In your JSX template:
68
+ <Selection mapId={MAP_ID} sources={selectionsources} />;
69
+ ```
70
+
71
+ ### VectorLayer as selection source
72
+
73
+ To use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map) as a selection source,
74
+ the provided service `VectorSelectionSourceFactory` can be used to create an instance of `VectorLayerSelectionSource`.
75
+
76
+ Key features of this selection source implementation are:
77
+
78
+ - using only the extent as selection kind
79
+ - listening to layer visibility changes and updating the status of the source
80
+ - limiting the number of returned selection results to the corresponding selection option
81
+ - throwing an event `changed:status` when the status updates
82
+
83
+ Inject the selection source factory by referencing `"selection.VectorSelectionSourceFactory"`:
84
+
85
+ ```js
86
+ // build.config.mjs
87
+ import { defineBuildConfig } from "@open-pioneer/build-support";
88
+
89
+ export default defineBuildConfig({
90
+ services: {
91
+ YourService: {
92
+ // ...
93
+ references: {
94
+ vectorSelectionSourceFactory: "selection.VectorSelectionSourceFactory"
95
+ }
96
+ }
97
+ }
98
+ });
99
+ ```
100
+
101
+ and create a selection source instance:
102
+
103
+ ```ts
104
+ const vectorSelectionSourceFactory = this._vectorSelectionSourceFactory; // injected
105
+ const layerSelectionSource = vectorSelectionSourceFactory.createSelectionSource({
106
+ vectorLayer: vectorLayer,
107
+ label: "My Vector Layer Title shown in UI"
108
+ });
109
+
110
+ const eventHandler = layerSelectionSource.on("changed:status", () => {
111
+ // do something (e.g. like removing map highlighting if unavailable)
112
+ });
113
+ ```
114
+
115
+ ## License
116
+
117
+ Apache-2.0 (see `LICENSE` file)
package/Selection.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ import { CommonComponentProps } from "@open-pioneer/react-utils";
2
+ import { FC } from "react";
3
+ import { SelectionResult, SelectionSource } from "./api";
4
+ /**
5
+ * Properties supported by the {@link Selection} component.
6
+ */
7
+ export interface SelectionProps extends CommonComponentProps {
8
+ /**
9
+ * The id of the map.
10
+ */
11
+ mapId: string;
12
+ /**
13
+ * Array of selection sources available for spatial selection.
14
+ */
15
+ sources: SelectionSource[];
16
+ /**
17
+ * This handler is called whenever the user has successfully selected
18
+ * some items.
19
+ */
20
+ onSelectionComplete?(event: SelectionCompleteEvent): void;
21
+ /**
22
+ * This handler is called whenever the user has changed the selected source
23
+ */
24
+ onSelectionSourceChanged?(event: SelectionSourceChangedEvent): void;
25
+ }
26
+ export interface SelectionCompleteEvent {
27
+ /** The source that returned the {@link results}. */
28
+ source: SelectionSource;
29
+ /** Results selected by the user. */
30
+ results: SelectionResult[];
31
+ }
32
+ export interface SelectionSourceChangedEvent {
33
+ /** The new selected source */
34
+ source: SelectionSource | undefined;
35
+ }
36
+ /**
37
+ * Supported selection methods
38
+ */
39
+ export declare enum SelectionMethods {
40
+ extent = "EXTENT",
41
+ polygon = "POLYGON",
42
+ free = "FREEPOLYGON",
43
+ circle = "CIRCLE"
44
+ }
45
+ /**
46
+ * A component that allows the user to perform a spatial selection on a given set of {@link SelectionSource}.
47
+ */
48
+ export declare const Selection: FC<SelectionProps>;