@open-pioneer/selection 1.4.0 → 1.5.0-dev.20260910103330
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 +47 -29
- package/README.md +28 -9
- package/_virtual/hooks.js +1 -1
- package/_virtual/source-info.js +1 -1
- package/api.d.ts +27 -2
- package/i18n/de.yaml +0 -6
- package/i18n/en.yaml +0 -6
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/interactions/ExtentSelectionInteraction.d.ts +12 -0
- package/interactions/ExtentSelectionInteraction.js +57 -0
- package/interactions/ExtentSelectionInteraction.js.map +1 -0
- package/model/SelectionViewModel.d.ts +30 -0
- package/model/SelectionViewModel.js +270 -0
- package/model/SelectionViewModel.js.map +1 -0
- package/model/SelectionViewModelFactory.d.ts +21 -0
- package/model/SelectionViewModelFactory.js +43 -0
- package/model/SelectionViewModelFactory.js.map +1 -0
- package/model/index.d.ts +1 -0
- package/model/index.js +2 -0
- package/model/index.js.map +1 -0
- package/package.json +34 -15
- package/services.d.ts +2 -7
- package/services.js +2 -17
- package/services.js.map +1 -1
- package/{VectorSelectionSource.d.ts → sources/VectorSelectionSource.d.ts} +3 -7
- package/{VectorSelectionSource.js → sources/VectorSelectionSource.js} +12 -9
- package/sources/VectorSelectionSource.js.map +1 -0
- package/sources/VectorSelectionSourceFactory.d.ts +7 -0
- package/sources/VectorSelectionSourceFactory.js +19 -0
- package/sources/VectorSelectionSourceFactory.js.map +1 -0
- package/{Selection.d.ts → ui/Selection.d.ts} +1 -1
- package/ui/Selection.js +97 -0
- package/ui/Selection.js.map +1 -0
- package/ui/SelectionSourceItem.d.ts +7 -0
- package/ui/SelectionSourceItem.js +38 -0
- package/ui/SelectionSourceItem.js.map +1 -0
- package/ui/useSelectionSourceId.d.ts +9 -0
- package/ui/useSelectionSourceId.js +23 -0
- package/ui/useSelectionSourceId.js.map +1 -0
- package/ui/useSelectionViewModel.d.ts +11 -0
- package/ui/useSelectionViewModel.js +43 -0
- package/ui/useSelectionViewModel.js.map +1 -0
- package/ui/useSourceStatus.d.ts +8 -0
- package/ui/useSourceStatus.js +27 -0
- package/ui/useSourceStatus.js.map +1 -0
- package/DragController.d.ts +0 -33
- package/DragController.js +0 -175
- package/DragController.js.map +0 -1
- package/Selection.js +0 -232
- package/Selection.js.map +0 -1
- package/SelectionController.d.ts +0 -20
- package/SelectionController.js +0 -58
- package/SelectionController.js.map +0 -1
- package/VectorSelectionSource.js.map +0 -1
- /package/{SelectionTooltipContent.d.ts → ui/SelectionTooltipContent.d.ts} +0 -0
- /package/{SelectionTooltipContent.js → ui/SelectionTooltipContent.js} +0 -0
- /package/{SelectionTooltipContent.js.map → ui/SelectionTooltipContent.js.map} +0 -0
- /package/{selection.css → ui/selection.css} +0 -0
- /package/{selection.css.map → ui/selection.css.map} +0 -0
package/Selection.js
DELETED
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { createListCollection, VStack, Select, Portal, Flex, Box, chakra, Icon } from '@chakra-ui/react';
|
|
3
|
-
import { Tooltip } from '@open-pioneer/chakra-snippets/tooltip';
|
|
4
|
-
import { useMapModelValue } from '@open-pioneer/map';
|
|
5
|
-
import { useCommonComponentProps, useEvent } from '@open-pioneer/react-utils';
|
|
6
|
-
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
7
|
-
import { useIntl, useService } from './_virtual/hooks.js';
|
|
8
|
-
import { useState, useEffect, useRef, useCallback } from 'react';
|
|
9
|
-
import { LuTriangleAlert } from 'react-icons/lu';
|
|
10
|
-
import { DragController } from './DragController.js';
|
|
11
|
-
import { SelectionController } from './SelectionController.js';
|
|
12
|
-
|
|
13
|
-
const Selection = (props) => {
|
|
14
|
-
const intl = useIntl();
|
|
15
|
-
const { sources, onSelectionComplete, onSelectionSourceChanged } = props;
|
|
16
|
-
const { containerProps } = useCommonComponentProps("selection", props);
|
|
17
|
-
const [currentSource, setCurrentSource] = useCurrentSelectionSource(
|
|
18
|
-
sources,
|
|
19
|
-
onSelectionSourceChanged
|
|
20
|
-
);
|
|
21
|
-
const currentSourceStatus = useSourceStatus(currentSource);
|
|
22
|
-
const map = useMapModelValue(props);
|
|
23
|
-
const { onExtentSelected } = useSelectionController(
|
|
24
|
-
map,
|
|
25
|
-
sources,
|
|
26
|
-
currentSource,
|
|
27
|
-
onSelectionComplete
|
|
28
|
-
);
|
|
29
|
-
const isActive = currentSourceStatus.kind === "available";
|
|
30
|
-
const hasSelectedSource = !!currentSource;
|
|
31
|
-
const dragController = useDragSelection(
|
|
32
|
-
map,
|
|
33
|
-
intl,
|
|
34
|
-
onExtentSelected,
|
|
35
|
-
isActive,
|
|
36
|
-
hasSelectedSource
|
|
37
|
-
);
|
|
38
|
-
const dragTooltip = useReactiveSnapshot(() => dragController?.tooltipText, [dragController]);
|
|
39
|
-
const getId = useSelectionSourceId();
|
|
40
|
-
const sourceOptionsCollection = createListCollection({
|
|
41
|
-
items: sources,
|
|
42
|
-
isItemDisabled: () => {
|
|
43
|
-
return false;
|
|
44
|
-
},
|
|
45
|
-
itemToString: (item) => item.label,
|
|
46
|
-
itemToValue: (item) => getId(item)
|
|
47
|
-
});
|
|
48
|
-
let triggerItem;
|
|
49
|
-
if (currentSource) {
|
|
50
|
-
triggerItem = /* @__PURE__ */ jsx(SelectionSourceItem, { source: currentSource });
|
|
51
|
-
} else {
|
|
52
|
-
triggerItem = null;
|
|
53
|
-
}
|
|
54
|
-
return /* @__PURE__ */ jsx(VStack, { ...containerProps, gap: 2, children: /* @__PURE__ */ jsxs(
|
|
55
|
-
Select.Root,
|
|
56
|
-
{
|
|
57
|
-
className: "selection-source",
|
|
58
|
-
collection: sourceOptionsCollection,
|
|
59
|
-
value: currentSource ? [getId(currentSource)] : void 0,
|
|
60
|
-
onValueChange: (option) => option && setCurrentSource(option.items[0]),
|
|
61
|
-
lazyMount: true,
|
|
62
|
-
unmountOnExit: true,
|
|
63
|
-
children: [
|
|
64
|
-
/* @__PURE__ */ jsx(Select.Label, { children: intl.formatMessage({ id: "selectSource" }) }),
|
|
65
|
-
/* @__PURE__ */ jsxs(Select.Control, { children: [
|
|
66
|
-
/* @__PURE__ */ jsx(Select.Trigger, { "aria-description": dragTooltip, children: /* @__PURE__ */ jsx(
|
|
67
|
-
Select.ValueText,
|
|
68
|
-
{
|
|
69
|
-
placeholder: intl.formatMessage({ id: "selectionPlaceholder" }),
|
|
70
|
-
children: triggerItem
|
|
71
|
-
}
|
|
72
|
-
) }),
|
|
73
|
-
/* @__PURE__ */ jsx(Select.IndicatorGroup, { children: /* @__PURE__ */ jsx(Select.Indicator, {}) })
|
|
74
|
-
] }),
|
|
75
|
-
/* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(Select.Positioner, { children: /* @__PURE__ */ jsx(Select.Content, { className: "selection-source-options", children: sourceOptionsCollection.items.map((item) => /* @__PURE__ */ jsx(SelectionSourceItemContent, { item }, getId(item))) }) }) })
|
|
76
|
-
]
|
|
77
|
-
}
|
|
78
|
-
) });
|
|
79
|
-
};
|
|
80
|
-
function useSelectionSourceId() {
|
|
81
|
-
const sourceIds = useRef(void 0);
|
|
82
|
-
const counter = useRef(0);
|
|
83
|
-
if (!sourceIds.current) {
|
|
84
|
-
sourceIds.current = /* @__PURE__ */ new WeakMap();
|
|
85
|
-
}
|
|
86
|
-
return useCallback((selectionSource) => {
|
|
87
|
-
const ids = sourceIds.current;
|
|
88
|
-
if (!ids.has(selectionSource)) {
|
|
89
|
-
ids.set(selectionSource, `source-${counter.current++}`);
|
|
90
|
-
}
|
|
91
|
-
return ids.get(selectionSource);
|
|
92
|
-
}, []);
|
|
93
|
-
}
|
|
94
|
-
function SelectionSourceItemContent(props) {
|
|
95
|
-
const { item } = props;
|
|
96
|
-
const isDisabled = useSourceStatus(item).kind === "unavailable";
|
|
97
|
-
return /* @__PURE__ */ jsx(
|
|
98
|
-
Select.Item,
|
|
99
|
-
{
|
|
100
|
-
className: "selection-source-option",
|
|
101
|
-
item,
|
|
102
|
-
justifyContent: "flex-start",
|
|
103
|
-
pointerEvents: "auto",
|
|
104
|
-
"aria-disabled": isDisabled ? "true" : void 0,
|
|
105
|
-
children: /* @__PURE__ */ jsx(SelectionSourceItem, { source: item })
|
|
106
|
-
}
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
function useCurrentSelectionSource(sources, onSourceChanged) {
|
|
110
|
-
const [currentSource, setCurrentSource] = useState(
|
|
111
|
-
() => sources[0]
|
|
112
|
-
);
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
if (currentSource && !sources.includes(currentSource)) {
|
|
115
|
-
setCurrentSource(void 0);
|
|
116
|
-
}
|
|
117
|
-
}, [sources, currentSource]);
|
|
118
|
-
const prevSelectedSource = useRef(void 0);
|
|
119
|
-
useEffect(() => {
|
|
120
|
-
if (currentSource !== prevSelectedSource.current) {
|
|
121
|
-
prevSelectedSource.current = currentSource;
|
|
122
|
-
onSourceChanged?.({ source: currentSource });
|
|
123
|
-
}
|
|
124
|
-
}, [currentSource, onSourceChanged]);
|
|
125
|
-
return [currentSource, setCurrentSource];
|
|
126
|
-
}
|
|
127
|
-
function SelectionSourceItem(props) {
|
|
128
|
-
const source = props.source;
|
|
129
|
-
const label = source?.label;
|
|
130
|
-
const status = useSourceStatus(source);
|
|
131
|
-
const isAvailable = status.kind === "available";
|
|
132
|
-
const clazz = isAvailable ? "selection-source-value" : "selection-source-value selection-source-value--disabled";
|
|
133
|
-
return /* @__PURE__ */ jsxs(Flex, { className: clazz, direction: "row", alignItems: "center", grow: 1, children: [
|
|
134
|
-
label,
|
|
135
|
-
status.kind === "unavailable" && /* @__PURE__ */ jsx(Box, { ml: 2, children: /* @__PURE__ */ jsx(
|
|
136
|
-
Tooltip,
|
|
137
|
-
{
|
|
138
|
-
content: status.reason,
|
|
139
|
-
positioning: { placement: "right" },
|
|
140
|
-
openDelay: 500,
|
|
141
|
-
children: /* @__PURE__ */ jsx(chakra.span, { children: /* @__PURE__ */ jsx(
|
|
142
|
-
Icon,
|
|
143
|
-
{
|
|
144
|
-
color: "red",
|
|
145
|
-
className: "warning-icon",
|
|
146
|
-
"aria-label": status.reason,
|
|
147
|
-
"aria-hidden": void 0,
|
|
148
|
-
children: /* @__PURE__ */ jsx(LuTriangleAlert, {})
|
|
149
|
-
}
|
|
150
|
-
) })
|
|
151
|
-
}
|
|
152
|
-
) })
|
|
153
|
-
] });
|
|
154
|
-
}
|
|
155
|
-
function useSelectionController(mapModel, sources, currentSource, onSelectionComplete) {
|
|
156
|
-
const notifier = useService("notifier.NotificationService");
|
|
157
|
-
const intl = useIntl();
|
|
158
|
-
const [controller, setController] = useState(void 0);
|
|
159
|
-
useEffect(() => {
|
|
160
|
-
const controller2 = new SelectionController({
|
|
161
|
-
mapModel,
|
|
162
|
-
onError() {
|
|
163
|
-
notifier.notify({
|
|
164
|
-
level: "error",
|
|
165
|
-
message: intl.formatMessage({ id: "selectionFailed" })
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
setController(controller2);
|
|
170
|
-
return () => {
|
|
171
|
-
controller2.destroy();
|
|
172
|
-
};
|
|
173
|
-
}, [mapModel, notifier, sources, intl]);
|
|
174
|
-
const onExtentSelected = useEvent(async (geometry) => {
|
|
175
|
-
if (!controller || !currentSource) {
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
const selectionResult = await controller.select(currentSource, geometry.getExtent());
|
|
179
|
-
if (!selectionResult) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
onSelectionComplete?.(selectionResult);
|
|
183
|
-
});
|
|
184
|
-
return {
|
|
185
|
-
controller,
|
|
186
|
-
onExtentSelected
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
function getSourceStatus(source, sourceNotAvailableReason) {
|
|
190
|
-
const rawCurrent = source.status ?? "available";
|
|
191
|
-
const current = typeof rawCurrent === "string" ? { kind: rawCurrent } : rawCurrent;
|
|
192
|
-
if (current.kind === "available") {
|
|
193
|
-
return current;
|
|
194
|
-
}
|
|
195
|
-
return {
|
|
196
|
-
kind: "unavailable",
|
|
197
|
-
reason: current.reason ?? sourceNotAvailableReason
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
function useSourceStatus(source) {
|
|
201
|
-
const intl = useIntl();
|
|
202
|
-
const defaultNotAvailableMessage = intl.formatMessage({ id: "sourceNotAvailable" });
|
|
203
|
-
const sourceStatus = useReactiveSnapshot(() => {
|
|
204
|
-
if (!source) {
|
|
205
|
-
return { kind: "unavailable", reason: defaultNotAvailableMessage };
|
|
206
|
-
}
|
|
207
|
-
return getSourceStatus(source, defaultNotAvailableMessage);
|
|
208
|
-
}, [source, defaultNotAvailableMessage]);
|
|
209
|
-
return sourceStatus;
|
|
210
|
-
}
|
|
211
|
-
function useDragSelection(map, intl, onExtentSelected, isActive, hasSelectedSource) {
|
|
212
|
-
const [controller, setController] = useState();
|
|
213
|
-
useEffect(() => {
|
|
214
|
-
const disabledMessage = hasSelectedSource ? intl.formatMessage({ id: "disabledTooltip" }) : intl.formatMessage({ id: "noSourceTooltip" });
|
|
215
|
-
const dragController = new DragController(
|
|
216
|
-
map,
|
|
217
|
-
intl.formatMessage({ id: "tooltip" }),
|
|
218
|
-
disabledMessage,
|
|
219
|
-
onExtentSelected
|
|
220
|
-
);
|
|
221
|
-
dragController.setActive(isActive);
|
|
222
|
-
setController(dragController);
|
|
223
|
-
return () => {
|
|
224
|
-
setController(void 0);
|
|
225
|
-
dragController.destroy();
|
|
226
|
-
};
|
|
227
|
-
}, [map, intl, onExtentSelected, isActive, hasSelectedSource]);
|
|
228
|
-
return controller;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
export { Selection };
|
|
232
|
-
//# sourceMappingURL=Selection.js.map
|
package/Selection.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Selection.js","sources":["Selection.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport {\n Box,\n chakra,\n createListCollection,\n Flex,\n Icon,\n Portal,\n Select,\n VStack\n} from \"@chakra-ui/react\";\nimport { Tooltip } from \"@open-pioneer/chakra-snippets/tooltip\";\nimport { MapModel, MapModelProps, useMapModelValue } from \"@open-pioneer/map\";\nimport { NotificationService } from \"@open-pioneer/notifier\";\nimport { CommonComponentProps, useCommonComponentProps, useEvent } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { Geometry } from \"ol/geom\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { FC, useCallback, useEffect, useRef, useState } from \"react\";\nimport { LuTriangleAlert } from \"react-icons/lu\";\nimport { SelectionResult, SelectionSource, SelectionSourceStatusObject } from \"./api\";\nimport { DragController } from \"./DragController\";\nimport { SelectionController } from \"./SelectionController\";\n\n/**\n * Properties supported by the {@link Selection} component.\n */\nexport interface SelectionProps extends CommonComponentProps, MapModelProps {\n /**\n * Array of selection sources available for spatial selection.\n */\n sources: SelectionSource[];\n\n /**\n * This handler is called whenever the user has successfully selected\n * some items.\n */\n onSelectionComplete?(event: SelectionCompleteEvent): void;\n\n /**\n * This handler is called whenever the user has changed the selected source\n */\n onSelectionSourceChanged?(event: SelectionSourceChangedEvent): void;\n}\n\nexport interface SelectionCompleteEvent {\n /** The source that returned the {@link results}. */\n source: SelectionSource;\n\n /** Results selected by the user. */\n results: SelectionResult[];\n}\n\nexport interface SelectionSourceChangedEvent {\n /** The new selected source */\n source: SelectionSource | undefined;\n}\n\n/**\n * A component that allows the user to perform a spatial selection on a given set of {@link SelectionSource}.\n */\nexport const Selection: FC<SelectionProps> = (props) => {\n const intl = useIntl();\n const { sources, onSelectionComplete, onSelectionSourceChanged } = props;\n const { containerProps } = useCommonComponentProps(\"selection\", props);\n\n const [currentSource, setCurrentSource] = useCurrentSelectionSource(\n sources,\n onSelectionSourceChanged\n );\n\n const currentSourceStatus = useSourceStatus(currentSource);\n\n const map = useMapModelValue(props);\n const { onExtentSelected } = useSelectionController(\n map,\n sources,\n currentSource,\n onSelectionComplete\n );\n\n const isActive = currentSourceStatus.kind === \"available\";\n const hasSelectedSource = !!currentSource;\n\n const dragController = useDragSelection(\n map,\n intl,\n onExtentSelected,\n isActive,\n hasSelectedSource\n );\n const dragTooltip = useReactiveSnapshot(() => dragController?.tooltipText, [dragController]);\n\n const getId = useSelectionSourceId();\n\n const sourceOptionsCollection = createListCollection({\n items: sources,\n isItemDisabled: () => {\n return false;\n },\n itemToString: (item) => item.label,\n itemToValue: (item) => getId(item)\n });\n\n let triggerItem;\n if (currentSource) {\n triggerItem = <SelectionSourceItem source={currentSource} />;\n } else {\n triggerItem = null;\n }\n\n return (\n <VStack {...containerProps} gap={2}>\n <Select.Root\n className=\"selection-source\"\n collection={sourceOptionsCollection}\n value={currentSource ? [getId(currentSource)] : undefined}\n onValueChange={(option) => option && setCurrentSource(option.items[0])}\n lazyMount={true}\n unmountOnExit={true}\n >\n <Select.Label>{intl.formatMessage({ id: \"selectSource\" })}</Select.Label>\n\n <Select.Control>\n <Select.Trigger aria-description={dragTooltip}>\n <Select.ValueText\n placeholder={intl.formatMessage({ id: \"selectionPlaceholder\" })}\n >\n {triggerItem}\n </Select.ValueText>\n </Select.Trigger>\n <Select.IndicatorGroup>\n <Select.Indicator />\n </Select.IndicatorGroup>\n </Select.Control>\n\n <Portal>\n <Select.Positioner>\n <Select.Content className=\"selection-source-options\">\n {sourceOptionsCollection.items.map((item) => (\n <SelectionSourceItemContent item={item} key={getId(item)} />\n ))}\n </Select.Content>\n </Select.Positioner>\n </Portal>\n </Select.Root>\n </VStack>\n );\n};\n\ntype GetSelectionSourceId = (selectionSource: SelectionSource) => string;\n\n/**\n * Assigns unique IDs to selection sources.\n */\nfunction useSelectionSourceId(): GetSelectionSourceId {\n const sourceIds = useRef<WeakMap<SelectionSource, string>>(undefined);\n const counter = useRef(0);\n if (!sourceIds.current) {\n sourceIds.current = new WeakMap();\n }\n\n return useCallback((selectionSource: SelectionSource) => {\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n const ids = sourceIds.current!;\n if (!ids.has(selectionSource)) {\n ids.set(selectionSource, `source-${counter.current++}`);\n }\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n return ids.get(selectionSource)!;\n }, []);\n}\n\nfunction SelectionSourceItemContent(props: { item: SelectionSource }) {\n const { item } = props;\n\n const isDisabled = useSourceStatus(item).kind === \"unavailable\";\n\n return (\n <Select.Item\n className=\"selection-source-option\"\n item={item}\n justifyContent=\"flex-start\"\n // Override pointer-events: none rule for disabled items; we want to show the tooltip on hover\n pointerEvents=\"auto\"\n aria-disabled={isDisabled ? \"true\" : undefined}\n >\n <SelectionSourceItem source={item} />\n </Select.Item>\n );\n}\n\nfunction useCurrentSelectionSource(\n sources: SelectionSource[],\n onSourceChanged: ((event: SelectionSourceChangedEvent) => void) | undefined\n): [SelectionSource | undefined, (source: SelectionSource | undefined) => void] {\n const [currentSource, setCurrentSource] = useState<SelectionSource | undefined>(\n () => sources[0]\n );\n\n // Reset to undefined if the current source is not in the list of sources\n useEffect(() => {\n if (currentSource && !sources.includes(currentSource)) {\n setCurrentSource(undefined);\n }\n }, [sources, currentSource]);\n\n // Track the current source and notify the parent component if it changes\n const prevSelectedSource = useRef<SelectionSource | undefined>(undefined);\n useEffect(() => {\n if (currentSource !== prevSelectedSource.current) {\n prevSelectedSource.current = currentSource;\n onSourceChanged?.({ source: currentSource });\n }\n }, [currentSource, onSourceChanged]);\n return [currentSource, setCurrentSource];\n}\n\nfunction SelectionSourceItem(props: { source: SelectionSource | undefined }) {\n const source = props.source;\n const label: string | undefined = source?.label;\n const status = useSourceStatus(source);\n const isAvailable = status.kind === \"available\";\n const clazz = isAvailable\n ? \"selection-source-value\"\n : \"selection-source-value selection-source-value--disabled\";\n\n return (\n <Flex className={clazz} direction=\"row\" alignItems=\"center\" grow={1}>\n {label}\n {status.kind === \"unavailable\" && (\n <Box ml={2}>\n <Tooltip\n content={status.reason}\n positioning={{ placement: \"right\" }}\n openDelay={500}\n >\n <chakra.span>\n <Icon\n color=\"red\"\n className=\"warning-icon\"\n aria-label={status.reason}\n aria-hidden={undefined} // Overwrite icon default so the label gets read\n >\n <LuTriangleAlert />\n </Icon>\n </chakra.span>\n </Tooltip>\n </Box>\n )}\n </Flex>\n );\n}\n\n/**\n * Hook to manage selection controller\n */\nfunction useSelectionController(\n mapModel: MapModel,\n sources: SelectionSource[],\n currentSource: SelectionSource | undefined,\n onSelectionComplete: ((event: SelectionCompleteEvent) => void) | undefined\n) {\n const notifier = useService<NotificationService>(\"notifier.NotificationService\");\n const intl = useIntl();\n const [controller, setController] = useState<SelectionController | undefined>(undefined);\n useEffect(() => {\n const controller = new SelectionController({\n mapModel,\n onError() {\n notifier.notify({\n level: \"error\",\n message: intl.formatMessage({ id: \"selectionFailed\" })\n });\n }\n });\n setController(controller);\n return () => {\n controller.destroy();\n };\n }, [mapModel, notifier, sources, intl]);\n\n const onExtentSelected = useEvent(async (geometry: Geometry) => {\n if (!controller || !currentSource) {\n return;\n }\n\n const selectionResult = await controller.select(currentSource, geometry.getExtent());\n if (!selectionResult) {\n return;\n }\n\n onSelectionComplete?.(selectionResult);\n });\n return {\n controller,\n onExtentSelected\n };\n}\n\ntype SimpleStatus =\n | {\n kind: \"available\";\n }\n | {\n kind: \"unavailable\";\n reason: string;\n };\n\nfunction getSourceStatus(source: SelectionSource, sourceNotAvailableReason: string): SimpleStatus {\n const rawCurrent = source.status ?? \"available\";\n const current: SelectionSourceStatusObject =\n typeof rawCurrent === \"string\" ? { kind: rawCurrent } : rawCurrent;\n if (current.kind === \"available\") {\n return current;\n }\n\n return {\n kind: \"unavailable\",\n reason: current.reason ?? sourceNotAvailableReason\n };\n}\n\n/**\n * Hook to manage source status\n */\nfunction useSourceStatus(source: SelectionSource | undefined): SimpleStatus {\n const intl = useIntl();\n const defaultNotAvailableMessage = intl.formatMessage({ id: \"sourceNotAvailable\" });\n const sourceStatus = useReactiveSnapshot((): SimpleStatus => {\n if (!source) {\n return { kind: \"unavailable\", reason: defaultNotAvailableMessage };\n }\n return getSourceStatus(source, defaultNotAvailableMessage);\n }, [source, defaultNotAvailableMessage]);\n return sourceStatus;\n}\n\n/**\n * Hook to manage map controls and tooltip\n */\n// oxlint-disable-next-line max-params\nfunction useDragSelection(\n map: MapModel,\n intl: PackageIntl,\n onExtentSelected: (geometry: Geometry) => void,\n isActive: boolean,\n hasSelectedSource: boolean\n): DragController | undefined {\n const [controller, setController] = useState<DragController | undefined>();\n useEffect(() => {\n const disabledMessage = hasSelectedSource\n ? intl.formatMessage({ id: \"disabledTooltip\" })\n : intl.formatMessage({ id: \"noSourceTooltip\" });\n\n const dragController = new DragController(\n map,\n intl.formatMessage({ id: \"tooltip\" }),\n disabledMessage,\n onExtentSelected\n );\n\n dragController.setActive(isActive);\n setController(dragController);\n return () => {\n setController(undefined);\n dragController.destroy();\n };\n }, [map, intl, onExtentSelected, isActive, hasSelectedSource]);\n return controller;\n}\n"],"names":["controller"],"mappings":";;;;;;;;;;;;AAgEO,MAAM,SAAA,GAAgC,CAAC,KAAA,KAAU;AACpD,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM,EAAE,OAAA,EAAS,mBAAA,EAAqB,wBAAA,EAAyB,GAAI,KAAA;AACnE,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,uBAAA,CAAwB,aAAa,KAAK,CAAA;AAErE,EAAA,MAAM,CAAC,aAAA,EAAe,gBAAgB,CAAA,GAAI,yBAAA;AAAA,IACtC,OAAA;AAAA,IACA;AAAA,GACJ;AAEA,EAAA,MAAM,mBAAA,GAAsB,gBAAgB,aAAa,CAAA;AAEzD,EAAA,MAAM,GAAA,GAAM,iBAAiB,KAAK,CAAA;AAClC,EAAA,MAAM,EAAE,kBAAiB,GAAI,sBAAA;AA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AACzE,EAAA,SAAA,CAAU,MAAM;AACZ,IAAA,MAAM,eAAA,GAAkB,iBAAA,GAClB,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,iBAAA,EAAmB,CAAA,GAC5C,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,mBAAmB,CAAA;AAElD,IAAA,MAAM,iBAAiB,IAAI,cAAA;AAAA,MACvB,GAAA;AAAA,MACA,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,WAAW,CAAA;AAAA,MACpC,eAAA;AAAA,MACA;AAAA,KACJ;AAEA,IAAA,cAAA,CAAe,UAAU,QAAQ,CAAA;AACjC,IAAA,aAAA,CAAc,cAAc,CAAA;AAC5B,IAAA,OAAO,MAAM;AACT,MAAA,aAAA,CAAc,MAAS,CAAA;AACvB,MAAA,cAAA,CAAe,OAAA,EAAQ;AAAA,IAC3B,CAAA;AAAA,EACJ,GAAG,CAAC,GAAA,EAAK,MAAM,gBAAA,EAAkB,QAAA,EAAU,iBAAiB,CAAC,CAAA;AAC7D,EAAA,OAAO,UAAA;AACX;;;;"}
|
package/SelectionController.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { MapModel } from "@open-pioneer/map";
|
|
2
|
-
import { Extent } from "ol/extent";
|
|
3
|
-
import type { SelectionResult, SelectionSource } from "./api";
|
|
4
|
-
/**
|
|
5
|
-
* All results returned from one source.
|
|
6
|
-
*/
|
|
7
|
-
export interface SelectionSourceResults {
|
|
8
|
-
source: SelectionSource;
|
|
9
|
-
results: SelectionResult[];
|
|
10
|
-
}
|
|
11
|
-
export declare class SelectionController {
|
|
12
|
-
#private;
|
|
13
|
-
constructor(options: {
|
|
14
|
-
mapModel: MapModel;
|
|
15
|
-
onError: () => void;
|
|
16
|
-
maxResults?: number;
|
|
17
|
-
});
|
|
18
|
-
destroy(): void;
|
|
19
|
-
select(source: SelectionSource, extent: Extent): Promise<SelectionSourceResults | undefined>;
|
|
20
|
-
}
|
package/SelectionController.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { createLogger } from '@open-pioneer/core';
|
|
2
|
-
import { sourceId } from './_virtual/source-info.js';
|
|
3
|
-
|
|
4
|
-
const LOG = createLogger(sourceId);
|
|
5
|
-
const DEFAULT_MAX_RESULTS = 1e4;
|
|
6
|
-
class SelectionController {
|
|
7
|
-
#mapModel;
|
|
8
|
-
/**
|
|
9
|
-
* Limits the number of results.
|
|
10
|
-
*/
|
|
11
|
-
#maxResults;
|
|
12
|
-
/**
|
|
13
|
-
* Called whenever an error happens.
|
|
14
|
-
*/
|
|
15
|
-
#onError;
|
|
16
|
-
constructor(options) {
|
|
17
|
-
const { mapModel, onError, maxResults = DEFAULT_MAX_RESULTS } = options;
|
|
18
|
-
this.#mapModel = mapModel;
|
|
19
|
-
this.#maxResults = maxResults;
|
|
20
|
-
this.#onError = onError;
|
|
21
|
-
}
|
|
22
|
-
destroy() {
|
|
23
|
-
}
|
|
24
|
-
async select(source, extent) {
|
|
25
|
-
if (!extent) {
|
|
26
|
-
return void 0;
|
|
27
|
-
}
|
|
28
|
-
return await this.#selectFromSource(source, extent);
|
|
29
|
-
}
|
|
30
|
-
async #selectFromSource(source, extent) {
|
|
31
|
-
const projection = this.#mapModel.olMap.getView().getProjection();
|
|
32
|
-
try {
|
|
33
|
-
LOG.debug(`Starting selection on source '${source.label}'`);
|
|
34
|
-
const maxResults = this.#maxResults;
|
|
35
|
-
let results = await source.select(
|
|
36
|
-
{ type: "extent", extent },
|
|
37
|
-
{
|
|
38
|
-
maxResults,
|
|
39
|
-
mapProjection: projection,
|
|
40
|
-
signal: new AbortController().signal
|
|
41
|
-
// currently not used
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
if (results.length > maxResults) {
|
|
45
|
-
results = results.slice(0, maxResults);
|
|
46
|
-
}
|
|
47
|
-
LOG.debug(`Found ${results.length} results on source '${source.label}'`);
|
|
48
|
-
return { source, results };
|
|
49
|
-
} catch (e) {
|
|
50
|
-
LOG.error(`selection from source ${source.label} failed`, e);
|
|
51
|
-
this.#onError();
|
|
52
|
-
return void 0;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export { SelectionController };
|
|
58
|
-
//# sourceMappingURL=SelectionController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SelectionController.js","sources":["SelectionController.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { createLogger } from \"@open-pioneer/core\";\nimport { MapModel } from \"@open-pioneer/map\";\nimport { Extent } from \"ol/extent\";\nimport { sourceId } from \"open-pioneer:source-info\";\nimport type { SelectionResult, SelectionSource } from \"./api\";\n\nconst LOG = createLogger(sourceId);\n\n/**\n * All results returned from one source.\n */\nexport interface SelectionSourceResults {\n source: SelectionSource;\n results: SelectionResult[];\n}\n\nconst DEFAULT_MAX_RESULTS = 10000;\n\nexport class SelectionController {\n #mapModel: MapModel;\n\n /**\n * Limits the number of results.\n */\n readonly #maxResults: number;\n\n /**\n * Called whenever an error happens.\n */\n readonly #onError: () => void;\n\n constructor(options: { mapModel: MapModel; onError: () => void; maxResults?: number }) {\n const { mapModel, onError, maxResults = DEFAULT_MAX_RESULTS } = options;\n this.#mapModel = mapModel;\n this.#maxResults = maxResults;\n this.#onError = onError;\n }\n\n destroy() {}\n\n async select(\n source: SelectionSource,\n extent: Extent\n ): Promise<SelectionSourceResults | undefined> {\n if (!extent) {\n return undefined;\n }\n\n return await this.#selectFromSource(source, extent);\n }\n\n async #selectFromSource(\n source: SelectionSource,\n extent: Extent\n ): Promise<SelectionSourceResults | undefined> {\n const projection = this.#mapModel.olMap.getView().getProjection();\n try {\n LOG.debug(`Starting selection on source '${source.label}'`);\n\n const maxResults = this.#maxResults;\n let results = await source.select(\n { type: \"extent\", extent },\n {\n maxResults,\n mapProjection: projection,\n signal: new AbortController().signal // currently not used\n }\n );\n if (results.length > maxResults) {\n results = results.slice(0, maxResults);\n }\n\n LOG.debug(`Found ${results.length} results on source '${source.label}'`);\n return { source: source, results: results };\n } catch (e) {\n LOG.error(`selection from source ${source.label} failed`, e);\n this.#onError();\n return undefined;\n }\n }\n}\n"],"names":[],"mappings":";;;AASA,MAAM,GAAA,GAAM,aAAa,QAAQ,CAAA;AAUjC,MAAM,mBAAA,GAAsB,GAAA;AAErB,MAAM,mBAAA,CAAoB;AAAA,EAC7B,SAAA;AAAA;AAAA;AAAA;AAAA,EAKS,WAAA;AAAA;AAAA;AAAA;AAAA,EAKA,QAAA;AAAA,EAET,YAAY,OAAA,EAA2E;AACnF,IAAA,MAAM,EAAE,QAAA,EAAU,OAAA,EAAS,UAAA,GAAa,qBAAoB,GAAI,OAAA;AAChE,IAAA,IAAA,CAAK,SAAA,GAAY,QAAA;AACjB,IAAA,IAAA,CAAK,WAAA,GAAc,UAAA;AACnB,IAAA,IAAA,CAAK,QAAA,GAAW,OAAA;AAAA,EACpB;AAAA,EAEA,OAAA,GAAU;AAAA,EAAC;AAAA,EAEX,MAAM,MAAA,CACF,MAAA,EACA,MAAA,EAC2C;AAC3C,IAAA,IAAI,CAAC,MAAA,EAAQ;AACT,MAAA,OAAO,MAAA;AAAA,IACX;AAEA,IAAA,OAAO,MAAM,IAAA,CAAK,iBAAA,CAAkB,MAAA,EAAQ,MAAM,CAAA;AAAA,EACtD;AAAA,EAEA,MAAM,iBAAA,CACF,MAAA,EACA,MAAA,EAC2C;AAC3C,IAAA,MAAM,aAAa,IAAA,CAAK,SAAA,CAAU,KAAA,CAAM,OAAA,GAAU,aAAA,EAAc;AAChE,IAAA,IAAI;AACA,MAAA,GAAA,CAAI,KAAA,CAAM,CAAA,8BAAA,EAAiC,MAAA,CAAO,KAAK,CAAA,CAAA,CAAG,CAAA;AAE1D,MAAA,MAAM,aAAa,IAAA,CAAK,WAAA;AACxB,MAAA,IAAI,OAAA,GAAU,MAAM,MAAA,CAAO,MAAA;AAAA,QACvB,EAAE,IAAA,EAAM,QAAA,EAAU,MAAA,EAAO;AAAA,QACzB;AAAA,UACI,UAAA;AAAA,UACA,aAAA,EAAe,UAAA;AAAA,UACf,MAAA,EAAQ,IAAI,eAAA,EAAgB,CAAE;AAAA;AAAA;AAClC,OACJ;AACA,MAAA,IAAI,OAAA,CAAQ,SAAS,UAAA,EAAY;AAC7B,QAAA,OAAA,GAAU,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,UAAU,CAAA;AAAA,MACzC;AAEA,MAAA,GAAA,CAAI,MAAM,CAAA,MAAA,EAAS,OAAA,CAAQ,MAAM,CAAA,oBAAA,EAAuB,MAAA,CAAO,KAAK,CAAA,CAAA,CAAG,CAAA;AACvE,MAAA,OAAO,EAAE,QAAgB,OAAA,EAAiB;AAAA,IAC9C,SAAS,CAAA,EAAG;AACR,MAAA,GAAA,CAAI,KAAA,CAAM,CAAA,sBAAA,EAAyB,MAAA,CAAO,KAAK,WAAW,CAAC,CAAA;AAC3D,MAAA,IAAA,CAAK,QAAA,EAAS;AACd,MAAA,OAAO,MAAA;AAAA,IACX;AAAA,EACJ;AACJ;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"VectorSelectionSource.js","sources":["VectorSelectionSource.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\n\nimport { computed, reactive, ReadonlyReactive } from \"@conterra/reactivity-core\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport { EventsKey } from \"ol/events\";\nimport Feature from \"ol/Feature\";\nimport VectorLayer from \"ol/layer/Vector\";\nimport { unByKey } from \"ol/Observable\";\nimport VectorSource from \"ol/source/Vector\";\nimport { v4 as uuid4v } from \"uuid\";\nimport {\n SelectionResult,\n SelectionOptions,\n SelectionKind,\n VectorLayerSelectionSource,\n SelectionSourceStatusObject\n} from \"./api\";\n\n/**\n * A SelectionSource to use an OpenLayers VectorLayer with an OpenLayers VectorSource (e.g. layer of the map).\n * Features are:\n * - using only the extent as selection kind\n * - listening to layer visibility changes and updating the status of the source\n * - limiting the number of returned selection results to the corresponding selection option\n * - throwing an event `changed:status` when the status updates\n */\nexport class VectorLayerSelectionSourceImpl implements VectorLayerSelectionSource {\n readonly label: string;\n #vectorLayer: VectorLayer<VectorSource, Feature>;\n #eventHandler: EventsKey;\n #currentIntl: ReadonlyReactive<PackageIntl>;\n #layerVisible = reactive<boolean>(true);\n #status: ReadonlyReactive<SelectionSourceStatusObject>;\n\n constructor(\n vectorLayer: VectorLayer<VectorSource, Feature>,\n label: string,\n currentIntl: ReadonlyReactive<PackageIntl>\n ) {\n this.label = label;\n this.#vectorLayer = vectorLayer;\n this.#currentIntl = currentIntl;\n this.#layerVisible.value = vectorLayer.getVisible();\n this.#status = computed<SelectionSourceStatusObject>(() =>\n this.#layerVisible.value\n ? { kind: \"available\" }\n : {\n kind: \"unavailable\",\n reason: this.#currentIntl.value.formatMessage({ id: \"layerNotVisibleReason\" })\n }\n );\n this.#eventHandler = this.#vectorLayer.on(\"change:visible\", () => {\n this.#layerVisible.value = this.#vectorLayer.getVisible();\n });\n }\n\n destroy() {\n unByKey(this.#eventHandler);\n }\n\n get status() {\n return this.#status.value;\n }\n\n async select(\n selectionKind: SelectionKind,\n options: SelectionOptions\n ): Promise<SelectionResult[]> {\n if (selectionKind.type !== \"extent\") {\n throw new Error(`Unsupported selection kind: ${selectionKind.type}`);\n }\n\n if (this.#status.value.kind !== \"available\" || this.#vectorLayer.getSource() === null)\n return [];\n\n const allResults: SelectionResult[] = [];\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.#vectorLayer\n .getSource()!\n .forEachFeatureIntersectingExtent(selectionKind.extent, (feature) => {\n if (!feature.getGeometry()) return;\n\n // TODO: Think about where to implement Date-Formatting, if the dates are already\n // encoded as Strings...\n\n const filteredProperties = { ...feature.getProperties() };\n delete filteredProperties.geometries;\n\n const result: SelectionResult = {\n id: feature.getId()?.toString() || uuid4v(),\n // oxlint-disable-next-line @typescript-eslint/no-non-null-assertion\n geometry: feature.getGeometry()!,\n properties: filteredProperties\n };\n\n allResults.push(result);\n });\n const selectedFeatures = allResults.filter((s): s is SelectionResult => s != null);\n const limitedFeatures =\n selectedFeatures.length > options.maxResults\n ? selectedFeatures.slice(0, options.maxResults)\n : selectedFeatures;\n return limitedFeatures;\n }\n}\n"],"names":["uuid4v"],"mappings":";;;;AA2BO,MAAM,8BAAA,CAAqE;AAAA,EACrE,KAAA;AAAA,EACT,YAAA;AAAA,EACA,aAAA;AAAA,EACA,YAAA;AAAA,EACA,aAAA,GAAgB,SAAkB,IAAI,CAAA;AAAA,EACtC,OAAA;AAAA,EAEA,WAAA,CACI,WAAA,EACA,KAAA,EACA,WAAA,EACF;AACE,IAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,IAAA,IAAA,CAAK,YAAA,GAAe,WAAA;AACpB,IAAA,IAAA,CAAK,YAAA,GAAe,WAAA;AACpB,IAAA,IAAA,CAAK,aAAA,CAAc,KAAA,GAAQ,WAAA,CAAY,UAAA,EAAW;AAClD,IAAA,IAAA,CAAK,OAAA,GAAU,QAAA;AAAA,MAAsC,MACjD,IAAA,CAAK,aAAA,CAAc,QACb,EAAE,IAAA,EAAM,aAAY,GACpB;AAAA,QACI,IAAA,EAAM,aAAA;AAAA,QACN,MAAA,EAAQ,KAAK,YAAA,CAAa,KAAA,CAAM,cAAc,EAAE,EAAA,EAAI,yBAAyB;AAAA;AACjF,KACV;AACA,IAAA,IAAA,CAAK,aAAA,GAAgB,IAAA,CAAK,YAAA,CAAa,EAAA,CAAG,kBAAkB,MAAM;AAC9D,MAAA,IAAA,CAAK,aAAA,CAAc,KAAA,GAAQ,IAAA,CAAK,YAAA,CAAa,UAAA,EAAW;AAAA,IAC5D,CAAC,CAAA;AAAA,EACL;AAAA,EAEA,OAAA,GAAU;AACN,IAAA,OAAA,CAA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