@itwin/map-layers 4.0.0-dev.8 → 5.0.0-dev.2

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +746 -848
  2. package/README.md +32 -32
  3. package/lib/cjs/MapLayerPreferences.d.ts +88 -88
  4. package/lib/cjs/MapLayerPreferences.js +311 -312
  5. package/lib/cjs/MapLayerPreferences.js.map +1 -1
  6. package/lib/cjs/map-layers.d.ts +6 -6
  7. package/lib/cjs/map-layers.js +22 -22
  8. package/lib/cjs/mapLayers.d.ts +26 -44
  9. package/lib/cjs/mapLayers.d.ts.map +1 -1
  10. package/lib/cjs/mapLayers.js +33 -63
  11. package/lib/cjs/mapLayers.js.map +1 -1
  12. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  13. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  14. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js +46 -52
  15. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  16. package/lib/cjs/ui/Interfaces.d.ts +50 -50
  17. package/lib/cjs/ui/Interfaces.d.ts.map +1 -1
  18. package/lib/cjs/ui/Interfaces.js +2 -2
  19. package/lib/cjs/ui/Interfaces.js.map +1 -1
  20. package/lib/cjs/ui/MapFeatureInfoTool.d.ts +13 -13
  21. package/lib/cjs/ui/MapFeatureInfoTool.d.ts.map +1 -1
  22. package/lib/cjs/ui/MapFeatureInfoTool.js +50 -50
  23. package/lib/cjs/ui/MapFeatureInfoTool.js.map +1 -1
  24. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts +8 -8
  25. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  26. package/lib/cjs/ui/MapLayersUiItemsProvider.js +35 -38
  27. package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
  28. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  29. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  30. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +334 -338
  31. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  32. package/lib/cjs/ui/widget/BasemapPanel.d.ts +7 -8
  33. package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
  34. package/lib/cjs/ui/widget/BasemapPanel.js +151 -156
  35. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  36. package/lib/cjs/ui/widget/BasemapPanel.scss +87 -87
  37. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  38. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  39. package/lib/cjs/ui/widget/ConfirmMessageDialog.js +22 -25
  40. package/lib/cjs/ui/widget/ConfirmMessageDialog.js.map +1 -1
  41. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  42. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  43. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js +139 -139
  44. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  45. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts +6 -7
  46. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  47. package/lib/cjs/ui/widget/FeatureInfoWidget.js +70 -71
  48. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  49. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts +18 -19
  50. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  51. package/lib/cjs/ui/widget/MapLayerDroppable.js +85 -88
  52. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  53. package/lib/cjs/ui/widget/MapLayerManager.d.ts +26 -26
  54. package/lib/cjs/ui/widget/MapLayerManager.d.ts.map +1 -1
  55. package/lib/cjs/ui/widget/MapLayerManager.js +399 -403
  56. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  57. package/lib/cjs/ui/widget/MapLayerManager.scss +409 -409
  58. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  59. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  60. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +79 -83
  61. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  62. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  63. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  64. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +65 -65
  65. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  66. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  67. package/lib/cjs/ui/widget/MapLayersWidget.d.ts +10 -11
  68. package/lib/cjs/ui/widget/MapLayersWidget.d.ts.map +1 -1
  69. package/lib/cjs/ui/widget/MapLayersWidget.js +31 -31
  70. package/lib/cjs/ui/widget/MapLayersWidget.js.map +1 -1
  71. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +2 -3
  72. package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
  73. package/lib/cjs/ui/widget/MapManagerSettings.js +195 -200
  74. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  75. package/lib/cjs/ui/widget/MapManagerSettings.scss +29 -29
  76. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +22 -23
  77. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  78. package/lib/cjs/ui/widget/MapUrlDialog.js +528 -527
  79. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  80. package/lib/cjs/ui/widget/MapUrlDialog.scss +99 -100
  81. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +17 -18
  82. package/lib/cjs/ui/widget/SelectMapFormat.d.ts.map +1 -1
  83. package/lib/cjs/ui/widget/SelectMapFormat.js +54 -59
  84. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  85. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +18 -20
  86. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  87. package/lib/cjs/ui/widget/SubLayersDataProvider.js +74 -76
  88. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  89. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +9 -10
  90. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  91. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  92. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  93. package/lib/cjs/ui/widget/SubLayersTree.d.ts +14 -15
  94. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  95. package/lib/cjs/ui/widget/SubLayersTree.js +408 -419
  96. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  97. package/lib/cjs/ui/widget/SubLayersTree.scss +70 -69
  98. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +13 -14
  99. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  100. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  101. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  102. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +35 -36
  103. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  104. package/lib/esm/MapLayerPreferences.js +307 -308
  105. package/lib/esm/MapLayerPreferences.js.map +1 -1
  106. package/lib/esm/map-layers.d.ts +6 -6
  107. package/lib/esm/map-layers.js +10 -10
  108. package/lib/esm/mapLayers.d.ts +26 -44
  109. package/lib/esm/mapLayers.d.ts.map +1 -1
  110. package/lib/esm/mapLayers.js +29 -59
  111. package/lib/esm/mapLayers.js.map +1 -1
  112. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  113. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  114. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +42 -48
  115. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  116. package/lib/esm/ui/Interfaces.d.ts +50 -50
  117. package/lib/esm/ui/Interfaces.d.ts.map +1 -1
  118. package/lib/esm/ui/Interfaces.js +1 -1
  119. package/lib/esm/ui/Interfaces.js.map +1 -1
  120. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  121. package/lib/esm/ui/MapFeatureInfoTool.d.ts.map +1 -1
  122. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  123. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  124. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  125. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  126. package/lib/esm/ui/MapLayersUiItemsProvider.js +31 -34
  127. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  128. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  129. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  130. package/lib/esm/ui/widget/AttachLayerPopupButton.js +330 -334
  131. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  132. package/lib/esm/ui/widget/BasemapPanel.d.ts +7 -8
  133. package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
  134. package/lib/esm/ui/widget/BasemapPanel.js +147 -152
  135. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  136. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  137. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  138. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  139. package/lib/esm/ui/widget/ConfirmMessageDialog.js +18 -21
  140. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  141. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  142. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  143. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +135 -135
  144. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  145. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +6 -7
  146. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  147. package/lib/esm/ui/widget/FeatureInfoWidget.js +66 -67
  148. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  149. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +18 -19
  150. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  151. package/lib/esm/ui/widget/MapLayerDroppable.js +81 -84
  152. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  153. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  154. package/lib/esm/ui/widget/MapLayerManager.d.ts.map +1 -1
  155. package/lib/esm/ui/widget/MapLayerManager.js +394 -398
  156. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  157. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  158. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  159. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  160. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +75 -79
  161. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  162. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  163. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  164. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  165. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  166. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  167. package/lib/esm/ui/widget/MapLayersWidget.d.ts +10 -11
  168. package/lib/esm/ui/widget/MapLayersWidget.d.ts.map +1 -1
  169. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  170. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  171. package/lib/esm/ui/widget/MapManagerSettings.d.ts +2 -3
  172. package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
  173. package/lib/esm/ui/widget/MapManagerSettings.js +191 -196
  174. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  175. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  176. package/lib/esm/ui/widget/MapUrlDialog.d.ts +22 -23
  177. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  178. package/lib/esm/ui/widget/MapUrlDialog.js +524 -523
  179. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  180. package/lib/esm/ui/widget/MapUrlDialog.scss +99 -100
  181. package/lib/esm/ui/widget/SelectMapFormat.d.ts +17 -18
  182. package/lib/esm/ui/widget/SelectMapFormat.d.ts.map +1 -1
  183. package/lib/esm/ui/widget/SelectMapFormat.js +50 -55
  184. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  185. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +18 -20
  186. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  187. package/lib/esm/ui/widget/SubLayersDataProvider.js +70 -72
  188. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  189. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +9 -10
  190. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  191. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  192. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  193. package/lib/esm/ui/widget/SubLayersTree.d.ts +14 -15
  194. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  195. package/lib/esm/ui/widget/SubLayersTree.js +403 -414
  196. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  197. package/lib/esm/ui/widget/SubLayersTree.scss +70 -69
  198. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +13 -14
  199. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  200. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  201. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  202. package/lib/esm/ui/widget/TransparencyPopupButton.scss +35 -36
  203. package/package.json +39 -38
@@ -1,335 +1,331 @@
1
- /*---------------------------------------------------------------------------------------------
2
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
- * See LICENSE.md in the project root for license terms and full copyright notice.
4
- *--------------------------------------------------------------------------------------------*/
5
- import * as React from "react";
6
- import { IModelApp, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority } from "@itwin/core-frontend";
7
- import { RelativePosition } from "@itwin/appui-abstract";
8
- import * as UiCore from "@itwin/core-react";
9
- import { ModalDialogManager } from "@itwin/appui-react";
10
- import { useSourceMapContext } from "./MapLayerManager";
11
- import { MapUrlDialog } from "./MapUrlDialog";
12
- import { ConfirmMessageDialog } from "./ConfirmMessageDialog";
13
- import { Button, Input } from "@itwin/itwinui-react";
14
- import { MapLayerPreferences } from "../../MapLayerPreferences";
15
- import { MapLayersUI } from "../../mapLayers";
16
- // cSpell:ignore droppable Sublayer
17
- var LayerAction;
18
- (function (LayerAction) {
19
- LayerAction[LayerAction["Attached"] = 0] = "Attached";
20
- LayerAction[LayerAction["Edited"] = 1] = "Edited";
21
- })(LayerAction || (LayerAction = {}));
22
- // eslint-disable-next-line @typescript-eslint/naming-convention
23
- function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick }) {
24
- var _a, _b;
25
- const [layerNameToAdd, setLayerNameToAdd] = React.useState();
26
- const [sourceFilterString, setSourceFilterString] = React.useState();
27
- const { placeholderLabel, addCustomLayerLabel, addCustomLayerToolTip, loadingMapSources, removeLayerDefButtonTitle, editLayerDefButtonTitle, removeLayerDefDialogTitle } = React.useMemo(() => {
28
- return {
29
- placeholderLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.SearchPlaceholder"),
30
- addCustomLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Custom"),
31
- addCustomLayerToolTip: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.AttachCustomLayer"),
32
- loadingMapSources: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.LoadingMapSources"),
33
- removeLayerDefButtonTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefButtonTitle"),
34
- editLayerDefButtonTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.EditLayerDefButtonTitle"),
35
- removeLayerDefDialogTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefDialogTitle"),
36
- };
37
- }, []);
38
- const [loading, setLoading] = React.useState(false);
39
- const [layerNameUnderCursor, setLayerNameUnderCursor] = React.useState();
40
- const resumeOutsideClick = React.useCallback(() => {
41
- if (onHandleOutsideClick) {
42
- onHandleOutsideClick(true);
43
- }
44
- }, [onHandleOutsideClick]);
45
- // 'isMounted' is used to prevent any async operation once the hook has been
46
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
47
- const isMounted = React.useRef(false);
48
- React.useEffect(() => {
49
- isMounted.current = true;
50
- return () => {
51
- isMounted.current = false;
52
- // We close any open dialogs that we might have opened
53
- // This was added because the modal dialog remained remained displayed after the session expired.
54
- ModalDialogManager.closeDialog();
55
- };
56
- }, []);
57
- const handleFilterTextChanged = React.useCallback((event) => {
58
- setSourceFilterString(event.target.value);
59
- }, []);
60
- const { loadingSources, sources, activeViewport, backgroundLayers, overlayLayers, mapLayerOptions } = useSourceMapContext();
61
- const mapTypesOptions = mapLayerOptions === null || mapLayerOptions === void 0 ? void 0 : mapLayerOptions.mapTypeOptions;
62
- const iTwinId = (_a = activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.iModel) === null || _a === void 0 ? void 0 : _a.iTwinId;
63
- const iModelId = (_b = activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.iModel) === null || _b === void 0 ? void 0 : _b.iModelId;
64
- const styleContainsLayer = React.useCallback((name) => {
65
- if (backgroundLayers) {
66
- if (-1 !== backgroundLayers.findIndex((layer) => layer.name === name))
67
- return true;
68
- }
69
- if (overlayLayers) {
70
- if (-1 !== overlayLayers.findIndex((layer) => layer.name === name))
71
- return true;
72
- }
73
- return false;
74
- }, [backgroundLayers, overlayLayers]);
75
- const handleModalUrlDialogOk = React.useCallback((action) => {
76
- if (LayerAction.Attached === action) {
77
- // close popup and refresh UI
78
- onLayerAttached();
79
- }
80
- resumeOutsideClick();
81
- }, [onLayerAttached, resumeOutsideClick]);
82
- const handleModalUrlDialogCancel = React.useCallback(() => {
83
- // close popup and refresh UI
84
- setLoading(false);
85
- ModalDialogManager.closeDialog();
86
- resumeOutsideClick();
87
- }, [resumeOutsideClick]);
88
- React.useEffect(() => {
89
- async function attemptToAddLayer(layerName) {
90
- if (layerName && activeViewport) {
91
- // if the layer is not in the style add it now.
92
- if (undefined === (backgroundLayers === null || backgroundLayers === void 0 ? void 0 : backgroundLayers.find((layer) => layerName === layer.name)) && undefined === (overlayLayers === null || overlayLayers === void 0 ? void 0 : overlayLayers.find((layer) => layerName === layer.name))) {
93
- const mapLayerSettings = sources === null || sources === void 0 ? void 0 : sources.find((source) => source.name === layerName);
94
- if (mapLayerSettings === undefined) {
95
- return;
96
- }
97
- try {
98
- if (isMounted.current) {
99
- setLoading(true);
100
- }
101
- const { status, subLayers } = await mapLayerSettings.validateSource();
102
- if (status === MapLayerSourceStatus.Valid || status === MapLayerSourceStatus.RequireAuth) {
103
- if (status === MapLayerSourceStatus.Valid) {
104
- const settings = mapLayerSettings.toLayerSettings(subLayers);
105
- if (settings) {
106
- activeViewport.displayStyle.attachMapLayer({ settings, isOverlay });
107
- activeViewport.invalidateRenderPlan();
108
- const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: settings.name, sourceUrl: settings.url });
109
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
110
- }
111
- if (isMounted.current) {
112
- setLoading(false);
113
- }
114
- if (onLayerAttached) {
115
- onLayerAttached();
116
- }
117
- }
118
- else if (status === MapLayerSourceStatus.RequireAuth && isMounted.current) {
119
- ModalDialogManager.openDialog(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, layerRequiringCredentials: mapLayerSettings.toJSON(), onOkResult: () => handleModalUrlDialogOk(LayerAction.Attached), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
120
- if (onHandleOutsideClick) {
121
- onHandleOutsideClick(false);
122
- }
123
- }
124
- }
125
- else {
126
- const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerValidationFailed", { sourceUrl: mapLayerSettings.url });
127
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
128
- if (isMounted.current) {
129
- setLoading(false);
130
- }
131
- }
132
- }
133
- catch (err) {
134
- if (isMounted.current) {
135
- setLoading(false);
136
- }
137
- const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: err, sourceUrl: mapLayerSettings.url });
138
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
139
- }
140
- }
141
- }
142
- return;
143
- }
144
- if (layerNameToAdd) {
145
- attemptToAddLayer(layerNameToAdd); // eslint-disable-line @typescript-eslint/no-floating-promises
146
- if (isMounted.current) {
147
- setLayerNameToAdd(undefined);
148
- }
149
- }
150
- }, [setLayerNameToAdd, layerNameToAdd, activeViewport, sources, backgroundLayers, isOverlay, overlayLayers, onLayerAttached, handleModalUrlDialogOk, mapTypesOptions, handleModalUrlDialogCancel, onHandleOutsideClick]);
151
- const options = React.useMemo(() => sources === null || sources === void 0 ? void 0 : sources.filter((source) => !styleContainsLayer(source.name)), [sources, styleContainsLayer]);
152
- const filteredOptions = React.useMemo(() => {
153
- if (undefined === sourceFilterString || 0 === sourceFilterString.length) {
154
- return options;
155
- }
156
- else {
157
- return options === null || options === void 0 ? void 0 : options.filter((option) => option.name.toLowerCase().includes(sourceFilterString === null || sourceFilterString === void 0 ? void 0 : sourceFilterString.toLowerCase()));
158
- }
159
- }, [options, sourceFilterString]);
160
- const handleAddNewMapSource = React.useCallback(() => {
161
- ModalDialogManager.openDialog(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, onOkResult: () => handleModalUrlDialogOk(LayerAction.Attached), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
162
- if (onHandleOutsideClick) {
163
- onHandleOutsideClick(false);
164
- }
165
- return;
166
- }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapTypesOptions, onHandleOutsideClick]);
167
- const handleAttach = React.useCallback((mapName) => {
168
- setLayerNameToAdd(mapName);
169
- }, []);
170
- const handleKeypressOnSourceList = React.useCallback((event) => {
171
- var _a, _b;
172
- const key = event.key;
173
- if (key === "Enter") {
174
- event.preventDefault();
175
- const mapName = (_b = (_a = event.currentTarget) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.value;
176
- if (mapName && mapName.length) {
177
- handleAttach(mapName);
178
- }
179
- }
180
- }, [handleAttach]);
181
- const onListboxValueChange = React.useCallback((mapName) => {
182
- setLayerNameToAdd(mapName);
183
- }, []);
184
- const handleNoConfirmation = React.useCallback((_layerName) => {
185
- ModalDialogManager.closeDialog();
186
- resumeOutsideClick();
187
- }, [resumeOutsideClick]);
188
- const handleYesConfirmation = React.useCallback(async (source) => {
189
- const layerName = source.name;
190
- if (!!iTwinId) {
191
- try {
192
- await MapLayerPreferences.deleteByName(source, iTwinId, iModelId);
193
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefSuccess", { layerName });
194
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
195
- }
196
- catch (err) {
197
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefError", { layerName });
198
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
199
- }
200
- }
201
- ModalDialogManager.closeDialog();
202
- resumeOutsideClick();
203
- }, [iTwinId, iModelId, resumeOutsideClick]);
204
- /*
205
- Handle Remove layer button clicked
206
- */
207
- const onItemRemoveButtonClicked = React.useCallback((source, event) => {
208
- event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
209
- const layerName = source.name;
210
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefDialogMessage", { layerName });
211
- ModalDialogManager.openDialog(React.createElement(ConfirmMessageDialog, { className: "map-sources-delete-confirmation", title: removeLayerDefDialogTitle, message: msg, maxWidth: 400, onClose: () => handleNoConfirmation(layerName), onEscape: () => handleNoConfirmation(layerName), onYesResult: async () => handleYesConfirmation(source), onNoResult: () => handleNoConfirmation(layerName) }));
212
- if (onHandleOutsideClick) {
213
- onHandleOutsideClick(false);
214
- }
215
- }, [handleNoConfirmation, handleYesConfirmation, onHandleOutsideClick, removeLayerDefDialogTitle]);
216
- /*
217
- Handle Edit layer button clicked
218
- */
219
- const onItemEditButtonClicked = React.useCallback((event) => {
220
- var _a, _b, _c;
221
- event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
222
- const targetLayerName = (_c = (_b = (_a = event === null || event === void 0 ? void 0 : event.currentTarget) === null || _a === void 0 ? void 0 : _a.parentNode) === null || _b === void 0 ? void 0 : _b.dataset) === null || _c === void 0 ? void 0 : _c.value;
223
- const matchingSource = sources.find((layerSource) => layerSource.name === targetLayerName);
224
- // we expect a single layer source matching this name
225
- if (matchingSource === undefined) {
226
- return;
227
- }
228
- ModalDialogManager.openDialog(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, mapLayerSourceToEdit: matchingSource, onOkResult: () => handleModalUrlDialogOk(LayerAction.Edited), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
229
- if (onHandleOutsideClick) {
230
- onHandleOutsideClick(false);
231
- }
232
- }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapTypesOptions, onHandleOutsideClick, sources]);
233
- return (React.createElement("div", { className: "map-manager-header" },
234
- (loading || loadingSources) && React.createElement(UiCore.LoadingSpinner, { message: loadingMapSources }),
235
- React.createElement("div", { className: "map-manager-source-listbox-header" },
236
- React.createElement(Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged, size: "small" }),
237
- React.createElement(Button, { className: "map-manager-add-source-button", title: addCustomLayerToolTip, onClick: handleAddNewMapSource }, addCustomLayerLabel)),
238
- React.createElement("div", { className: "map-manager-sources" },
239
- React.createElement(UiCore.Listbox, { id: "map-sources", selectedValue: layerNameToAdd, className: "map-manager-source-list", onKeyPress: handleKeypressOnSourceList, onListboxValueChange: onListboxValueChange }, filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map((source) => React.createElement(UiCore.ListboxItem, { key: source.name, className: "map-source-list-entry", value: source.name, onMouseEnter: () => setLayerNameUnderCursor(source.name), onMouseLeave: () => setLayerNameUnderCursor(undefined) },
240
- React.createElement("span", { className: "map-source-list-entry-name", title: source.name }, source.name),
241
- // otherwise list feels cluttered.
242
- (!!iTwinId && layerNameUnderCursor && layerNameUnderCursor === source.name) &&
243
- React.createElement(React.Fragment, null,
244
- React.createElement(Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: editLayerDefButtonTitle, onClick: onItemEditButtonClicked },
245
- React.createElement(UiCore.Icon, { iconSpec: "icon-edit" })),
246
- React.createElement(Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: removeLayerDefButtonTitle, onClick: (event) => { onItemRemoveButtonClicked(source, event); } },
247
- React.createElement(UiCore.Icon, { iconSpec: "icon-delete" })))))))));
248
- }
249
- /** @internal */
250
- export var AttachLayerButtonType;
251
- (function (AttachLayerButtonType) {
252
- AttachLayerButtonType[AttachLayerButtonType["Primary"] = 0] = "Primary";
253
- AttachLayerButtonType[AttachLayerButtonType["Blue"] = 1] = "Blue";
254
- AttachLayerButtonType[AttachLayerButtonType["Icon"] = 2] = "Icon";
255
- })(AttachLayerButtonType || (AttachLayerButtonType = {}));
256
- /** @internal */
257
- // eslint-disable-next-line @typescript-eslint/naming-convention
258
- export function AttachLayerPopupButton(props) {
259
- const { showAttachLayerLabel, hideAttachLayerLabel, addCustomLayerButtonLabel } = React.useMemo(() => {
260
- return {
261
- showAttachLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:AttachLayerPopup.Attach"),
262
- hideAttachLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:AttachLayerPopup.Close"),
263
- addCustomLayerButtonLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.AddCustomLayerButtonLabel"),
264
- };
265
- }, []);
266
- const [handleOutsideClick, setHandleOutsideClick] = React.useState(true);
267
- const [popupOpen, setPopupOpen] = React.useState(false);
268
- const buttonRef = React.useRef(null);
269
- const panelRef = React.useRef(null);
270
- // 'isMounted' is used to prevent any async operation once the hook has been
271
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
272
- const isMounted = React.useRef(false);
273
- React.useEffect(() => {
274
- isMounted.current = true;
275
- return () => {
276
- isMounted.current = false;
277
- };
278
- }, []);
279
- const togglePopup = React.useCallback(() => {
280
- setPopupOpen(!popupOpen);
281
- }, [popupOpen]);
282
- const handleClosePopup = React.useCallback(() => {
283
- setPopupOpen(false);
284
- }, []);
285
- const onHandleOutsideClick = React.useCallback((event) => {
286
- if (!handleOutsideClick) {
287
- return;
288
- }
289
- // If clicking on button that open panel - don't trigger outside click processing
290
- if ((buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current) && (buttonRef === null || buttonRef === void 0 ? void 0 : buttonRef.current.contains(event.target))) {
291
- return;
292
- }
293
- // If clicking the panel, this is not an outside clicked
294
- if (panelRef.current && (panelRef === null || panelRef === void 0 ? void 0 : panelRef.current.contains(event.target))) {
295
- return;
296
- }
297
- // If we reach this point, we got an outside clicked, no close the popup
298
- setPopupOpen(false);
299
- }, [handleOutsideClick]);
300
- const { refreshFromStyle } = useSourceMapContext();
301
- const handleLayerAttached = React.useCallback(() => {
302
- if (!isMounted.current) {
303
- return;
304
- }
305
- setPopupOpen(false);
306
- refreshFromStyle();
307
- }, [refreshFromStyle]);
308
- function renderButton() {
309
- let button;
310
- if (props.buttonType === undefined || props.buttonType === AttachLayerButtonType.Icon) {
311
- button = (React.createElement(Button, { disabled: props.disabled, size: "small", styleType: "borderless", ref: buttonRef, className: "map-manager-attach-layer-button", title: popupOpen ? hideAttachLayerLabel : showAttachLayerLabel, onClick: togglePopup },
312
- React.createElement(UiCore.WebFontIcon, { iconName: "icon-add" })));
313
- }
314
- else {
315
- const determineStyleType = () => {
316
- switch (props.buttonType) {
317
- case AttachLayerButtonType.Blue:
318
- return "high-visibility";
319
- case AttachLayerButtonType.Primary:
320
- default:
321
- return "cta";
322
- }
323
- };
324
- const styleType = determineStyleType();
325
- button = (React.createElement(Button, { disabled: props.disabled, ref: buttonRef, styleType: styleType, title: popupOpen ? hideAttachLayerLabel : showAttachLayerLabel, onClick: togglePopup }, addCustomLayerButtonLabel));
326
- }
327
- return button;
328
- }
329
- return (React.createElement(React.Fragment, null,
330
- renderButton(),
331
- React.createElement(UiCore.Popup, { isOpen: popupOpen, position: RelativePosition.BottomRight, onClose: handleClosePopup, onOutsideClick: onHandleOutsideClick, target: buttonRef.current, closeOnEnter: false, closeOnContextMenu: false },
332
- React.createElement("div", { ref: panelRef, className: "map-sources-popup-panel" },
333
- React.createElement(AttachLayerPanel, { isOverlay: props.isOverlay, onLayerAttached: handleLayerAttached, onHandleOutsideClick: setHandleOutsideClick })))));
334
- }
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ import * as React from "react";
6
+ import { IModelApp, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority } from "@itwin/core-frontend";
7
+ import { RelativePosition } from "@itwin/appui-abstract";
8
+ import * as UiCore from "@itwin/core-react";
9
+ import { UiFramework } from "@itwin/appui-react";
10
+ import { useSourceMapContext } from "./MapLayerManager";
11
+ import { MapUrlDialog } from "./MapUrlDialog";
12
+ import { ConfirmMessageDialog } from "./ConfirmMessageDialog";
13
+ import { Button, Input } from "@itwin/itwinui-react";
14
+ import { MapLayerPreferences } from "../../MapLayerPreferences";
15
+ import { MapLayersUI } from "../../mapLayers";
16
+ // cSpell:ignore droppable Sublayer
17
+ var LayerAction;
18
+ (function (LayerAction) {
19
+ LayerAction[LayerAction["Attached"] = 0] = "Attached";
20
+ LayerAction[LayerAction["Edited"] = 1] = "Edited";
21
+ })(LayerAction || (LayerAction = {}));
22
+ // eslint-disable-next-line @typescript-eslint/naming-convention
23
+ function AttachLayerPanel({ isOverlay, onLayerAttached, onHandleOutsideClick }) {
24
+ const [layerNameToAdd, setLayerNameToAdd] = React.useState();
25
+ const [sourceFilterString, setSourceFilterString] = React.useState();
26
+ const { placeholderLabel, addCustomLayerLabel, addCustomLayerToolTip, loadingMapSources, removeLayerDefButtonTitle, editLayerDefButtonTitle, removeLayerDefDialogTitle } = React.useMemo(() => {
27
+ return {
28
+ placeholderLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.SearchPlaceholder"),
29
+ addCustomLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Custom"),
30
+ addCustomLayerToolTip: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.AttachCustomLayer"),
31
+ loadingMapSources: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.LoadingMapSources"),
32
+ removeLayerDefButtonTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefButtonTitle"),
33
+ editLayerDefButtonTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.EditLayerDefButtonTitle"),
34
+ removeLayerDefDialogTitle: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefDialogTitle"),
35
+ };
36
+ }, []);
37
+ const [loading, setLoading] = React.useState(false);
38
+ const [layerNameUnderCursor, setLayerNameUnderCursor] = React.useState();
39
+ const resumeOutsideClick = React.useCallback(() => {
40
+ if (onHandleOutsideClick) {
41
+ onHandleOutsideClick(true);
42
+ }
43
+ }, [onHandleOutsideClick]);
44
+ // 'isMounted' is used to prevent any async operation once the hook has been
45
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
46
+ const isMounted = React.useRef(false);
47
+ React.useEffect(() => {
48
+ isMounted.current = true;
49
+ return () => {
50
+ isMounted.current = false;
51
+ // We close any open dialogs that we might have opened
52
+ // This was added because the modal dialog remained remained displayed after the session expired.
53
+ UiFramework.dialogs.modal.close();
54
+ };
55
+ }, []);
56
+ const handleFilterTextChanged = React.useCallback((event) => {
57
+ setSourceFilterString(event.target.value);
58
+ }, []);
59
+ const { loadingSources, sources, activeViewport, backgroundLayers, overlayLayers, mapLayerOptions } = useSourceMapContext();
60
+ const mapTypesOptions = mapLayerOptions?.mapTypeOptions;
61
+ const iTwinId = activeViewport?.iModel?.iTwinId;
62
+ const iModelId = activeViewport?.iModel?.iModelId;
63
+ const styleContainsLayer = React.useCallback((name) => {
64
+ if (backgroundLayers) {
65
+ if (-1 !== backgroundLayers.findIndex((layer) => layer.name === name))
66
+ return true;
67
+ }
68
+ if (overlayLayers) {
69
+ if (-1 !== overlayLayers.findIndex((layer) => layer.name === name))
70
+ return true;
71
+ }
72
+ return false;
73
+ }, [backgroundLayers, overlayLayers]);
74
+ const handleModalUrlDialogOk = React.useCallback((action) => {
75
+ if (LayerAction.Attached === action) {
76
+ // close popup and refresh UI
77
+ onLayerAttached();
78
+ }
79
+ resumeOutsideClick();
80
+ }, [onLayerAttached, resumeOutsideClick]);
81
+ const handleModalUrlDialogCancel = React.useCallback(() => {
82
+ // close popup and refresh UI
83
+ setLoading(false);
84
+ UiFramework.dialogs.modal.close();
85
+ resumeOutsideClick();
86
+ }, [resumeOutsideClick]);
87
+ React.useEffect(() => {
88
+ async function attemptToAddLayer(layerName) {
89
+ if (layerName && activeViewport) {
90
+ // if the layer is not in the style add it now.
91
+ if (undefined === backgroundLayers?.find((layer) => layerName === layer.name) && undefined === overlayLayers?.find((layer) => layerName === layer.name)) {
92
+ const mapLayerSettings = sources?.find((source) => source.name === layerName);
93
+ if (mapLayerSettings === undefined) {
94
+ return;
95
+ }
96
+ try {
97
+ if (isMounted.current) {
98
+ setLoading(true);
99
+ }
100
+ const { status, subLayers } = await mapLayerSettings.validateSource();
101
+ if (status === MapLayerSourceStatus.Valid || status === MapLayerSourceStatus.RequireAuth) {
102
+ if (status === MapLayerSourceStatus.Valid) {
103
+ const settings = mapLayerSettings.toLayerSettings(subLayers);
104
+ if (settings) {
105
+ activeViewport.displayStyle.attachMapLayer({ settings, mapLayerIndex: { index: -1, isOverlay } });
106
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: settings.name, sourceUrl: settings.url });
107
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
108
+ }
109
+ if (isMounted.current) {
110
+ setLoading(false);
111
+ }
112
+ if (onLayerAttached) {
113
+ onLayerAttached();
114
+ }
115
+ }
116
+ else if (status === MapLayerSourceStatus.RequireAuth && isMounted.current) {
117
+ UiFramework.dialogs.modal.open(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, layerRequiringCredentials: mapLayerSettings.toJSON(), onOkResult: () => handleModalUrlDialogOk(LayerAction.Attached), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
118
+ if (onHandleOutsideClick) {
119
+ onHandleOutsideClick(false);
120
+ }
121
+ }
122
+ }
123
+ else {
124
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerValidationFailed", { sourceUrl: mapLayerSettings.url });
125
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
126
+ if (isMounted.current) {
127
+ setLoading(false);
128
+ }
129
+ }
130
+ }
131
+ catch (err) {
132
+ if (isMounted.current) {
133
+ setLoading(false);
134
+ }
135
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: err, sourceUrl: mapLayerSettings.url });
136
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
137
+ }
138
+ }
139
+ }
140
+ return;
141
+ }
142
+ if (layerNameToAdd) {
143
+ attemptToAddLayer(layerNameToAdd); // eslint-disable-line @typescript-eslint/no-floating-promises
144
+ if (isMounted.current) {
145
+ setLayerNameToAdd(undefined);
146
+ }
147
+ }
148
+ }, [setLayerNameToAdd, layerNameToAdd, activeViewport, sources, backgroundLayers, isOverlay, overlayLayers, onLayerAttached, handleModalUrlDialogOk, mapTypesOptions, handleModalUrlDialogCancel, onHandleOutsideClick]);
149
+ const options = React.useMemo(() => sources?.filter((source) => !styleContainsLayer(source.name)), [sources, styleContainsLayer]);
150
+ const filteredOptions = React.useMemo(() => {
151
+ if (undefined === sourceFilterString || 0 === sourceFilterString.length) {
152
+ return options;
153
+ }
154
+ else {
155
+ return options?.filter((option) => option.name.toLowerCase().includes(sourceFilterString?.toLowerCase()));
156
+ }
157
+ }, [options, sourceFilterString]);
158
+ const handleAddNewMapSource = React.useCallback(() => {
159
+ UiFramework.dialogs.modal.open(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, onOkResult: () => handleModalUrlDialogOk(LayerAction.Attached), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
160
+ if (onHandleOutsideClick) {
161
+ onHandleOutsideClick(false);
162
+ }
163
+ return;
164
+ }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapTypesOptions, onHandleOutsideClick]);
165
+ const handleAttach = React.useCallback((mapName) => {
166
+ setLayerNameToAdd(mapName);
167
+ }, []);
168
+ const handleKeypressOnSourceList = React.useCallback((event) => {
169
+ const key = event.key;
170
+ if (key === "Enter") {
171
+ event.preventDefault();
172
+ const mapName = event.currentTarget?.dataset?.value;
173
+ if (mapName && mapName.length) {
174
+ handleAttach(mapName);
175
+ }
176
+ }
177
+ }, [handleAttach]);
178
+ const onListboxValueChange = React.useCallback((mapName) => {
179
+ setLayerNameToAdd(mapName);
180
+ }, []);
181
+ const handleNoConfirmation = React.useCallback((_layerName) => {
182
+ UiFramework.dialogs.modal.close();
183
+ resumeOutsideClick();
184
+ }, [resumeOutsideClick]);
185
+ const handleYesConfirmation = React.useCallback(async (source) => {
186
+ const layerName = source.name;
187
+ if (!!iTwinId) {
188
+ try {
189
+ await MapLayerPreferences.deleteByName(source, iTwinId, iModelId);
190
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefSuccess", { layerName });
191
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
192
+ }
193
+ catch (err) {
194
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefError", { layerName });
195
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
196
+ }
197
+ }
198
+ UiFramework.dialogs.modal.close();
199
+ resumeOutsideClick();
200
+ }, [iTwinId, iModelId, resumeOutsideClick]);
201
+ /*
202
+ Handle Remove layer button clicked
203
+ */
204
+ const onItemRemoveButtonClicked = React.useCallback((source, event) => {
205
+ event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
206
+ const layerName = source.name;
207
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefDialogMessage", { layerName });
208
+ UiFramework.dialogs.modal.open(React.createElement(ConfirmMessageDialog, { className: "map-sources-delete-confirmation", title: removeLayerDefDialogTitle, message: msg, maxWidth: 400, onClose: () => handleNoConfirmation(layerName), onEscape: () => handleNoConfirmation(layerName), onYesResult: async () => handleYesConfirmation(source), onNoResult: () => handleNoConfirmation(layerName) }));
209
+ if (onHandleOutsideClick) {
210
+ onHandleOutsideClick(false);
211
+ }
212
+ }, [handleNoConfirmation, handleYesConfirmation, onHandleOutsideClick, removeLayerDefDialogTitle]);
213
+ /*
214
+ Handle Edit layer button clicked
215
+ */
216
+ const onItemEditButtonClicked = React.useCallback((event) => {
217
+ event.stopPropagation(); // We don't want the owning ListBox to react on mouse click.
218
+ const targetLayerName = event?.currentTarget?.parentNode?.dataset?.value;
219
+ const matchingSource = sources.find((layerSource) => layerSource.name === targetLayerName);
220
+ // we expect a single layer source matching this name
221
+ if (matchingSource === undefined) {
222
+ return;
223
+ }
224
+ UiFramework.dialogs.modal.open(React.createElement(MapUrlDialog, { activeViewport: activeViewport, isOverlay: isOverlay, mapLayerSourceToEdit: matchingSource, onOkResult: () => handleModalUrlDialogOk(LayerAction.Edited), onCancelResult: handleModalUrlDialogCancel, mapTypesOptions: mapTypesOptions }));
225
+ if (onHandleOutsideClick) {
226
+ onHandleOutsideClick(false);
227
+ }
228
+ }, [activeViewport, handleModalUrlDialogCancel, handleModalUrlDialogOk, isOverlay, mapTypesOptions, onHandleOutsideClick, sources]);
229
+ return (React.createElement("div", { className: "map-manager-header" },
230
+ (loading || loadingSources) && React.createElement(UiCore.LoadingSpinner, { message: loadingMapSources }),
231
+ React.createElement("div", { className: "map-manager-source-listbox-header" },
232
+ React.createElement(Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged, size: "small" }),
233
+ React.createElement(Button, { className: "map-manager-add-source-button", title: addCustomLayerToolTip, onClick: handleAddNewMapSource }, addCustomLayerLabel)),
234
+ React.createElement("div", { className: "map-manager-sources" },
235
+ React.createElement(UiCore.Listbox, { id: "map-sources", selectedValue: layerNameToAdd, className: "map-manager-source-list", onKeyPress: handleKeypressOnSourceList, onListboxValueChange: onListboxValueChange }, filteredOptions?.map((source) => React.createElement(UiCore.ListboxItem, { key: source.name, className: "map-source-list-entry", value: source.name, onMouseEnter: () => setLayerNameUnderCursor(source.name), onMouseLeave: () => setLayerNameUnderCursor(undefined) },
236
+ React.createElement("span", { className: "map-source-list-entry-name", title: source.name }, source.name),
237
+ // otherwise list feels cluttered.
238
+ (!!iTwinId && layerNameUnderCursor && layerNameUnderCursor === source.name) &&
239
+ React.createElement(React.Fragment, null,
240
+ React.createElement(Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: editLayerDefButtonTitle, onClick: onItemEditButtonClicked },
241
+ React.createElement(UiCore.Icon, { iconSpec: "icon-edit" })),
242
+ React.createElement(Button, { size: "small", styleType: "borderless", className: "map-source-list-entry-button", title: removeLayerDefButtonTitle, onClick: (event) => { onItemRemoveButtonClicked(source, event); } },
243
+ React.createElement(UiCore.Icon, { iconSpec: "icon-delete" })))))))));
244
+ }
245
+ /** @internal */
246
+ export var AttachLayerButtonType;
247
+ (function (AttachLayerButtonType) {
248
+ AttachLayerButtonType[AttachLayerButtonType["Primary"] = 0] = "Primary";
249
+ AttachLayerButtonType[AttachLayerButtonType["Blue"] = 1] = "Blue";
250
+ AttachLayerButtonType[AttachLayerButtonType["Icon"] = 2] = "Icon";
251
+ })(AttachLayerButtonType || (AttachLayerButtonType = {}));
252
+ /** @internal */
253
+ // eslint-disable-next-line @typescript-eslint/naming-convention
254
+ export function AttachLayerPopupButton(props) {
255
+ const { showAttachLayerLabel, hideAttachLayerLabel, addCustomLayerButtonLabel } = React.useMemo(() => {
256
+ return {
257
+ showAttachLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:AttachLayerPopup.Attach"),
258
+ hideAttachLayerLabel: MapLayersUI.localization.getLocalizedString("mapLayers:AttachLayerPopup.Close"),
259
+ addCustomLayerButtonLabel: MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.AddCustomLayerButtonLabel"),
260
+ };
261
+ }, []);
262
+ const [handleOutsideClick, setHandleOutsideClick] = React.useState(true);
263
+ const [popupOpen, setPopupOpen] = React.useState(false);
264
+ const buttonRef = React.useRef(null);
265
+ const panelRef = React.useRef(null);
266
+ // 'isMounted' is used to prevent any async operation once the hook has been
267
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
268
+ const isMounted = React.useRef(false);
269
+ React.useEffect(() => {
270
+ isMounted.current = true;
271
+ return () => {
272
+ isMounted.current = false;
273
+ };
274
+ }, []);
275
+ const togglePopup = React.useCallback(() => {
276
+ setPopupOpen(!popupOpen);
277
+ }, [popupOpen]);
278
+ const handleClosePopup = React.useCallback(() => {
279
+ setPopupOpen(false);
280
+ }, []);
281
+ const onHandleOutsideClick = React.useCallback((event) => {
282
+ if (!handleOutsideClick) {
283
+ return;
284
+ }
285
+ // If clicking on button that open panel - don't trigger outside click processing
286
+ if (buttonRef?.current && buttonRef?.current.contains(event.target)) {
287
+ return;
288
+ }
289
+ // If clicking the panel, this is not an outside clicked
290
+ if (panelRef.current && panelRef?.current.contains(event.target)) {
291
+ return;
292
+ }
293
+ // If we reach this point, we got an outside clicked, no close the popup
294
+ setPopupOpen(false);
295
+ }, [handleOutsideClick]);
296
+ const { refreshFromStyle } = useSourceMapContext();
297
+ const handleLayerAttached = React.useCallback(() => {
298
+ if (!isMounted.current) {
299
+ return;
300
+ }
301
+ setPopupOpen(false);
302
+ refreshFromStyle();
303
+ }, [refreshFromStyle]);
304
+ function renderButton() {
305
+ let button;
306
+ if (props.buttonType === undefined || props.buttonType === AttachLayerButtonType.Icon) {
307
+ button = (React.createElement(Button, { disabled: props.disabled, size: "small", styleType: "borderless", ref: buttonRef, className: "map-manager-attach-layer-button", title: popupOpen ? hideAttachLayerLabel : showAttachLayerLabel, onClick: togglePopup },
308
+ React.createElement(UiCore.WebFontIcon, { iconName: "icon-add" })));
309
+ }
310
+ else {
311
+ const determineStyleType = () => {
312
+ switch (props.buttonType) {
313
+ case AttachLayerButtonType.Blue:
314
+ return "high-visibility";
315
+ case AttachLayerButtonType.Primary:
316
+ default:
317
+ return "cta";
318
+ }
319
+ };
320
+ const styleType = determineStyleType();
321
+ button = (React.createElement(Button, { disabled: props.disabled, ref: buttonRef, styleType: styleType, title: popupOpen ? hideAttachLayerLabel : showAttachLayerLabel, onClick: togglePopup }, addCustomLayerButtonLabel));
322
+ }
323
+ return button;
324
+ }
325
+ return (React.createElement(React.Fragment, null,
326
+ renderButton(),
327
+ React.createElement(UiCore.Popup, { isOpen: popupOpen, position: RelativePosition.BottomRight, onClose: handleClosePopup, onOutsideClick: onHandleOutsideClick, target: buttonRef.current, closeOnEnter: false, closeOnContextMenu: false },
328
+ React.createElement("div", { ref: panelRef, className: "map-sources-popup-panel" },
329
+ React.createElement(AttachLayerPanel, { isOverlay: props.isOverlay, onLayerAttached: handleLayerAttached, onHandleOutsideClick: setHandleOutsideClick })))));
330
+ }
335
331
  //# sourceMappingURL=AttachLayerPopupButton.js.map