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