@open-pioneer/spatial-bookmarks 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,17 @@
1
+ # @open-pioneer/spatial-bookmarks
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 3ca8a25: Initial release
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [08bffbc]
12
+ - Updated dependencies [a58546b]
13
+ - Updated dependencies [3ca8a25]
14
+ - Updated dependencies [a58546b]
15
+ - Updated dependencies [0c4ce04]
16
+ - @open-pioneer/map@0.1.1
17
+ - @open-pioneer/local-storage@0.1.0
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,18 @@
1
+ # @open-pioneer/spatial-bookmarks
2
+
3
+ This package provides a UI component that allows the user to store, manage, and easily navigate between different map extents by creating bookmarks. The bookmarks are stored locally in the browser's local storage.
4
+
5
+ The UI presents a list view that displays stored bookmarks and allows the user to easily interact with them. The widget contains an input field that allows the user to create a bookmark with the given name.
6
+ Users can also delete individual bookmarks directly from the list.
7
+
8
+ ## Usage
9
+
10
+ To integrate the spatial bookmarks component in your app, insert the following snippet and reference a map ID:
11
+
12
+ ```tsx
13
+ <SpatialBookmarks mapId={MAP_ID} />
14
+ ```
15
+
16
+ ## License
17
+
18
+ Apache-2.0 (see `LICENSE` file)
@@ -0,0 +1,12 @@
1
+ import { CommonComponentProps } from "@open-pioneer/react-utils";
2
+ import { FC } from "react";
3
+ export interface SpatialBookmarksProps extends CommonComponentProps {
4
+ /**
5
+ * The id of the map.
6
+ */
7
+ mapId: string;
8
+ }
9
+ /**
10
+ * A component that allows the user to manage a set of spatial bookmarks.
11
+ */
12
+ export declare const SpatialBookmarks: FC<SpatialBookmarksProps>;
@@ -0,0 +1,290 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { Flex, VStack, Alert, AlertIcon, Input, List, Box, Center, Text, Spacer, Tooltip, Button } from '@open-pioneer/chakra-integration';
3
+ import { useMapModel } from '@open-pioneer/map';
4
+ import { useCommonComponentProps } from '@open-pioneer/react-utils';
5
+ import classNames from 'classnames';
6
+ import { Provider, useAtomValue } from 'jotai';
7
+ import { useService, useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
8
+ import { useRef, useState, useEffect } from 'react';
9
+ import { PiMapTrifold, PiTrashSimpleLight } from 'react-icons/pi';
10
+ import { SpatialBookmarkViewModel } from './SpatialBookmarksViewModel.js';
11
+
12
+ const SpatialBookmarks = (props) => {
13
+ const { map } = useMapModel(props.mapId);
14
+ const localStorageService = useService(
15
+ "local-storage.LocalStorageService"
16
+ );
17
+ const viewModel = useViewModel(map, localStorageService);
18
+ return viewModel && // Makes the store accessible to useAtom() etc. in the UI
19
+ /* @__PURE__ */ jsx(Provider, { store: viewModel.store, children: /* @__PURE__ */ jsx(SpatialBookmarkUI, { ...props, viewModel }) });
20
+ };
21
+ function SpatialBookmarkUI(props) {
22
+ const { viewModel } = props;
23
+ const intl = useIntl();
24
+ const listItemNodes = useRef([]);
25
+ const [scrollToLastItem, setScrollToLastItem] = useState(false);
26
+ const bookmarks = useAtomValue(viewModel.bookmarks);
27
+ const [bookmarkName, setBookmarkName] = useState("");
28
+ const isValidBookmarkName = bookmarkName.trim().length > 0;
29
+ const { containerProps } = useCommonComponentProps("spatial-bookmarks", props);
30
+ const [uiMode, setUiMode] = useState("list");
31
+ const clearBookmarks = () => {
32
+ viewModel.deleteAllBookmarks();
33
+ setUiMode("list");
34
+ };
35
+ const addBookmark = () => {
36
+ if (isValidBookmarkName) {
37
+ viewModel.createBookmark(bookmarkName);
38
+ setUiMode("list");
39
+ setBookmarkName("");
40
+ setScrollToLastItem(true);
41
+ }
42
+ };
43
+ useEffect(() => {
44
+ if (scrollToLastItem) {
45
+ const listItems = listItemNodes.current;
46
+ if (listItems) {
47
+ const lastItem = listItems[bookmarks.length - 1];
48
+ lastItem?.scrollIntoView?.();
49
+ }
50
+ setScrollToLastItem(false);
51
+ }
52
+ }, [bookmarks, scrollToLastItem]);
53
+ const deleteContent = () => /* @__PURE__ */ jsxs(VStack, { children: [
54
+ /* @__PURE__ */ jsxs(Alert, { rounded: "md", status: "warning", children: [
55
+ /* @__PURE__ */ jsx(AlertIcon, {}),
56
+ intl.formatMessage({ id: "bookmark.alert.delete" })
57
+ ] }),
58
+ /* @__PURE__ */ jsx(
59
+ RemoveControls,
60
+ {
61
+ intl,
62
+ onClear: clearBookmarks,
63
+ onCancel: () => setUiMode("list")
64
+ }
65
+ )
66
+ ] });
67
+ const createContent = () => /* @__PURE__ */ jsxs(VStack, { children: [
68
+ /* @__PURE__ */ jsxs(Alert, { rounded: "md", status: "info", children: [
69
+ /* @__PURE__ */ jsx(AlertIcon, {}),
70
+ intl.formatMessage({ id: "bookmark.alert.create" })
71
+ ] }),
72
+ /* @__PURE__ */ jsx(
73
+ Input,
74
+ {
75
+ "aria-label": intl.formatMessage({ id: "bookmark.input.label" }),
76
+ placeholder: intl.formatMessage({ id: "bookmark.input.placeholder" }),
77
+ value: bookmarkName,
78
+ onChange: (event) => {
79
+ setBookmarkName(event.target.value);
80
+ },
81
+ onKeyDown: (e) => {
82
+ if (e.key === "Enter") {
83
+ addBookmark();
84
+ }
85
+ },
86
+ isRequired: true,
87
+ isInvalid: !isValidBookmarkName,
88
+ autoFocus: true
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsx(
92
+ CreateControls,
93
+ {
94
+ intl,
95
+ isInvalid: !isValidBookmarkName,
96
+ onCancel: () => {
97
+ setBookmarkName("");
98
+ setUiMode("list");
99
+ },
100
+ onSave: addBookmark
101
+ }
102
+ )
103
+ ] });
104
+ const listContent = () => /* @__PURE__ */ jsxs(Fragment, { children: [
105
+ bookmarks.length ? createList(bookmarks, viewModel, intl, listItemNodes) : /* @__PURE__ */ jsxs(Alert, { rounded: "md", status: "info", children: [
106
+ /* @__PURE__ */ jsx(AlertIcon, {}),
107
+ intl.formatMessage({ id: "bookmark.alert.noSaved" })
108
+ ] }),
109
+ /* @__PURE__ */ jsx(
110
+ ListControls,
111
+ {
112
+ intl,
113
+ bookmarks,
114
+ showCreate: () => setUiMode("create"),
115
+ showDelete: () => setUiMode("delete")
116
+ }
117
+ )
118
+ ] });
119
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
120
+ uiMode === "list" && listContent(),
121
+ uiMode === "create" && createContent(),
122
+ uiMode === "delete" && deleteContent()
123
+ ] });
124
+ return /* @__PURE__ */ jsx(Flex, { flexDirection: "column", ...containerProps, children: content });
125
+ }
126
+ function createList(bookmarks, viewModel, intl, listRef) {
127
+ const deleteBtnLabel = intl.formatMessage({
128
+ id: "bookmark.button.deleteOne"
129
+ });
130
+ const bookmarkItems = bookmarks.map((bookmark, idx) => /* @__PURE__ */ jsx(
131
+ BookmarkItem,
132
+ {
133
+ index: idx,
134
+ listItemNodes: listRef,
135
+ bookmark,
136
+ onActivate: () => viewModel.activateBookmark(bookmark),
137
+ onDelete: () => viewModel.deleteBookmark(bookmark.id),
138
+ deleteBtnLabel
139
+ },
140
+ bookmark.id
141
+ ));
142
+ return /* @__PURE__ */ jsx(
143
+ List,
144
+ {
145
+ as: "ul",
146
+ className: "spatial-bookmark-list",
147
+ role: "listbox",
148
+ "aria-label": intl.formatMessage({
149
+ id: "bookmark.list.label"
150
+ }),
151
+ flexShrink: 1,
152
+ flexGrow: 1,
153
+ p: 1,
154
+ spacing: 1,
155
+ overflowY: "auto",
156
+ listStyleType: "none",
157
+ children: bookmarkItems
158
+ }
159
+ );
160
+ }
161
+ const ARROW_INDEX_MAP = {
162
+ ArrowDown: 1,
163
+ ArrowUp: -1
164
+ };
165
+ function BookmarkItem(props) {
166
+ const { index, listItemNodes, bookmark, onDelete, onActivate, deleteBtnLabel } = props;
167
+ const title = bookmark.title;
168
+ const onKeyDown = (evt) => {
169
+ const key = evt.key;
170
+ if (key === "Enter") {
171
+ if (evt.target === evt.currentTarget) {
172
+ onActivate();
173
+ }
174
+ return;
175
+ }
176
+ if (ARROW_INDEX_MAP[key] != null) {
177
+ const len = listItemNodes.current?.length;
178
+ if (!len) {
179
+ return;
180
+ }
181
+ let nextIndex = (index + ARROW_INDEX_MAP[key]) % len;
182
+ if (nextIndex < 0) {
183
+ nextIndex = len - 1;
184
+ }
185
+ listItemNodes.current[nextIndex]?.focus();
186
+ }
187
+ };
188
+ return /* @__PURE__ */ jsx(
189
+ Box,
190
+ {
191
+ as: "li",
192
+ p: 1,
193
+ ref: (el) => {
194
+ if (!el) {
195
+ listItemNodes.current.splice(index, 1);
196
+ return;
197
+ }
198
+ listItemNodes.current[index] = el;
199
+ },
200
+ className: classNames("spatial-bookmarks-item"),
201
+ tabIndex: 0,
202
+ rounded: "md",
203
+ role: "option",
204
+ cursor: "pointer",
205
+ outline: 0,
206
+ _hover: { background: "trails.50" },
207
+ _focusVisible: { boxShadow: "outline" },
208
+ onKeyDown,
209
+ onClick: onActivate,
210
+ children: /* @__PURE__ */ jsxs(Flex, { width: "100%", flexDirection: "row", align: "center", gap: 1, children: [
211
+ /* @__PURE__ */ jsx(Center, { children: /* @__PURE__ */ jsx(PiMapTrifold, {}) }),
212
+ /* @__PURE__ */ jsx(Text, { ps: 2, noOfLines: 1, children: title }),
213
+ /* @__PURE__ */ jsx(Spacer, {}),
214
+ /* @__PURE__ */ jsx(Tooltip, { hasArrow: true, label: deleteBtnLabel, placement: "right", children: /* @__PURE__ */ jsx(
215
+ Button,
216
+ {
217
+ className: "spatial-bookmarks-item-delete",
218
+ "aria-label": deleteBtnLabel,
219
+ borderRadius: "full",
220
+ iconSpacing: 0,
221
+ padding: 0,
222
+ colorScheme: "red",
223
+ variant: "ghost",
224
+ leftIcon: /* @__PURE__ */ jsx(PiTrashSimpleLight, {}),
225
+ onClick: (event) => {
226
+ onDelete();
227
+ event.stopPropagation();
228
+ }
229
+ }
230
+ ) }, index)
231
+ ] })
232
+ }
233
+ );
234
+ }
235
+ function ListControls(props) {
236
+ const { intl, bookmarks, showCreate, showDelete } = props;
237
+ return /* @__PURE__ */ jsxs(ButtonContainer, { children: [
238
+ /* @__PURE__ */ jsx(
239
+ DialogButton,
240
+ {
241
+ isDisabled: bookmarks.length === 0,
242
+ colorScheme: "red",
243
+ width: void 0,
244
+ iconSpacing: 0,
245
+ leftIcon: /* @__PURE__ */ jsx(PiTrashSimpleLight, {}),
246
+ onClick: showDelete,
247
+ "aria-label": intl.formatMessage({ id: "bookmark.button.deleteAll" }),
248
+ variant: "outline"
249
+ }
250
+ ),
251
+ /* @__PURE__ */ jsx(DialogButton, { onClick: showCreate, width: "100%", children: intl.formatMessage({ id: "bookmark.button.create" }) })
252
+ ] });
253
+ }
254
+ function RemoveControls(props) {
255
+ const { intl, onCancel, onClear } = props;
256
+ return /* @__PURE__ */ jsxs(ButtonContainer, { children: [
257
+ /* @__PURE__ */ jsx(DialogButton, { variant: "outline", onClick: onCancel, children: intl.formatMessage({ id: "bookmark.button.cancelDelete" }) }),
258
+ /* @__PURE__ */ jsx(DialogButton, { onClick: onClear, children: intl.formatMessage({ id: "bookmark.button.confirmDelete" }) })
259
+ ] });
260
+ }
261
+ function CreateControls(props) {
262
+ const { intl, onCancel, onSave, isInvalid } = props;
263
+ return /* @__PURE__ */ jsxs(ButtonContainer, { children: [
264
+ /* @__PURE__ */ jsx(DialogButton, { variant: "outline", onClick: () => onCancel(), children: intl.formatMessage({ id: "bookmark.button.cancel" }) }),
265
+ /* @__PURE__ */ jsx(DialogButton, { isDisabled: isInvalid, onClick: () => onSave(), children: intl.formatMessage({ id: "bookmark.button.save" }) })
266
+ ] });
267
+ }
268
+ function ButtonContainer(props) {
269
+ return /* @__PURE__ */ jsx(Flex, { width: "100%", flexDirection: "row", mt: 2, gap: 1, flexGrow: 0, flexShrink: 0, children: props.children });
270
+ }
271
+ function DialogButton(props) {
272
+ return /* @__PURE__ */ jsx(Button, { width: "100%", ...props });
273
+ }
274
+ function useViewModel(map, localStorageService) {
275
+ const [viewModel, setViewModel] = useState();
276
+ useEffect(() => {
277
+ let viewModel2;
278
+ if (!map) {
279
+ viewModel2 = void 0;
280
+ } else {
281
+ viewModel2 = new SpatialBookmarkViewModel(map, localStorageService);
282
+ }
283
+ setViewModel(viewModel2);
284
+ return () => viewModel2?.destroy();
285
+ }, [map, localStorageService]);
286
+ return viewModel;
287
+ }
288
+
289
+ export { SpatialBookmarks };
290
+ //# sourceMappingURL=SpatialBookmarks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialBookmarks.js","sources":["SpatialBookmarks.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport {\n Alert,\n AlertIcon,\n Box,\n Button,\n ButtonProps,\n Flex,\n Input,\n List,\n Spacer,\n Text,\n Tooltip,\n VStack,\n Center\n} from \"@open-pioneer/chakra-integration\";\nimport { LocalStorageService } from \"@open-pioneer/local-storage\";\nimport { MapModel, useMapModel } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { PackageIntl } from \"@open-pioneer/runtime\";\nimport classNames from \"classnames\";\nimport { Provider as JotaiProvider, useAtomValue } from \"jotai\";\nimport { useIntl, useService } from \"open-pioneer:react-hooks\";\nimport { FC, KeyboardEvent, ReactNode, useEffect, useRef, useState } from \"react\";\nimport { PiMapTrifold, PiTrashSimpleLight } from \"react-icons/pi\";\nimport { Bookmark, SpatialBookmarkViewModel } from \"./SpatialBookmarksViewModel\";\n\ntype UIMode = \"list\" | \"create\" | \"delete\";\n\nexport interface SpatialBookmarksProps extends CommonComponentProps {\n /**\n * The id of the map.\n */\n mapId: string;\n}\n\n/**\n * A component that allows the user to manage a set of spatial bookmarks.\n */\nexport const SpatialBookmarks: FC<SpatialBookmarksProps> = (props) => {\n const { map } = useMapModel(props.mapId);\n const localStorageService = useService<LocalStorageService>(\n \"local-storage.LocalStorageService\"\n );\n const viewModel = useViewModel(map, localStorageService);\n return (\n viewModel && (\n // Makes the store accessible to useAtom() etc. in the UI\n <JotaiProvider store={viewModel.store}>\n <SpatialBookmarkUI {...props} viewModel={viewModel} />\n </JotaiProvider>\n )\n );\n};\n\nfunction SpatialBookmarkUI(props: SpatialBookmarksProps & { viewModel: SpatialBookmarkViewModel }) {\n const { viewModel } = props;\n const intl = useIntl();\n const listItemNodes = useRef<HTMLElement[]>([]);\n const [scrollToLastItem, setScrollToLastItem] = useState(false);\n\n const bookmarks = useAtomValue(viewModel.bookmarks);\n const [bookmarkName, setBookmarkName] = useState<string>(\"\");\n const isValidBookmarkName = bookmarkName.trim().length > 0; // use trim to avoid bookmarks with space character only\n const { containerProps } = useCommonComponentProps(\"spatial-bookmarks\", props);\n const [uiMode, setUiMode] = useState<UIMode>(\"list\");\n\n const clearBookmarks = () => {\n viewModel.deleteAllBookmarks();\n setUiMode(\"list\");\n };\n\n const addBookmark = () => {\n if (isValidBookmarkName) {\n viewModel.createBookmark(bookmarkName);\n setUiMode(\"list\");\n setBookmarkName(\"\");\n setScrollToLastItem(true);\n }\n };\n\n // Scroll to newly created bookmark after render\n useEffect(() => {\n if (scrollToLastItem) {\n const listItems = listItemNodes.current;\n if (listItems) {\n const lastItem = listItems[bookmarks.length - 1];\n lastItem?.scrollIntoView?.();\n }\n setScrollToLastItem(false);\n }\n }, [bookmarks, scrollToLastItem]);\n\n const deleteContent = () => (\n <VStack>\n <Alert rounded=\"md\" status=\"warning\">\n <AlertIcon />\n {intl.formatMessage({ id: \"bookmark.alert.delete\" })}\n </Alert>\n <RemoveControls\n intl={intl}\n onClear={clearBookmarks}\n onCancel={() => setUiMode(\"list\")}\n />\n </VStack>\n );\n\n const createContent = () => (\n <VStack>\n <Alert rounded=\"md\" status=\"info\">\n <AlertIcon />\n {intl.formatMessage({ id: \"bookmark.alert.create\" })}\n </Alert>\n <Input\n aria-label={intl.formatMessage({ id: \"bookmark.input.label\" })}\n placeholder={intl.formatMessage({ id: \"bookmark.input.placeholder\" })}\n value={bookmarkName}\n onChange={(event) => {\n setBookmarkName(event.target.value);\n }}\n onKeyDown={(e) => {\n // add bookmark only, if valid bookmark name exists\n if (e.key === \"Enter\") {\n addBookmark();\n }\n }}\n isRequired\n isInvalid={!isValidBookmarkName}\n autoFocus // eslint-disable-line jsx-a11y/no-autofocus\n />\n <CreateControls\n intl={intl}\n isInvalid={!isValidBookmarkName}\n onCancel={() => {\n setBookmarkName(\"\");\n setUiMode(\"list\");\n }}\n onSave={addBookmark}\n />\n </VStack>\n );\n\n const listContent = () => (\n <>\n {bookmarks.length ? (\n createList(bookmarks, viewModel, intl, listItemNodes)\n ) : (\n <Alert rounded=\"md\" status=\"info\">\n <AlertIcon />\n {intl.formatMessage({ id: \"bookmark.alert.noSaved\" })}\n </Alert>\n )}\n <ListControls\n intl={intl}\n bookmarks={bookmarks}\n showCreate={() => setUiMode(\"create\")}\n showDelete={() => setUiMode(\"delete\")}\n />\n </>\n );\n\n const content = (\n <>\n {uiMode === \"list\" && listContent()}\n {uiMode === \"create\" && createContent()}\n {uiMode === \"delete\" && deleteContent()}\n </>\n );\n\n return (\n <Flex flexDirection=\"column\" {...containerProps}>\n {content}\n </Flex>\n );\n}\n\nfunction createList(\n bookmarks: Bookmark[],\n viewModel: SpatialBookmarkViewModel,\n intl: PackageIntl,\n listRef: React.MutableRefObject<HTMLElement[]>\n) {\n const deleteBtnLabel = intl.formatMessage({\n id: \"bookmark.button.deleteOne\"\n });\n\n const bookmarkItems = bookmarks.map((bookmark, idx) => (\n <BookmarkItem\n key={bookmark.id}\n index={idx}\n listItemNodes={listRef}\n bookmark={bookmark}\n onActivate={() => viewModel.activateBookmark(bookmark)}\n onDelete={() => viewModel.deleteBookmark(bookmark.id)}\n deleteBtnLabel={deleteBtnLabel}\n />\n ));\n\n return (\n <List\n as=\"ul\"\n className=\"spatial-bookmark-list\"\n role=\"listbox\"\n aria-label={intl.formatMessage({\n id: \"bookmark.list.label\"\n })}\n flexShrink={1}\n flexGrow={1}\n p={1} // Some padding for children's box shadow\n spacing={1}\n overflowY=\"auto\"\n listStyleType=\"none\"\n >\n {bookmarkItems}\n </List>\n );\n}\n\n// key name -> index\nconst ARROW_INDEX_MAP: Record<string, number> = {\n ArrowDown: 1,\n ArrowUp: -1\n};\n\nfunction BookmarkItem(props: {\n index: number;\n listItemNodes: React.MutableRefObject<HTMLElement[]>;\n bookmark: Bookmark;\n onActivate: () => void;\n onDelete: () => void;\n deleteBtnLabel: string;\n}): JSX.Element {\n const { index, listItemNodes, bookmark, onDelete, onActivate, deleteBtnLabel } = props;\n const title = bookmark.title;\n const onKeyDown = (evt: KeyboardEvent) => {\n const key = evt.key;\n if (key === \"Enter\") {\n // Ignore enter from child components (buttons)\n if (evt.target === evt.currentTarget) {\n onActivate();\n }\n return;\n }\n\n if (ARROW_INDEX_MAP[key] != null) {\n const len = listItemNodes.current?.length;\n if (!len) {\n return;\n }\n\n let nextIndex = (index + ARROW_INDEX_MAP[key]!) % len;\n if (nextIndex < 0) {\n nextIndex = len - 1;\n }\n listItemNodes.current[nextIndex]?.focus();\n }\n };\n return (\n <Box\n as=\"li\"\n p={1}\n ref={(el: HTMLDivElement | null) => {\n if (!el) {\n listItemNodes.current.splice(index, 1);\n return;\n }\n listItemNodes.current[index] = el;\n }}\n className={classNames(\"spatial-bookmarks-item\")}\n tabIndex={0}\n rounded=\"md\"\n role=\"option\"\n cursor=\"pointer\"\n outline={0}\n _hover={{ background: \"trails.50\" }}\n _focusVisible={{ boxShadow: \"outline\" }}\n onKeyDown={onKeyDown}\n onClick={onActivate}\n >\n <Flex width=\"100%\" flexDirection=\"row\" align=\"center\" gap={1}>\n <Center>\n <PiMapTrifold />\n </Center>\n <Text ps={2} noOfLines={1}>\n {title}\n </Text>\n <Spacer />\n <Tooltip key={index} hasArrow label={deleteBtnLabel} placement=\"right\">\n <Button\n className=\"spatial-bookmarks-item-delete\"\n aria-label={deleteBtnLabel}\n borderRadius=\"full\"\n iconSpacing={0}\n padding={0}\n colorScheme=\"red\"\n variant=\"ghost\"\n leftIcon={<PiTrashSimpleLight />}\n onClick={(event) => {\n onDelete();\n event.stopPropagation();\n }}\n />\n </Tooltip>\n </Flex>\n </Box>\n );\n}\n\nfunction ListControls(props: {\n intl: PackageIntl;\n bookmarks: Bookmark[];\n showCreate: () => void;\n showDelete: () => void;\n}): JSX.Element {\n const { intl, bookmarks, showCreate, showDelete } = props;\n\n return (\n <ButtonContainer>\n <DialogButton\n isDisabled={bookmarks.length === 0}\n colorScheme=\"red\"\n width={undefined}\n iconSpacing={0}\n leftIcon={<PiTrashSimpleLight />}\n onClick={showDelete}\n aria-label={intl.formatMessage({ id: \"bookmark.button.deleteAll\" })}\n variant=\"outline\"\n />\n <DialogButton onClick={showCreate} width=\"100%\">\n {intl.formatMessage({ id: \"bookmark.button.create\" })}\n </DialogButton>\n </ButtonContainer>\n );\n}\n\nfunction RemoveControls(props: { intl: PackageIntl; onClear: () => void; onCancel: () => void }) {\n const { intl, onCancel, onClear } = props;\n return (\n <ButtonContainer>\n <DialogButton variant=\"outline\" onClick={onCancel}>\n {intl.formatMessage({ id: \"bookmark.button.cancelDelete\" })}\n </DialogButton>\n <DialogButton onClick={onClear}>\n {intl.formatMessage({ id: \"bookmark.button.confirmDelete\" })}\n </DialogButton>\n </ButtonContainer>\n );\n}\n\nfunction CreateControls(props: {\n intl: PackageIntl;\n isInvalid: boolean;\n onCancel: () => void;\n onSave: () => void;\n}) {\n const { intl, onCancel, onSave, isInvalid } = props;\n return (\n <ButtonContainer>\n <DialogButton variant=\"outline\" onClick={() => onCancel()}>\n {intl.formatMessage({ id: \"bookmark.button.cancel\" })}\n </DialogButton>\n <DialogButton isDisabled={isInvalid} onClick={() => onSave()}>\n {intl.formatMessage({ id: \"bookmark.button.save\" })}\n </DialogButton>\n </ButtonContainer>\n );\n}\n\nfunction ButtonContainer(props: { children: ReactNode }) {\n return (\n <Flex width=\"100%\" flexDirection=\"row\" mt={2} gap={1} flexGrow={0} flexShrink={0}>\n {props.children}\n </Flex>\n );\n}\n\nfunction DialogButton(props?: ButtonProps): JSX.Element {\n return <Button width=\"100%\" {...props} />;\n}\n\nfunction useViewModel(map: MapModel | undefined, localStorageService: LocalStorageService) {\n const [viewModel, setViewModel] = useState<SpatialBookmarkViewModel>();\n useEffect(() => {\n let viewModel: SpatialBookmarkViewModel | undefined;\n if (!map) {\n viewModel = undefined;\n } else {\n viewModel = new SpatialBookmarkViewModel(map, localStorageService);\n }\n\n setViewModel(viewModel);\n return () => viewModel?.destroy();\n }, [map, localStorageService]);\n\n return viewModel;\n}\n"],"names":["JotaiProvider","viewModel"],"mappings":";;;;;;;;;;;AAwCa,MAAA,gBAAA,GAA8C,CAAC,KAAU,KAAA;AAClE,EAAA,MAAM,EAAE,GAAA,EAAQ,GAAA,WAAA,CAAY,MAAM,KAAK,CAAA,CAAA;AACvC,EAAA,MAAM,mBAAsB,GAAA,UAAA;AAAA,IACxB,mCAAA;AAAA,GACJ,CAAA;AACA,EAAM,MAAA,SAAA,GAAY,YAAa,CAAA,GAAA,EAAK,mBAAmB,CAAA,CAAA;AACvD,EACI,OAAA,SAAA;AAAA,kBAEI,GAAA,CAACA,QAAc,EAAA,EAAA,KAAA,EAAO,SAAU,CAAA,KAAA,EAC5B,8BAAC,iBAAmB,EAAA,EAAA,GAAG,KAAO,EAAA,SAAA,EAAsB,CACxD,EAAA,CAAA,CAAA;AAGZ,EAAA;AAEA,SAAS,kBAAkB,KAAwE,EAAA;AAC/F,EAAM,MAAA,EAAE,WAAc,GAAA,KAAA,CAAA;AACtB,EAAA,MAAM,OAAO,OAAQ,EAAA,CAAA;AACrB,EAAM,MAAA,aAAA,GAAgB,MAAsB,CAAA,EAAE,CAAA,CAAA;AAC9C,EAAA,MAAM,CAAC,gBAAA,EAAkB,mBAAmB,CAAA,GAAI,SAAS,KAAK,CAAA,CAA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EAAA,GAAA,EAAK,GAAG,QAAU,EAAA,CAAA,EAAG,UAAY,EAAA,CAAA,EAC1E,gBAAM,QACX,EAAA,CAAA,CAAA;AAER,CAAA;AAEA,SAAS,aAAa,KAAkC,EAAA;AACpD,EAAA,uBAAQ,GAAA,CAAA,MAAA,EAAA,EAAO,KAAM,EAAA,MAAA,EAAQ,GAAG,KAAO,EAAA,CAAA,CAAA;AAC3C,CAAA;AAEA,SAAS,YAAA,CAAa,KAA2B,mBAA0C,EAAA;AACvF,EAAA,MAAM,CAAC,SAAA,EAAW,YAAY,CAAA,GAAI,QAAmC,EAAA,CAAA;AACrE,EAAA,SAAA,CAAU,MAAM;AACZ,IAAIC,IAAAA,UAAAA,CAAAA;AACJ,IAAA,IAAI,CAAC,GAAK,EAAA;AACN,MAAAA,UAAY,GAAA,KAAA,CAAA,CAAA;AAAA,KACT,MAAA;AACH,MAAAA,UAAY,GAAA,IAAI,wBAAyB,CAAA,GAAA,EAAK,mBAAmB,CAAA,CAAA;AAAA,KACrE;AAEA,IAAA,YAAA,CAAaA,UAAS,CAAA,CAAA;AACtB,IAAO,OAAA,MAAMA,YAAW,OAAQ,EAAA,CAAA;AAAA,GACjC,EAAA,CAAC,GAAK,EAAA,mBAAmB,CAAC,CAAA,CAAA;AAE7B,EAAO,OAAA,SAAA,CAAA;AACX;;;;"}
@@ -0,0 +1,64 @@
1
+ import { MapModel } from "@open-pioneer/map";
2
+ import { Atom, createStore } from "jotai";
3
+ import { LocalStorageService } from "@open-pioneer/local-storage";
4
+ interface Extent {
5
+ minX: number;
6
+ minY: number;
7
+ maxX: number;
8
+ maxY: number;
9
+ }
10
+ export interface Bookmark {
11
+ id: string;
12
+ title: string;
13
+ extent: Extent;
14
+ projection: string;
15
+ }
16
+ type Store = ReturnType<typeof createStore>;
17
+ export declare class SpatialBookmarkViewModel {
18
+ private map;
19
+ private packageNamespace;
20
+ private writableBookmarks;
21
+ private stopBookmarksListener;
22
+ /** Contains the jotai state (atoms + store === value). */
23
+ readonly store: Store;
24
+ /**
25
+ * Provides read-only access to the bookmarks array.
26
+ * The UI simply renders the contents of the store and
27
+ * uses the methods below to modify the state.
28
+ */
29
+ get bookmarks(): Atom<Bookmark[]>;
30
+ constructor(map: MapModel, localStorageService: LocalStorageService);
31
+ destroy(): void;
32
+ /**
33
+ * Creates a new bookmark with the `title` provided by the UI.
34
+ * The current map extent is used for the new bookmark's extent.
35
+ */
36
+ createBookmark(title: string): void;
37
+ /**
38
+ * Activates the bookmark with the given id by zooming
39
+ * to the bookmark's extent.
40
+ */
41
+ activateBookmark(bookmark: Bookmark): void;
42
+ /**
43
+ * Deletes the bookmark with the given id.
44
+ */
45
+ deleteBookmark(id: string): void;
46
+ /**
47
+ * Deletes all bookmarks.
48
+ */
49
+ deleteAllBookmarks(): void;
50
+ /**
51
+ * Loads the bookmarks from local storage.
52
+ * If the bookmarks are not valid, the initial state (empty array) is restored.
53
+ */
54
+ private loadState;
55
+ /**
56
+ * Saves the bookmarks to local storage.
57
+ */
58
+ private saveState;
59
+ /** Computes an OpenLayers extent for the given bookmark. */
60
+ private getBookmarkExtent;
61
+ /** Moves the map to the given extent. */
62
+ private applyExtent;
63
+ }
64
+ export {};
@@ -0,0 +1,163 @@
1
+ import { atom, createStore } from 'jotai';
2
+ import { v4 } from 'uuid';
3
+ import { getCenter } from 'ol/extent';
4
+ import { transformExtent } from 'ol/proj';
5
+ import { createLogger } from '@open-pioneer/core';
6
+
7
+ const LOG = createLogger("spatial-bookmark:SpatialBookmarkViewModel");
8
+ class SpatialBookmarkViewModel {
9
+ map;
10
+ packageNamespace;
11
+ writableBookmarks = atom([]);
12
+ stopBookmarksListener;
13
+ /** Contains the jotai state (atoms + store === value). */
14
+ store;
15
+ // contains jotai state
16
+ /**
17
+ * Provides read-only access to the bookmarks array.
18
+ * The UI simply renders the contents of the store and
19
+ * uses the methods below to modify the state.
20
+ */
21
+ get bookmarks() {
22
+ return this.writableBookmarks;
23
+ }
24
+ constructor(map, localStorageService) {
25
+ this.map = map;
26
+ this.packageNamespace = localStorageService.getNamespace("spatial-bookmarks");
27
+ this.store = createStore();
28
+ this.loadState();
29
+ this.stopBookmarksListener = this.store.sub(this.bookmarks, () => {
30
+ this.saveState();
31
+ });
32
+ }
33
+ destroy() {
34
+ this.stopBookmarksListener();
35
+ }
36
+ /**
37
+ * Creates a new bookmark with the `title` provided by the UI.
38
+ * The current map extent is used for the new bookmark's extent.
39
+ */
40
+ createBookmark(title) {
41
+ const olMap = this.map.olMap;
42
+ const olExtent = olMap.getView().calculateExtent();
43
+ const projection = olMap.getView().getProjection().getCode();
44
+ const extent = {
45
+ minX: olExtent[0],
46
+ minY: olExtent[1],
47
+ maxX: olExtent[2],
48
+ maxY: olExtent[3]
49
+ };
50
+ const bookmark = {
51
+ id: v4(),
52
+ title,
53
+ extent,
54
+ projection
55
+ };
56
+ LOG.debug("Created a new bookmark", bookmark);
57
+ const bookmarks = this.writableBookmarks;
58
+ this.store.set(bookmarks, [...this.store.get(bookmarks), bookmark]);
59
+ }
60
+ /**
61
+ * Activates the bookmark with the given id by zooming
62
+ * to the bookmark's extent.
63
+ */
64
+ activateBookmark(bookmark) {
65
+ LOG.debug("Activating bookmark", bookmark);
66
+ const extent = this.getBookmarkExtent(bookmark);
67
+ LOG.debug("Attempting to apply extent", extent);
68
+ this.applyExtent(extent);
69
+ }
70
+ /**
71
+ * Deletes the bookmark with the given id.
72
+ */
73
+ deleteBookmark(id) {
74
+ LOG.debug("Deleting bookmark", id);
75
+ const bookmarks = this.writableBookmarks;
76
+ this.store.set(bookmarks, [...this.store.get(bookmarks).filter((b) => b.id !== id)]);
77
+ }
78
+ /**
79
+ * Deletes all bookmarks.
80
+ */
81
+ deleteAllBookmarks() {
82
+ LOG.debug("Deleting all bookmarks");
83
+ this.store.set(this.writableBookmarks, []);
84
+ }
85
+ /**
86
+ * Loads the bookmarks from local storage.
87
+ * If the bookmarks are not valid, the initial state (empty array) is restored.
88
+ */
89
+ loadState() {
90
+ LOG.debug("Restoring bookmarks from local storage");
91
+ const rawBookmarks = this.packageNamespace.get("bookmarks") ?? [];
92
+ try {
93
+ validateBookmarks(rawBookmarks);
94
+ this.store.set(this.writableBookmarks, rawBookmarks);
95
+ } catch (e) {
96
+ LOG.error("Bookmarks data in local storage is invalid, resetting to default value.", e);
97
+ this.store.set(this.writableBookmarks, []);
98
+ this.saveState();
99
+ }
100
+ }
101
+ /**
102
+ * Saves the bookmarks to local storage.
103
+ */
104
+ saveState() {
105
+ LOG.debug("Saving bookmarks to local storage");
106
+ this.packageNamespace.set("bookmarks", this.store.get(this.bookmarks));
107
+ }
108
+ /** Computes an OpenLayers extent for the given bookmark. */
109
+ getBookmarkExtent(bookmark) {
110
+ const olMap = this.map.olMap;
111
+ const olView = olMap.getView();
112
+ const extent = bookmark.extent;
113
+ const olExtent = [extent.minX, extent.minY, extent.maxX, extent.maxY];
114
+ const viewProjection = olView.getProjection();
115
+ const extentProjection = bookmark.projection;
116
+ return transformExtent(olExtent, extentProjection, viewProjection);
117
+ }
118
+ /** Moves the map to the given extent. */
119
+ applyExtent(olExtent) {
120
+ const olMap = this.map.olMap;
121
+ const olView = olMap.getView();
122
+ const center = getCenter(olExtent);
123
+ const resolution = olView.getResolutionForExtent(olExtent);
124
+ olView.setCenter(center);
125
+ olView.setResolution(resolution);
126
+ }
127
+ }
128
+ function validateBookmarks(rawBookmarks) {
129
+ if (!Array.isArray(rawBookmarks)) {
130
+ throw new Error(`Expected bookmarks from local storage to be an array.`);
131
+ }
132
+ for (const rawBookmark of rawBookmarks) {
133
+ validateBookmark(rawBookmark);
134
+ }
135
+ }
136
+ function validateBookmark(rawBookmark) {
137
+ if (!rawBookmark || typeof rawBookmark !== "object") {
138
+ throw new Error(`Expected bookmark from local storage to be an object.`);
139
+ }
140
+ const bookmark = rawBookmark;
141
+ if (typeof bookmark.id !== "string") {
142
+ throw new Error("Bookmark does not have a valid id.");
143
+ }
144
+ if (typeof bookmark.title !== "string") {
145
+ throw new Error("Bookmark does not have a valid title.");
146
+ }
147
+ validateExtent(bookmark.extent);
148
+ if (typeof bookmark.projection !== "string") {
149
+ throw new Error("Bookmark does not have a valid projection value.");
150
+ }
151
+ }
152
+ function validateExtent(rawExtent) {
153
+ if (!rawExtent || typeof rawExtent !== "object") {
154
+ throw new Error(`Expected bookmark extent from local storage to be an object.`);
155
+ }
156
+ const extent = rawExtent;
157
+ if (typeof extent.minX !== "number" || typeof extent.minY !== "number" || typeof extent.maxX !== "number" || typeof extent.maxY !== "number") {
158
+ throw new Error("Expected bookmark extent from local storage to have valid coordinates.");
159
+ }
160
+ }
161
+
162
+ export { SpatialBookmarkViewModel };
163
+ //# sourceMappingURL=SpatialBookmarksViewModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SpatialBookmarksViewModel.js","sources":["SpatialBookmarksViewModel.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { MapModel } from \"@open-pioneer/map\";\nimport { Atom, atom, createStore } from \"jotai\";\nimport { LocalStorageNamespace, LocalStorageService } from \"@open-pioneer/local-storage\";\nimport { v4 as uuid4v } from \"uuid\";\nimport { Extent as OlExtent, getCenter } from \"ol/extent\";\nimport { transformExtent } from \"ol/proj\";\nimport { createLogger } from \"@open-pioneer/core\";\n\nconst LOG = createLogger(\"spatial-bookmark:SpatialBookmarkViewModel\");\n\ninterface Extent {\n minX: number;\n minY: number;\n maxX: number;\n maxY: number;\n}\n\nexport interface Bookmark {\n id: string;\n title: string;\n extent: Extent;\n projection: string;\n}\n\ntype Store = ReturnType<typeof createStore>;\n\nexport class SpatialBookmarkViewModel {\n private map: MapModel;\n private packageNamespace: LocalStorageNamespace;\n private writableBookmarks = atom<Bookmark[]>([]);\n private stopBookmarksListener: () => void;\n\n /** Contains the jotai state (atoms + store === value). */\n readonly store: Store; // contains jotai state\n\n /**\n * Provides read-only access to the bookmarks array.\n * The UI simply renders the contents of the store and\n * uses the methods below to modify the state.\n */\n get bookmarks(): Atom<Bookmark[]> {\n return this.writableBookmarks;\n }\n\n constructor(map: MapModel, localStorageService: LocalStorageService) {\n this.map = map;\n this.packageNamespace = localStorageService.getNamespace(\"spatial-bookmarks\");\n this.store = createStore();\n\n // Load from local storage on start; save changes whenever bookmarks change.\n this.loadState();\n this.stopBookmarksListener = this.store.sub(this.bookmarks, () => {\n this.saveState();\n });\n }\n\n destroy() {\n this.stopBookmarksListener();\n }\n\n /**\n * Creates a new bookmark with the `title` provided by the UI.\n * The current map extent is used for the new bookmark's extent.\n */\n createBookmark(title: string) {\n const olMap = this.map.olMap;\n // minx, miny, maxx, maxy\n const olExtent = olMap.getView().calculateExtent();\n const projection = olMap.getView().getProjection().getCode();\n const extent: Extent = {\n minX: olExtent[0]!,\n minY: olExtent[1]!,\n maxX: olExtent[2]!,\n maxY: olExtent[3]!\n };\n const bookmark: Bookmark = {\n id: uuid4v(),\n title,\n extent,\n projection\n };\n LOG.debug(\"Created a new bookmark\", bookmark);\n\n const bookmarks = this.writableBookmarks;\n this.store.set(bookmarks, [...this.store.get(bookmarks), bookmark]);\n }\n\n /**\n * Activates the bookmark with the given id by zooming\n * to the bookmark's extent.\n */\n activateBookmark(bookmark: Bookmark) {\n LOG.debug(\"Activating bookmark\", bookmark);\n const extent = this.getBookmarkExtent(bookmark);\n\n LOG.debug(\"Attempting to apply extent\", extent);\n this.applyExtent(extent);\n }\n\n /**\n * Deletes the bookmark with the given id.\n */\n deleteBookmark(id: string) {\n LOG.debug(\"Deleting bookmark\", id);\n const bookmarks = this.writableBookmarks;\n this.store.set(bookmarks, [...this.store.get(bookmarks).filter((b) => b.id !== id)]);\n }\n\n /**\n * Deletes all bookmarks.\n */\n deleteAllBookmarks() {\n LOG.debug(\"Deleting all bookmarks\");\n this.store.set(this.writableBookmarks, []);\n }\n\n /**\n * Loads the bookmarks from local storage.\n * If the bookmarks are not valid, the initial state (empty array) is restored.\n */\n private loadState() {\n LOG.debug(\"Restoring bookmarks from local storage\");\n\n const rawBookmarks = this.packageNamespace.get(\"bookmarks\") ?? [];\n try {\n validateBookmarks(rawBookmarks);\n this.store.set(this.writableBookmarks, rawBookmarks);\n } catch (e) {\n LOG.error(\"Bookmarks data in local storage is invalid, resetting to default value.\", e);\n this.store.set(this.writableBookmarks, []);\n this.saveState();\n }\n }\n\n /**\n * Saves the bookmarks to local storage.\n */\n private saveState() {\n LOG.debug(\"Saving bookmarks to local storage\");\n this.packageNamespace.set(\"bookmarks\", this.store.get(this.bookmarks));\n }\n\n /** Computes an OpenLayers extent for the given bookmark. */\n private getBookmarkExtent(bookmark: Bookmark) {\n const olMap = this.map.olMap;\n const olView = olMap.getView();\n const extent = bookmark.extent;\n const olExtent = [extent.minX, extent.minY, extent.maxX, extent.maxY];\n const viewProjection = olView.getProjection();\n const extentProjection = bookmark.projection;\n return transformExtent(olExtent, extentProjection, viewProjection);\n }\n\n /** Moves the map to the given extent. */\n private applyExtent(olExtent: OlExtent) {\n const olMap = this.map.olMap;\n const olView = olMap.getView();\n const center = getCenter(olExtent);\n const resolution = olView.getResolutionForExtent(olExtent);\n olView.setCenter(center);\n olView.setResolution(resolution);\n }\n}\n\nfunction validateBookmarks(rawBookmarks: unknown): asserts rawBookmarks is Bookmark[] {\n if (!Array.isArray(rawBookmarks)) {\n throw new Error(`Expected bookmarks from local storage to be an array.`);\n }\n for (const rawBookmark of rawBookmarks) {\n validateBookmark(rawBookmark);\n }\n}\n\nfunction validateBookmark(rawBookmark: unknown): asserts rawBookmark is Bookmark {\n if (!rawBookmark || typeof rawBookmark !== \"object\") {\n throw new Error(`Expected bookmark from local storage to be an object.`);\n }\n\n const bookmark = rawBookmark as Record<keyof Bookmark, unknown>;\n if (typeof bookmark.id !== \"string\") {\n throw new Error(\"Bookmark does not have a valid id.\");\n }\n if (typeof bookmark.title !== \"string\") {\n throw new Error(\"Bookmark does not have a valid title.\");\n }\n validateExtent(bookmark.extent);\n if (typeof bookmark.projection !== \"string\") {\n throw new Error(\"Bookmark does not have a valid projection value.\");\n }\n}\n\nfunction validateExtent(rawExtent: unknown): asserts rawExtent is Extent {\n if (!rawExtent || typeof rawExtent !== \"object\") {\n throw new Error(`Expected bookmark extent from local storage to be an object.`);\n }\n\n const extent = rawExtent as Record<keyof Extent, unknown>;\n if (\n typeof extent.minX !== \"number\" ||\n typeof extent.minY !== \"number\" ||\n typeof extent.maxX !== \"number\" ||\n typeof extent.maxY !== \"number\"\n ) {\n throw new Error(\"Expected bookmark extent from local storage to have valid coordinates.\");\n }\n}\n"],"names":["uuid4v"],"mappings":";;;;;;AAUA,MAAM,GAAA,GAAM,aAAa,2CAA2C,CAAA,CAAA;AAkB7D,MAAM,wBAAyB,CAAA;AAAA,EAC1B,GAAA,CAAA;AAAA,EACA,gBAAA,CAAA;AAAA,EACA,iBAAA,GAAoB,IAAiB,CAAA,EAAE,CAAA,CAAA;AAAA,EACvC,qBAAA,CAAA;AAAA;AAAA,EAGC,KAAA,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOT,IAAI,SAA8B,GAAA;AAC9B,IAAA,OAAO,IAAK,CAAA,iBAAA,CAAA;AAAA,GAChB;AAAA,EAEA,WAAA,CAAY,KAAe,mBAA0C,EAAA;AACjE,IAAA,IAAA,CAAK,GAAM,GAAA,GAAA,CAAA;AACX,IAAK,IAAA,CAAA,gBAAA,GAAmB,mBAAoB,CAAA,YAAA,CAAa,mBAAmB,CAAA,CAAA;AAC5E,IAAA,IAAA,CAAK,QAAQ,WAAY,EAAA,CAAA;AAGzB,IAAA,IAAA,CAAK,SAAU,EAAA,CAAA;AACf,IAAA,IAAA,CAAK,wBAAwB,IAAK,CAAA,KAAA,CAAM,GAAI,CAAA,IAAA,CAAK,WAAW,MAAM;AAC9D,MAAA,IAAA,CAAK,SAAU,EAAA,CAAA;AAAA,KAClB,CAAA,CAAA;AAAA,GACL;AAAA,EAEA,OAAU,GAAA;AACN,IAAA,IAAA,CAAK,qBAAsB,EAAA,CA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wE,CAAA,CAAA;AAAA,GAC5F;AACJ;;;;"}
@@ -0,0 +1,8 @@
1
+ import { useServiceInternal, useIntlInternal } from '@open-pioneer/runtime/react-integration';
2
+
3
+ const PACKAGE_NAME = "@open-pioneer/spatial-bookmarks";
4
+ const useService = /*@__PURE__*/ useServiceInternal.bind(undefined, PACKAGE_NAME);
5
+ const useIntl = /*@__PURE__*/ useIntlInternal.bind(undefined, PACKAGE_NAME);
6
+
7
+ export { useIntl, useService };
8
+ //# sourceMappingURL=_virtual-pioneer-module_react-hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_virtual-pioneer-module_react-hooks.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
package/i18n/de.yaml ADDED
@@ -0,0 +1,19 @@
1
+ messages:
2
+ bookmark:
3
+ button:
4
+ create: "Neues Lesezeichen hinzufügen"
5
+ deleteAll: "Alle Lesezeichen löschen"
6
+ deleteOne: "Lesezeichen löschen"
7
+ save: "Speichern"
8
+ cancel: "Abbrechen"
9
+ cancelDelete: "Nein"
10
+ confirmDelete: "Ja"
11
+ input:
12
+ label: "Name"
13
+ placeholder: "Name des Lesezeichens"
14
+ alert:
15
+ create: "Nach der Eingabe eines Namens können Sie das neue Lesezeichen speichern. Dabei wird der aktuelle Kartenausschnitt als Grundlage für die Position verwendet."
16
+ delete: "Möchten Sie wirklich alle räumlichen Lesezeichen löschen?"
17
+ noSaved: "Sie haben keine gespeicherten Lesezeichen"
18
+ list:
19
+ label: "Räumliche Lesezeichen"
package/i18n/en.yaml ADDED
@@ -0,0 +1,19 @@
1
+ messages:
2
+ bookmark:
3
+ button:
4
+ create: "Add new bookmark"
5
+ deleteAll: "Delete all bookmarks"
6
+ deleteOne: "Delete bookmark"
7
+ save: "Save"
8
+ cancel: "Cancel"
9
+ cancelDelete: "No"
10
+ confirmDelete: "Yes"
11
+ input:
12
+ label: "Name"
13
+ placeholder: "Enter bookmark name"
14
+ alert:
15
+ create: "After entering a name you can save the new bookmark. The current map extent is used as the basis for the position."
16
+ delete: "Do you really want to delete all spatial bookmarks?"
17
+ noSaved: "No bookmarks saved"
18
+ list:
19
+ label: "Spatial bookmarks"
package/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { SpatialBookmarks, type SpatialBookmarksProps } from "./SpatialBookmarks";
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { SpatialBookmarks } from './SpatialBookmarks.js';
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,49 @@
1
+ {
2
+ "type": "module",
3
+ "name": "@open-pioneer/spatial-bookmarks",
4
+ "version": "0.1.0",
5
+ "license": "Apache-2.0",
6
+ "dependencies": {
7
+ "jotai": "^2.6.0",
8
+ "uuid": "^9.0.1"
9
+ },
10
+ "peerDependencies": {
11
+ "@chakra-ui/icons": "^2.1.1",
12
+ "@open-pioneer/chakra-integration": "^1.1.1",
13
+ "@open-pioneer/core": "^1.2.1",
14
+ "@open-pioneer/runtime": "^2.0.2",
15
+ "classnames": "^2.3.2",
16
+ "ol": "^8.2.0",
17
+ "react": "^18.2.0",
18
+ "react-icons": "^4.12.0",
19
+ "@open-pioneer/local-storage": "^0.1.0",
20
+ "@open-pioneer/map": "^0.1.1",
21
+ "@open-pioneer/react-utils": "^0.1.0"
22
+ },
23
+ "exports": {
24
+ "./package.json": "./package.json",
25
+ ".": {
26
+ "import": "./index.js",
27
+ "types": "./index.d.ts"
28
+ }
29
+ },
30
+ "openPioneerFramework": {
31
+ "services": [],
32
+ "i18n": {
33
+ "languages": [
34
+ "en",
35
+ "de"
36
+ ]
37
+ },
38
+ "ui": {
39
+ "references": [
40
+ {
41
+ "type": "unique",
42
+ "interfaceName": "local-storage.LocalStorageService"
43
+ }
44
+ ]
45
+ },
46
+ "properties": [],
47
+ "packageFormatVersion": "1.0.0"
48
+ }
49
+ }