@open-pioneer/basemap-switcher 1.0.0 → 1.2.0-dev.20251128143231
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/BasemapSwitcher.d.ts +1 -18
- package/BasemapSwitcher.js +52 -29
- package/BasemapSwitcher.js.map +1 -1
- package/CHANGELOG.md +27 -0
- package/i18n/de.yaml +1 -0
- package/i18n/en.yaml +1 -0
- package/package.json +9 -9
package/BasemapSwitcher.d.ts
CHANGED
|
@@ -1,24 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MapModelProps } from "@open-pioneer/map";
|
|
2
2
|
import { CommonComponentProps } from "@open-pioneer/react-utils";
|
|
3
3
|
import { FC } from "react";
|
|
4
4
|
export declare const NO_BASEMAP_ID = "___NO_BASEMAP___";
|
|
5
|
-
/**
|
|
6
|
-
* Properties for single select options.
|
|
7
|
-
*/
|
|
8
|
-
export interface SelectOption {
|
|
9
|
-
/**
|
|
10
|
-
* The id of the basemap for the select option.
|
|
11
|
-
*/
|
|
12
|
-
value: string;
|
|
13
|
-
/**
|
|
14
|
-
* The label of the select option.
|
|
15
|
-
*/
|
|
16
|
-
label: string;
|
|
17
|
-
/**
|
|
18
|
-
* The layer object for the select option.
|
|
19
|
-
*/
|
|
20
|
-
layer: Layer | undefined;
|
|
21
|
-
}
|
|
22
5
|
/**
|
|
23
6
|
* These are special properties for the BasemapSwitcher.
|
|
24
7
|
*/
|
package/BasemapSwitcher.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { createListCollection, Box, Select, Portal } from '@chakra-ui/react';
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import { createListCollection, Box, Select, Portal, Text } from '@chakra-ui/react';
|
|
3
3
|
import { Tooltip } from '@open-pioneer/chakra-snippets/tooltip';
|
|
4
4
|
import { useMapModelValue } from '@open-pioneer/map';
|
|
5
5
|
import { useCommonComponentProps } from '@open-pioneer/react-utils';
|
|
6
6
|
import { useReactiveSnapshot } from '@open-pioneer/reactivity';
|
|
7
7
|
import { useIntl } from './_virtual/_virtual-pioneer-module_react-hooks.js';
|
|
8
|
-
import {
|
|
8
|
+
import { useMemo } from 'react';
|
|
9
|
+
import { LuTriangleAlert, LuInfo } from 'react-icons/lu';
|
|
9
10
|
|
|
10
11
|
const NO_BASEMAP_ID = "___NO_BASEMAP___";
|
|
11
12
|
const BasemapSwitcher = (props) => {
|
|
@@ -41,14 +42,17 @@ const BasemapSwitcher = (props) => {
|
|
|
41
42
|
options.push(emptyOption);
|
|
42
43
|
}
|
|
43
44
|
const optionsListCollection2 = createListCollection({ items: options });
|
|
44
|
-
const selectedOption2 =
|
|
45
|
+
const selectedOption2 = optionsListCollection2.find(activeBaseLayer?.id ?? NO_BASEMAP_ID);
|
|
46
|
+
if (!selectedOption2) {
|
|
47
|
+
throw new Error("Internal error: selected option not found in list.");
|
|
48
|
+
}
|
|
45
49
|
return { optionsListCollection: optionsListCollection2, selectedOption: selectedOption2 };
|
|
46
50
|
}, [allowSelectingEmptyBasemap, emptyBasemapLabel, map]);
|
|
47
51
|
return /* @__PURE__ */ jsx(Box, { ...containerProps, children: /* @__PURE__ */ jsxs(
|
|
48
52
|
Select.Root,
|
|
49
53
|
{
|
|
50
54
|
collection: optionsListCollection,
|
|
51
|
-
value: selectedOption,
|
|
55
|
+
value: [selectedOption.value],
|
|
52
56
|
onValueChange: (option) => option && activateLayer(option.value),
|
|
53
57
|
className: "basemap-switcher-select",
|
|
54
58
|
lazyMount: true,
|
|
@@ -61,7 +65,7 @@ const BasemapSwitcher = (props) => {
|
|
|
61
65
|
"aria-label": ariaLabel,
|
|
62
66
|
"aria-labelledby": ariaLabelledBy,
|
|
63
67
|
className: "basemap-switcher-select-trigger",
|
|
64
|
-
children: /* @__PURE__ */ jsx(Select.ValueText, {})
|
|
68
|
+
children: /* @__PURE__ */ jsx(Select.ValueText, { display: "flex", alignItems: "center", children: /* @__PURE__ */ jsx(BasemapItemContent, { option: selectedOption }) })
|
|
65
69
|
}
|
|
66
70
|
),
|
|
67
71
|
/* @__PURE__ */ jsx(Select.IndicatorGroup, { children: /* @__PURE__ */ jsx(Select.Indicator, {}) })
|
|
@@ -72,40 +76,59 @@ const BasemapSwitcher = (props) => {
|
|
|
72
76
|
) });
|
|
73
77
|
};
|
|
74
78
|
function BasemapItem(props) {
|
|
75
|
-
const intl = useIntl();
|
|
76
|
-
const notAvailableLabel = intl.formatMessage({ id: "layerNotAvailable" });
|
|
77
79
|
const item = props.item;
|
|
78
|
-
return /* @__PURE__ */
|
|
80
|
+
return /* @__PURE__ */ jsx(
|
|
79
81
|
Select.Item,
|
|
80
82
|
{
|
|
81
83
|
item,
|
|
82
84
|
justifyContent: "flex-start",
|
|
83
85
|
pointerEvents: "auto",
|
|
84
86
|
className: "basemap-switcher-option",
|
|
85
|
-
children:
|
|
86
|
-
item.label,
|
|
87
|
-
item.layer?.loadState === "error" && /* @__PURE__ */ jsx(Box, { ml: 2, children: /* @__PURE__ */ jsx(
|
|
88
|
-
Tooltip,
|
|
89
|
-
{
|
|
90
|
-
content: notAvailableLabel,
|
|
91
|
-
"aria-label": notAvailableLabel,
|
|
92
|
-
positioning: { placement: "right" },
|
|
93
|
-
children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
|
|
94
|
-
LuTriangleAlert,
|
|
95
|
-
{
|
|
96
|
-
color: "red",
|
|
97
|
-
"aria-label": intl.formatMessage({
|
|
98
|
-
id: "layerNotAvailable"
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
) })
|
|
102
|
-
}
|
|
103
|
-
) })
|
|
104
|
-
]
|
|
87
|
+
children: /* @__PURE__ */ jsx(BasemapItemContent, { option: item })
|
|
105
88
|
},
|
|
106
89
|
item.value
|
|
107
90
|
);
|
|
108
91
|
}
|
|
92
|
+
function BasemapItemContent(props) {
|
|
93
|
+
const { option } = props;
|
|
94
|
+
const intl = useIntl();
|
|
95
|
+
const loadState = useReactiveSnapshot(() => option.layer?.loadState, [option.layer]);
|
|
96
|
+
const visibleInScale = useReactiveSnapshot(() => option.layer?.visibleInScale, [option.layer]);
|
|
97
|
+
const { problem, opacity } = useMemo(() => {
|
|
98
|
+
let problem2 = void 0;
|
|
99
|
+
let opacity2 = void 0;
|
|
100
|
+
if (option.layer) {
|
|
101
|
+
if (loadState === "error") {
|
|
102
|
+
problem2 = /* @__PURE__ */ jsx(
|
|
103
|
+
ProblemIndicator,
|
|
104
|
+
{
|
|
105
|
+
Icon: LuTriangleAlert,
|
|
106
|
+
color: "red",
|
|
107
|
+
message: intl.formatMessage({ id: "layerNotAvailable" })
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
} else if (!visibleInScale) {
|
|
111
|
+
problem2 = /* @__PURE__ */ jsx(
|
|
112
|
+
ProblemIndicator,
|
|
113
|
+
{
|
|
114
|
+
Icon: LuInfo,
|
|
115
|
+
message: intl.formatMessage({ id: "layerNotVisible" })
|
|
116
|
+
}
|
|
117
|
+
);
|
|
118
|
+
opacity2 = 0.5;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { problem: problem2, opacity: opacity2 };
|
|
122
|
+
}, [option.layer, loadState, visibleInScale, intl]);
|
|
123
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
124
|
+
/* @__PURE__ */ jsx(Text, { as: "span", opacity, children: option.label }),
|
|
125
|
+
problem
|
|
126
|
+
] });
|
|
127
|
+
}
|
|
128
|
+
function ProblemIndicator(props) {
|
|
129
|
+
const { Icon, message, color } = props;
|
|
130
|
+
return /* @__PURE__ */ jsx(Box, { ml: 2, className: "basemap-switcher-option-problem-indicator", children: /* @__PURE__ */ jsx(Tooltip, { content: message, "aria-label": message, positioning: { placement: "right" }, children: /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(Icon, { "aria-label": message, color }) }) }) });
|
|
131
|
+
}
|
|
109
132
|
|
|
110
133
|
export { BasemapSwitcher, NO_BASEMAP_ID };
|
|
111
134
|
//# sourceMappingURL=BasemapSwitcher.js.map
|
package/BasemapSwitcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasemapSwitcher.js","sources":["BasemapSwitcher.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Box, createListCollection, Portal, Select } from \"@chakra-ui/react\";\nimport { Tooltip } from \"@open-pioneer/chakra-snippets/tooltip\";\nimport { Layer, MapModelProps, useMapModelValue } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC } from \"react\";\nimport { LuTriangleAlert } from \"react-icons/lu\";\n\n/*\n Exported for tests. Feels a bit hacky but should be fine for now.\n Originally was using the empty string, but that doesn't work well with happy-dom.\n*/\nexport const NO_BASEMAP_ID = \"___NO_BASEMAP___\";\n\n/**\n * Properties for single select options.\n */\nexport interface SelectOption {\n /**\n * The id of the basemap for the select option.\n */\n value: string;\n\n /**\n * The label of the select option.\n */\n label: string;\n\n /**\n * The layer object for the select option.\n */\n layer: Layer | undefined;\n}\n\n/**\n * These are special properties for the BasemapSwitcher.\n */\nexport interface BasemapSwitcherProps extends CommonComponentProps, MapModelProps {\n /**\n * Additional css class name(s) that will be added to the BasemapSwitcher component.\n */\n className?: string;\n\n /**\n * Specifies whether an option to deactivate all basemap layers is available in the BasemapSwitcher.\n * Defaults to `false`.\n */\n allowSelectingEmptyBasemap?: boolean | undefined;\n\n /**\n * Optional aria-labelledby property.\n * Do not use together with aria-label.\n */\n \"aria-labelledby\"?: string;\n\n /**\n * Optional aria-label property.\n * Do not use together with aria-label.\n */\n \"aria-label\"?: string;\n}\n\n/**\n * The `BasemapSwitcher` component can be used in an app to switch between the different basemaps.\n */\nexport const BasemapSwitcher: FC<BasemapSwitcherProps> = (props) => {\n const map = useMapModelValue(props);\n const intl = useIntl();\n const {\n allowSelectingEmptyBasemap = false,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy\n } = props;\n const { containerProps } = useCommonComponentProps(\"basemap-switcher\", props);\n const emptyBasemapLabel = intl.formatMessage({ id: \"emptyBasemapLabel\" });\n\n const activateLayer = (layerId: string[]) => {\n map.layers.activateBaseLayer(layerId[0] === NO_BASEMAP_ID ? undefined : layerId[0]);\n };\n\n const { optionsListCollection, selectedOption } = useReactiveSnapshot(() => {\n const baseLayers = map.layers.getBaseLayers() ?? [];\n const options: SelectOption[] = baseLayers.map<SelectOption>((layer) => {\n return {\n value: layer.id,\n layer: layer,\n label: layer.title,\n disabled: layer.loadState == \"error\"\n };\n });\n\n const activeBaseLayer = map.layers.getActiveBaseLayer();\n if (allowSelectingEmptyBasemap || activeBaseLayer == null) {\n const emptyOption: SelectOption = {\n value: NO_BASEMAP_ID,\n layer: undefined,\n label: emptyBasemapLabel\n };\n options.push(emptyOption);\n }\n const optionsListCollection = createListCollection({ items: options });\n\n const selectedOption = [activeBaseLayer?.id ?? NO_BASEMAP_ID];\n\n return { optionsListCollection, selectedOption };\n }, [allowSelectingEmptyBasemap, emptyBasemapLabel, map]);\n\n return (\n <Box {...containerProps}>\n <Select.Root\n collection={optionsListCollection}\n value={selectedOption}\n onValueChange={(option) => option && activateLayer(option.value)}\n className=\"basemap-switcher-select\"\n lazyMount={true}\n unmountOnExit={true}\n >\n <Select.Control>\n <Select.Trigger\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n className=\"basemap-switcher-select-trigger\"\n >\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=\"basemap-switcher-select-content\">\n {optionsListCollection.items.map((item) => (\n <BasemapItem item={item} key={item.value} />\n ))}\n </Select.Content>\n </Select.Positioner>\n </Portal>\n </Select.Root>\n </Box>\n );\n};\n\nfunction BasemapItem(props: { item: SelectOption }) {\n const intl = useIntl();\n const notAvailableLabel = intl.formatMessage({ id: \"layerNotAvailable\" });\n const item = props.item;\n return (\n <Select.Item\n item={item}\n key={item.value}\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 className=\"basemap-switcher-option\"\n >\n {item.label}\n {item.layer?.loadState === \"error\" && (\n <Box ml={2}>\n <Tooltip\n content={notAvailableLabel}\n aria-label={notAvailableLabel}\n positioning={{ placement: \"right\" }}\n >\n <span>\n <LuTriangleAlert\n color={\"red\"}\n aria-label={intl.formatMessage({\n id: \"layerNotAvailable\"\n })}\n />\n </span>\n </Tooltip>\n </Box>\n )}\n </Select.Item>\n );\n}\n"],"names":["optionsListCollection","selectedOption"],"mappings":";;;;;;;;;AAeO,MAAM,aAAA,GAAgB;AAqDtB,MAAM,eAAA,GAA4C,CAAC,KAAA,KAAU;AAChE,EAAA,MAAM,GAAA,GAAM,iBAAiB,KAAK,CAAA;AAClC,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM;AAAA,IACF,0BAAA,GAA6B,KAAA;AAAA,IAC7B,YAAA,EAAc,SAAA;AAAA,IACd,iBAAA,EAAmB;AAAA,GACvB,GAAI,KAAA;AACJ,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,uBAAA,CAAwB,oBAAoB,KAAK,CAAA;AAC5E,EAAA,MAAM,oBAAoB,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,qBAAqB,CAAA;AAExE,EAAA,MAAM,aAAA,GAAgB,CAAC,OAAA,KAAsB;AACzC,IAAA,GAAA,CAAI,MAAA,CAAO,kBAAkB,OAAA,CAAQ,CAAC,MAAM,aAAA,GAAgB,MAAA,GAAY,OAAA,CAAQ,CAAC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,CAAO,IAAA;AAAA,IAAP;AAAA,MACG,IAAA;AAAA,MAEA,cAAA,EAAe,YAAA;AAAA,MAEf,aAAA,EAAc,MAAA;AAAA,MACd,SAAA,EAAU,yBAAA;AAAA,MAET,QAAA,EAAA;AAAA,QAAA,IAAA,CAAK,KAAA;AAAA,QACL,KAAK,KAAA,EAAO,SAAA,KAAc,2BACvB,GAAA,CAAC,GAAA,EAAA,EAAI,IAAI,CAAA,EACL,QAAA,kBAAA,GAAA;AAAA,UAAC,OAAA;AAAA,UAAA;AAAA,YACG,OAAA,EAAS,iBAAA;AAAA,YACT,YAAA,EAAY,iBAAA;AAAA,YACZ,WAAA,EAAa,EAAE,SAAA,EAAW,OAAA,EAAQ;AAAA,YAElC,8BAAC,MAAA,EAAA,EACG,QAAA,kBAAA,GAAA;AAAA,cAAC,eAAA;AAAA,cAAA;AAAA,gBACG,KAAA,EAAO,KAAA;AAAA,gBACP,YAAA,EAAY,KAAK,aAAA,CAAc;AAAA,kBAC3B,EAAA,EAAI;AAAA,iBACP;AAAA;AAAA,aACL,EACJ;AAAA;AAAA,SACJ,EACJ;AAAA;AAAA,KAAA;AAAA,IAvBC,IAAA,CAAK;AAAA,GAyBd;AAER;;;;"}
|
|
1
|
+
{"version":3,"file":"BasemapSwitcher.js","sources":["BasemapSwitcher.tsx"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { Box, createListCollection, Portal, Select, Text } from \"@chakra-ui/react\";\nimport { Tooltip } from \"@open-pioneer/chakra-snippets/tooltip\";\nimport { Layer, MapModelProps, useMapModelValue } from \"@open-pioneer/map\";\nimport { CommonComponentProps, useCommonComponentProps } from \"@open-pioneer/react-utils\";\nimport { useReactiveSnapshot } from \"@open-pioneer/reactivity\";\nimport { useIntl } from \"open-pioneer:react-hooks\";\nimport { FC, useMemo } from \"react\";\nimport { type IconType } from \"react-icons/lib\";\nimport { LuInfo, LuTriangleAlert } from \"react-icons/lu\";\n\n/*\n Exported for tests. Feels a bit hacky but should be fine for now.\n Originally was using the empty string, but that doesn't work well with happy-dom.\n*/\nexport const NO_BASEMAP_ID = \"___NO_BASEMAP___\";\n\n/**\n * Properties for single select options.\n */\ninterface SelectOption {\n /**\n * The id of the basemap for the select option.\n */\n value: string;\n\n /**\n * The label of the select option.\n */\n label: string;\n\n /**\n * The layer object for the select option.\n * Undefined is used for \"no basemap\".\n */\n layer: Layer | undefined;\n}\n\n/**\n * These are special properties for the BasemapSwitcher.\n */\nexport interface BasemapSwitcherProps extends CommonComponentProps, MapModelProps {\n /**\n * Additional css class name(s) that will be added to the BasemapSwitcher component.\n */\n className?: string;\n\n /**\n * Specifies whether an option to deactivate all basemap layers is available in the BasemapSwitcher.\n * Defaults to `false`.\n */\n allowSelectingEmptyBasemap?: boolean | undefined;\n\n /**\n * Optional aria-labelledby property.\n * Do not use together with aria-label.\n */\n \"aria-labelledby\"?: string;\n\n /**\n * Optional aria-label property.\n * Do not use together with aria-label.\n */\n \"aria-label\"?: string;\n}\n\n/**\n * The `BasemapSwitcher` component can be used in an app to switch between the different basemaps.\n */\nexport const BasemapSwitcher: FC<BasemapSwitcherProps> = (props) => {\n const map = useMapModelValue(props);\n const intl = useIntl();\n const {\n allowSelectingEmptyBasemap = false,\n \"aria-label\": ariaLabel,\n \"aria-labelledby\": ariaLabelledBy\n } = props;\n const { containerProps } = useCommonComponentProps(\"basemap-switcher\", props);\n const emptyBasemapLabel = intl.formatMessage({ id: \"emptyBasemapLabel\" });\n\n const activateLayer = (layerId: string[]) => {\n map.layers.activateBaseLayer(layerId[0] === NO_BASEMAP_ID ? undefined : layerId[0]);\n };\n\n const { optionsListCollection, selectedOption } = useReactiveSnapshot(() => {\n const baseLayers = map.layers.getBaseLayers() ?? [];\n const options: SelectOption[] = baseLayers.map<SelectOption>((layer) => {\n return {\n value: layer.id,\n layer: layer,\n label: layer.title,\n disabled: layer.loadState == \"error\"\n };\n });\n\n const activeBaseLayer = map.layers.getActiveBaseLayer();\n if (allowSelectingEmptyBasemap || activeBaseLayer == null) {\n const emptyOption: SelectOption = {\n value: NO_BASEMAP_ID,\n layer: undefined,\n label: emptyBasemapLabel\n };\n options.push(emptyOption);\n }\n const optionsListCollection = createListCollection({ items: options });\n const selectedOption = optionsListCollection.find(activeBaseLayer?.id ?? NO_BASEMAP_ID);\n if (!selectedOption) {\n throw new Error(\"Internal error: selected option not found in list.\");\n }\n\n return { optionsListCollection, selectedOption };\n }, [allowSelectingEmptyBasemap, emptyBasemapLabel, map]);\n\n return (\n <Box {...containerProps}>\n <Select.Root\n collection={optionsListCollection}\n value={[selectedOption.value]}\n onValueChange={(option) => option && activateLayer(option.value)}\n className=\"basemap-switcher-select\"\n lazyMount={true}\n unmountOnExit={true}\n >\n <Select.Control>\n <Select.Trigger\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n className=\"basemap-switcher-select-trigger\"\n >\n <Select.ValueText display=\"flex\" alignItems=\"center\">\n <BasemapItemContent option={selectedOption} />\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=\"basemap-switcher-select-content\">\n {optionsListCollection.items.map((item) => (\n <BasemapItem item={item} key={item.value} />\n ))}\n </Select.Content>\n </Select.Positioner>\n </Portal>\n </Select.Root>\n </Box>\n );\n};\n\nfunction BasemapItem(props: { item: SelectOption }) {\n const item = props.item;\n\n return (\n <Select.Item\n item={item}\n key={item.value}\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 className=\"basemap-switcher-option\"\n >\n <BasemapItemContent option={item} />\n </Select.Item>\n );\n}\n\nfunction BasemapItemContent(props: { option: SelectOption }) {\n const { option } = props;\n const intl = useIntl();\n const loadState = useReactiveSnapshot(() => option.layer?.loadState, [option.layer]);\n const visibleInScale = useReactiveSnapshot(() => option.layer?.visibleInScale, [option.layer]);\n\n const { problem, opacity } = useMemo(() => {\n let problem = undefined;\n let opacity = undefined;\n if (option.layer) {\n if (loadState === \"error\") {\n problem = (\n <ProblemIndicator\n Icon={LuTriangleAlert}\n color=\"red\"\n message={intl.formatMessage({ id: \"layerNotAvailable\" })}\n />\n );\n } else if (!visibleInScale) {\n problem = (\n <ProblemIndicator\n Icon={LuInfo}\n message={intl.formatMessage({ id: \"layerNotVisible\" })}\n />\n );\n opacity = 0.5;\n }\n }\n return { problem, opacity };\n }, [option.layer, loadState, visibleInScale, intl]);\n\n return (\n <>\n <Text as=\"span\" opacity={opacity}>\n {option.label}\n </Text>\n {problem}\n </>\n );\n}\n\nfunction ProblemIndicator(props: { Icon: IconType; message: string; color?: string }) {\n const { Icon, message, color } = props;\n return (\n <Box ml={2} className=\"basemap-switcher-option-problem-indicator\">\n <Tooltip content={message} aria-label={message} positioning={{ placement: \"right\" }}>\n <span>\n <Icon aria-label={message} color={color} />\n </span>\n </Tooltip>\n </Box>\n );\n}\n"],"names":["optionsListCollection","selectedOption","problem","opacity"],"mappings":";;;;;;;;;;AAgBO,MAAM,aAAA,GAAgB;AAsDtB,MAAM,eAAA,GAA4C,CAAC,KAAA,KAAU;AAChE,EAAA,MAAM,GAAA,GAAM,iBAAiB,KAAK,CAAA;AAClC,EAAA,MAAM,OAAO,OAAA,EAAQ;AACrB,EAAA,MAAM;AAAA,IACF,0BAAA,GAA6B,KAAA;AAAA,IAC7B,YAAA,EAAc,SAAA;AAAA,IACd,iBAAA,EAAmB;AAAA,GACvB,GAAI,KAAA;AACJ,EAAA,MAAM,EAAE,cAAA,EAAe,GAAI,uBAAA,CAAwB,oBAAoB,KAAK,CAAA;AAC5E,EAAA,MAAM,oBAAoB,IAAA,CAAK,aAAA,CAAc,EAAE,EAAA,EAAI,qBAAqB,CAAA;AAExE,EAAA,MAAM,aAAA,GAAgB,CAAC,OAAA,KAAsB;AACzC,IAAA,GAAA,CAAI,MA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
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @open-pioneer/basemap-switcher
|
|
2
2
|
|
|
3
|
+
## 1.2.0-dev.20251128143231
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 279ca67: Use `workspace:*` instead of `workspace:^` for local package references as default. This ensures that trails packages from this repository are always referenced with their exact version to avoid potential issues with version mismatches. If a project specifically wants to use other versions for some trails packages, a pnpm override can be used to force other versions.
|
|
8
|
+
- Updated dependencies [279ca67]
|
|
9
|
+
- @open-pioneer/map@1.2.0-dev.20251128143231
|
|
10
|
+
|
|
11
|
+
## 1.1.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- 10338fa: Update OpenLayers to 10.7.0
|
|
16
|
+
- c38b619: Layers that are not visible in the current resolution of the map are indicated with an icon and disabled text (but are still selectable by the user).
|
|
17
|
+
- a8b8a36: Update trails core packages to 4.3.0
|
|
18
|
+
- 10338fa: Update Chakra to 3.29.0
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- c38b619: Show the icon indicator and disabled text of the selected option also in collapsed state, not only in the list of options.
|
|
23
|
+
- Updated dependencies [fce7fa9]
|
|
24
|
+
- Updated dependencies [10338fa]
|
|
25
|
+
- Updated dependencies [a8b8a36]
|
|
26
|
+
- Updated dependencies [10338fa]
|
|
27
|
+
- Updated dependencies [c38b619]
|
|
28
|
+
- @open-pioneer/map@1.1.0
|
|
29
|
+
|
|
3
30
|
## 1.0.0
|
|
4
31
|
|
|
5
32
|
### Minor Changes
|
package/i18n/de.yaml
CHANGED
package/i18n/en.yaml
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/basemap-switcher",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.2.0-dev.20251128143231",
|
|
5
5
|
"description": "This package provides a UI component that allows a user to switch between different base maps.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,16 +14,16 @@
|
|
|
14
14
|
"directory": "src/packages/basemap-switcher"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@open-pioneer/react-utils": "^4.
|
|
18
|
-
"@open-pioneer/runtime": "^4.
|
|
19
|
-
"@chakra-ui/react": "^3.
|
|
20
|
-
"ol": "^10.
|
|
17
|
+
"@open-pioneer/react-utils": "^4.3.0",
|
|
18
|
+
"@open-pioneer/runtime": "^4.3.0",
|
|
19
|
+
"@chakra-ui/react": "^3.29.0",
|
|
20
|
+
"ol": "^10.7.0",
|
|
21
21
|
"react": "^19.2.0",
|
|
22
22
|
"react-icons": "^5.5.0",
|
|
23
|
-
"@open-pioneer/reactivity": "^4.
|
|
24
|
-
"@conterra/reactivity-core": "^0.8.
|
|
25
|
-
"@open-pioneer/chakra-snippets": "^4.
|
|
26
|
-
"@open-pioneer/map": "
|
|
23
|
+
"@open-pioneer/reactivity": "^4.3.0",
|
|
24
|
+
"@conterra/reactivity-core": "^0.8.1",
|
|
25
|
+
"@open-pioneer/chakra-snippets": "^4.3.0",
|
|
26
|
+
"@open-pioneer/map": "1.2.0-dev.20251128143231"
|
|
27
27
|
},
|
|
28
28
|
"exports": {
|
|
29
29
|
"./package.json": "./package.json",
|