@itwin/map-layers 4.0.0-dev.7 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) 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 +312 -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 +34 -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 +47 -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.js +2 -2
  18. package/lib/cjs/ui/Interfaces.js.map +1 -1
  19. package/lib/cjs/ui/MapFeatureInfoTool.d.ts +13 -13
  20. package/lib/cjs/ui/MapFeatureInfoTool.d.ts.map +1 -1
  21. package/lib/cjs/ui/MapFeatureInfoTool.js +50 -50
  22. package/lib/cjs/ui/MapFeatureInfoTool.js.map +1 -1
  23. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts +8 -8
  24. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  25. package/lib/cjs/ui/MapLayersUiItemsProvider.js +35 -38
  26. package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
  27. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  28. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  29. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +338 -338
  30. package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
  31. package/lib/cjs/ui/widget/BasemapPanel.d.ts +7 -8
  32. package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
  33. package/lib/cjs/ui/widget/BasemapPanel.js +156 -156
  34. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  35. package/lib/cjs/ui/widget/BasemapPanel.scss +87 -87
  36. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  37. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  38. package/lib/cjs/ui/widget/ConfirmMessageDialog.js +25 -25
  39. package/lib/cjs/ui/widget/ConfirmMessageDialog.js.map +1 -1
  40. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  41. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  42. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js +140 -139
  43. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  44. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts +6 -7
  45. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  46. package/lib/cjs/ui/widget/FeatureInfoWidget.js +76 -71
  47. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  48. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts +18 -19
  49. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  50. package/lib/cjs/ui/widget/MapLayerDroppable.js +88 -88
  51. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  52. package/lib/cjs/ui/widget/MapLayerManager.d.ts +26 -26
  53. package/lib/cjs/ui/widget/MapLayerManager.js +403 -403
  54. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  55. package/lib/cjs/ui/widget/MapLayerManager.scss +409 -409
  56. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  57. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  58. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +83 -83
  59. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  60. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  61. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  62. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +65 -65
  63. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  64. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  65. package/lib/cjs/ui/widget/MapLayersWidget.d.ts +10 -11
  66. package/lib/cjs/ui/widget/MapLayersWidget.d.ts.map +1 -1
  67. package/lib/cjs/ui/widget/MapLayersWidget.js +31 -31
  68. package/lib/cjs/ui/widget/MapLayersWidget.js.map +1 -1
  69. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +2 -3
  70. package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
  71. package/lib/cjs/ui/widget/MapManagerSettings.js +200 -200
  72. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  73. package/lib/cjs/ui/widget/MapManagerSettings.scss +29 -29
  74. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +22 -23
  75. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  76. package/lib/cjs/ui/widget/MapUrlDialog.js +533 -527
  77. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  78. package/lib/cjs/ui/widget/MapUrlDialog.scss +99 -100
  79. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +17 -18
  80. package/lib/cjs/ui/widget/SelectMapFormat.d.ts.map +1 -1
  81. package/lib/cjs/ui/widget/SelectMapFormat.js +59 -59
  82. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  83. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +18 -20
  84. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  85. package/lib/cjs/ui/widget/SubLayersDataProvider.js +75 -76
  86. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  87. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +9 -10
  88. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  89. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  90. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  91. package/lib/cjs/ui/widget/SubLayersTree.d.ts +14 -15
  92. package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
  93. package/lib/cjs/ui/widget/SubLayersTree.js +419 -419
  94. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  95. package/lib/cjs/ui/widget/SubLayersTree.scss +70 -69
  96. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +13 -14
  97. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  98. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  99. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  100. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +35 -36
  101. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  102. package/lib/esm/MapLayerPreferences.js +308 -308
  103. package/lib/esm/MapLayerPreferences.js.map +1 -1
  104. package/lib/esm/map-layers.d.ts +6 -6
  105. package/lib/esm/map-layers.js +10 -10
  106. package/lib/esm/mapLayers.d.ts +26 -44
  107. package/lib/esm/mapLayers.d.ts.map +1 -1
  108. package/lib/esm/mapLayers.js +30 -59
  109. package/lib/esm/mapLayers.js.map +1 -1
  110. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +16 -11
  111. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts.map +1 -1
  112. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +43 -48
  113. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  114. package/lib/esm/ui/Interfaces.d.ts +50 -50
  115. package/lib/esm/ui/Interfaces.js +1 -1
  116. package/lib/esm/ui/Interfaces.js.map +1 -1
  117. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  118. package/lib/esm/ui/MapFeatureInfoTool.d.ts.map +1 -1
  119. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  120. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  121. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  122. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts.map +1 -1
  123. package/lib/esm/ui/MapLayersUiItemsProvider.js +31 -34
  124. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  125. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +13 -14
  126. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
  127. package/lib/esm/ui/widget/AttachLayerPopupButton.js +334 -334
  128. package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
  129. package/lib/esm/ui/widget/BasemapPanel.d.ts +7 -8
  130. package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
  131. package/lib/esm/ui/widget/BasemapPanel.js +152 -152
  132. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  133. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  134. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +20 -21
  135. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts.map +1 -1
  136. package/lib/esm/ui/widget/ConfirmMessageDialog.js +21 -21
  137. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  138. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +35 -40
  139. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts.map +1 -1
  140. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +136 -135
  141. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  142. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +6 -7
  143. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts.map +1 -1
  144. package/lib/esm/ui/widget/FeatureInfoWidget.js +72 -67
  145. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  146. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +18 -19
  147. package/lib/esm/ui/widget/MapLayerDroppable.d.ts.map +1 -1
  148. package/lib/esm/ui/widget/MapLayerDroppable.js +84 -84
  149. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  150. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  151. package/lib/esm/ui/widget/MapLayerManager.js +398 -398
  152. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  153. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  154. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +11 -12
  155. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts.map +1 -1
  156. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +79 -79
  157. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  158. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +6 -7
  159. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts.map +1 -1
  160. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  161. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  162. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  163. package/lib/esm/ui/widget/MapLayersWidget.d.ts +10 -11
  164. package/lib/esm/ui/widget/MapLayersWidget.d.ts.map +1 -1
  165. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  166. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  167. package/lib/esm/ui/widget/MapManagerSettings.d.ts +2 -3
  168. package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
  169. package/lib/esm/ui/widget/MapManagerSettings.js +196 -196
  170. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  171. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  172. package/lib/esm/ui/widget/MapUrlDialog.d.ts +22 -23
  173. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  174. package/lib/esm/ui/widget/MapUrlDialog.js +529 -523
  175. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  176. package/lib/esm/ui/widget/MapUrlDialog.scss +99 -100
  177. package/lib/esm/ui/widget/SelectMapFormat.d.ts +17 -18
  178. package/lib/esm/ui/widget/SelectMapFormat.d.ts.map +1 -1
  179. package/lib/esm/ui/widget/SelectMapFormat.js +55 -55
  180. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  181. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +18 -20
  182. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts.map +1 -1
  183. package/lib/esm/ui/widget/SubLayersDataProvider.js +71 -72
  184. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  185. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +9 -10
  186. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts.map +1 -1
  187. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  188. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  189. package/lib/esm/ui/widget/SubLayersTree.d.ts +14 -15
  190. package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
  191. package/lib/esm/ui/widget/SubLayersTree.js +414 -414
  192. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  193. package/lib/esm/ui/widget/SubLayersTree.scss +70 -69
  194. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +13 -14
  195. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts.map +1 -1
  196. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  197. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  198. package/lib/esm/ui/widget/TransparencyPopupButton.scss +35 -36
  199. package/package.json +39 -38
@@ -1,404 +1,404 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- // cSpell:ignore droppable Sublayer Basemap
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.MapLayerManager = exports.useSourceMapContext = exports.SourceMapContext = void 0;
9
- // the following quiet warning caused by react-beautiful-dnd package
10
- /* eslint-disable @typescript-eslint/unbound-method */
11
- const core_bentley_1 = require("@itwin/core-bentley");
12
- const core_common_1 = require("@itwin/core-common");
13
- const core_frontend_1 = require("@itwin/core-frontend");
14
- const itwinui_react_1 = require("@itwin/itwinui-react");
15
- const React = require("react");
16
- const react_beautiful_dnd_1 = require("react-beautiful-dnd");
17
- const MapLayerPreferences_1 = require("../../MapLayerPreferences");
18
- const AttachLayerPopupButton_1 = require("./AttachLayerPopupButton");
19
- const BasemapPanel_1 = require("./BasemapPanel");
20
- const MapLayerDroppable_1 = require("./MapLayerDroppable");
21
- require("./MapLayerManager.scss");
22
- const MapLayerSettingsPopupButton_1 = require("./MapLayerSettingsPopupButton");
23
- const mapLayers_1 = require("../../mapLayers");
24
- /** @internal */
25
- exports.SourceMapContext = React.createContext({
26
- sources: [],
27
- loadingSources: false,
28
- bases: [],
29
- refreshFromStyle: () => { },
30
- });
31
- /** @internal */
32
- function useSourceMapContext() {
33
- return React.useContext(exports.SourceMapContext);
34
- }
35
- exports.useSourceMapContext = useSourceMapContext;
36
- function getSubLayerProps(subLayerSettings) {
37
- return subLayerSettings.map((subLayer) => subLayer.toJSON());
38
- }
39
- function getMapLayerSettingsFromViewport(viewport, getBackgroundMap, populateSubLayers = true) {
40
- const displayStyle = viewport.displayStyle;
41
- if (!displayStyle)
42
- return undefined;
43
- const layers = new Array();
44
- const displayStyleLayers = (getBackgroundMap ? displayStyle.backgroundMapLayers : displayStyle.overlayMapLayers);
45
- for (let layerIndex = 0; layerIndex < displayStyleLayers.length; layerIndex++) {
46
- const layerSettings = displayStyleLayers[layerIndex];
47
- const isOverlay = !getBackgroundMap;
48
- const layerProvider = viewport.getMapLayerImageryProvider(layerIndex, isOverlay);
49
- const treeVisibility = viewport.getMapLayerScaleRangeVisibility(layerIndex, isOverlay);
50
- const popSubLayers = populateSubLayers && (layerSettings instanceof core_common_1.ImageMapLayerSettings);
51
- layers.push({
52
- visible: layerSettings.visible,
53
- treeVisibility,
54
- name: layerSettings.name,
55
- source: layerSettings.source,
56
- transparency: layerSettings.transparency,
57
- transparentBackground: layerSettings.transparentBackground,
58
- subLayers: popSubLayers ? getSubLayerProps(layerSettings.subLayers) : undefined,
59
- showSubLayers: false,
60
- isOverlay,
61
- layerIndex,
62
- provider: layerProvider,
63
- });
64
- }
65
- // since we want to display higher level maps above lower maps in UI reverse their order here.
66
- return layers.reverse();
67
- }
68
- // eslint-disable-next-line @typescript-eslint/naming-convention
69
- function MapLayerManager(props) {
70
- var _a, _b;
71
- const [mapSources, setMapSources] = React.useState();
72
- const [loadingSources, setLoadingSources] = React.useState(false);
73
- const [baseSources, setBaseSources] = React.useState();
74
- const [overlaysLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Widget.OverlayLayers"));
75
- const [underlaysLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Widget.BackgroundLayers"));
76
- const { activeViewport, mapLayerOptions } = props;
77
- const hideExternalMapLayersSection = (mapLayerOptions === null || mapLayerOptions === void 0 ? void 0 : mapLayerOptions.hideExternalMapLayers) ? mapLayerOptions.hideExternalMapLayers : false;
78
- const fetchPublicMapLayerSources = (mapLayerOptions === null || mapLayerOptions === void 0 ? void 0 : mapLayerOptions.fetchPublicMapLayerSources) ? mapLayerOptions.fetchPublicMapLayerSources : false;
79
- // map layer settings from display style
80
- const [backgroundMapLayers, setBackgroundMapLayers] = React.useState(getMapLayerSettingsFromViewport(activeViewport, true));
81
- const [overlayMapLayers, setOverlayMapLayers] = React.useState(getMapLayerSettingsFromViewport(activeViewport, false));
82
- const loadMapLayerSettingsFromViewport = React.useCallback((viewport) => {
83
- setBackgroundMapLayers(getMapLayerSettingsFromViewport(viewport, true));
84
- setOverlayMapLayers(getMapLayerSettingsFromViewport(viewport, false));
85
- }, [setBackgroundMapLayers, setOverlayMapLayers]);
86
- const [backgroundMapVisible, setBackgroundMapVisible] = React.useState(() => {
87
- if (activeViewport) {
88
- return activeViewport.viewFlags.backgroundMap;
89
- }
90
- return false;
91
- });
92
- React.useEffect(() => {
93
- const updateBackgroundMapVisible = () => setBackgroundMapVisible(activeViewport.viewFlags.backgroundMap);
94
- return activeViewport.onDisplayStyleChanged.addListener(updateBackgroundMapVisible);
95
- }, [activeViewport]);
96
- // 'isMounted' is used to prevent any async operation once the hook has been
97
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
98
- const isMounted = React.useRef(false);
99
- React.useEffect(() => {
100
- isMounted.current = true;
101
- return () => {
102
- isMounted.current = false;
103
- };
104
- });
105
- // Setup onTileTreeLoad events listening.
106
- // This is needed because we need to know when the imagery provider
107
- // is created, and be able to monitor to status change.
108
- React.useEffect(() => {
109
- const handleTileTreeLoad = (args) => {
110
- // Ignore non-map tile trees
111
- if (args.tileTree instanceof core_frontend_1.ImageryMapTileTree) {
112
- loadMapLayerSettingsFromViewport(activeViewport);
113
- }
114
- };
115
- core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.addListener(handleTileTreeLoad);
116
- return () => {
117
- core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.removeListener(handleTileTreeLoad);
118
- };
119
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
120
- React.useEffect(() => {
121
- const handleScaleRangeVisibilityChanged = (layerIndexes) => {
122
- const updateLayers = (array) => {
123
- if (array === undefined)
124
- return undefined;
125
- return array.map((curStyledLayer) => {
126
- const foundScaleRangeVisibility = layerIndexes.find((layerIdx) => layerIdx.index === curStyledLayer.layerIndex && layerIdx.isOverlay === curStyledLayer.isOverlay);
127
- if (undefined === foundScaleRangeVisibility)
128
- return curStyledLayer;
129
- else
130
- return { ...curStyledLayer, treeVisibility: foundScaleRangeVisibility.visibility };
131
- });
132
- };
133
- setBackgroundMapLayers(updateLayers(backgroundMapLayers));
134
- setOverlayMapLayers(updateLayers(overlayMapLayers));
135
- };
136
- activeViewport.onMapLayerScaleRangeVisibilityChanged.addListener(handleScaleRangeVisibilityChanged);
137
- return () => {
138
- activeViewport.onMapLayerScaleRangeVisibilityChanged.removeListener(handleScaleRangeVisibilityChanged);
139
- };
140
- }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
141
- // Setup onMapImageryChanged events listening.
142
- React.useEffect(() => {
143
- const handleMapImageryChanged = (args) => {
144
- if (args.backgroundLayers.length !== (backgroundMapLayers ? backgroundMapLayers.length : 0)
145
- || args.overlayLayers.length !== (overlayMapLayers ? overlayMapLayers.length : 0)) {
146
- loadMapLayerSettingsFromViewport(activeViewport);
147
- }
148
- };
149
- activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
150
- return () => {
151
- activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.displayStyle.settings.onMapImageryChanged.removeListener(handleMapImageryChanged);
152
- };
153
- }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
154
- const handleProviderStatusChanged = React.useCallback((_args) => {
155
- loadMapLayerSettingsFromViewport(activeViewport);
156
- }, [loadMapLayerSettingsFromViewport, activeViewport]);
157
- // Triggered whenever a provider status change
158
- React.useEffect(() => {
159
- backgroundMapLayers === null || backgroundMapLayers === void 0 ? void 0 : backgroundMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.addListener(handleProviderStatusChanged); });
160
- overlayMapLayers === null || overlayMapLayers === void 0 ? void 0 : overlayMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.addListener(handleProviderStatusChanged); });
161
- return () => {
162
- backgroundMapLayers === null || backgroundMapLayers === void 0 ? void 0 : backgroundMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.removeListener(handleProviderStatusChanged); });
163
- overlayMapLayers === null || overlayMapLayers === void 0 ? void 0 : overlayMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.removeListener(handleProviderStatusChanged); });
164
- };
165
- }, [backgroundMapLayers, overlayMapLayers, activeViewport, loadMapLayerSettingsFromViewport, handleProviderStatusChanged]);
166
- // Monitor viewport updates, and refresh the widget accordingly.
167
- // Note: This is needed for multiple viewport applications.
168
- React.useEffect(() => {
169
- // Update background map status
170
- setBackgroundMapVisible(activeViewport.viewFlags.backgroundMap);
171
- // Refresh list of layers
172
- loadMapLayerSettingsFromViewport(activeViewport);
173
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
174
- React.useEffect(() => {
175
- async function fetchWmsMapData() {
176
- const sources = [];
177
- const bases = [];
178
- const sourceLayers = await core_frontend_1.MapLayerSources.create(undefined, (fetchPublicMapLayerSources && !hideExternalMapLayersSection));
179
- const iModel = core_frontend_1.IModelApp.viewManager.selectedView ? core_frontend_1.IModelApp.viewManager.selectedView.iModel : undefined;
180
- try {
181
- const preferenceSources = ((iModel === null || iModel === void 0 ? void 0 : iModel.iTwinId) === undefined
182
- ? []
183
- : await MapLayerPreferences_1.MapLayerPreferences.getSources(iModel === null || iModel === void 0 ? void 0 : iModel.iTwinId, iModel === null || iModel === void 0 ? void 0 : iModel.iModelId));
184
- for (const source of preferenceSources)
185
- await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(source);
186
- }
187
- catch (err) {
188
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.ErrorLoadingLayers"), core_bentley_1.BentleyError.getErrorMessage(err)));
189
- }
190
- if (!isMounted.current) {
191
- return;
192
- }
193
- // This is where the list of layers first gets populated... I need to update it
194
- // MapUrlDialog gets around knowing MapLayerManager exists and vice versa by affecting the viewports displayStyle which MapLayerManager is listening for
195
- // We know when displayStyle changes we've added a layer, this layer may not be a custom layer
196
- sourceLayers === null || sourceLayers === void 0 ? void 0 : sourceLayers.layers.forEach((source) => { sources.push(source); });
197
- setMapSources(sources);
198
- sourceLayers === null || sourceLayers === void 0 ? void 0 : sourceLayers.bases.forEach((source) => { bases.push(source); });
199
- setBaseSources(bases);
200
- }
201
- setLoadingSources(true);
202
- fetchWmsMapData().then(() => {
203
- if (isMounted.current) {
204
- setLoadingSources(false);
205
- }
206
- }).catch(() => {
207
- if (isMounted.current) {
208
- setLoadingSources(false);
209
- }
210
- });
211
- }, [setMapSources, fetchPublicMapLayerSources, hideExternalMapLayersSection]);
212
- const updateMapSources = React.useCallback(() => {
213
- var _a, _b;
214
- const newSources = [];
215
- (_b = (_a = core_frontend_1.MapLayerSources.getInstance()) === null || _a === void 0 ? void 0 : _a.layers) === null || _b === void 0 ? void 0 : _b.forEach((sourceLayer) => { newSources.push(sourceLayer); });
216
- setMapSources(newSources);
217
- }, [setMapSources]);
218
- /**
219
- * Handle change events in the MapLayerPreferences
220
- */
221
- React.useEffect(() => {
222
- const handleLayerSourceChange = async (changeType, oldSource, newSource) => {
223
- const removeSourceOnly = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
224
- const removeSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
225
- const addSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Added);
226
- if (removeSource) {
227
- if (oldSource) {
228
- const succeeded = core_frontend_1.MapLayerSources.removeLayerByName(oldSource.name);
229
- (0, core_bentley_1.assert)(succeeded);
230
- if (!succeeded) {
231
- return;
232
- }
233
- if (removeSourceOnly) {
234
- updateMapSources();
235
- return;
236
- }
237
- }
238
- }
239
- if (addSource) {
240
- const sources = await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(newSource);
241
- (0, core_bentley_1.assert)(sources !== undefined);
242
- if (sources) {
243
- updateMapSources();
244
- }
245
- }
246
- };
247
- MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.addListener(handleLayerSourceChange);
248
- return (() => {
249
- MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.removeListener(handleLayerSourceChange);
250
- });
251
- }, [updateMapSources]);
252
- // update when a different display style is loaded.
253
- React.useEffect(() => {
254
- const handleDisplayStyleChange = (vp) => {
255
- loadMapLayerSettingsFromViewport(vp);
256
- };
257
- activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.onDisplayStyleChanged.addListener(handleDisplayStyleChange);
258
- return () => {
259
- activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.onDisplayStyleChanged.removeListener(handleDisplayStyleChange);
260
- };
261
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
262
- const handleOnMenuItemSelection = React.useCallback((action, mapLayerSettings) => {
263
- if (!activeViewport || !activeViewport.displayStyle)
264
- return;
265
- const indexInDisplayStyle = activeViewport.displayStyle.findMapLayerIndexByNameAndSource(mapLayerSettings.name, mapLayerSettings.source, mapLayerSettings.isOverlay);
266
- if (indexInDisplayStyle < 0)
267
- return;
268
- switch (action) {
269
- case "delete":
270
- activeViewport.displayStyle.detachMapLayerByIndex(indexInDisplayStyle, mapLayerSettings.isOverlay);
271
- break;
272
- case "zoom-to-layer":
273
- activeViewport.displayStyle.viewMapLayerRange(indexInDisplayStyle, mapLayerSettings.isOverlay, activeViewport).then((status) => {
274
- if (!status) {
275
- const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.NoRangeDefined");
276
- core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, `${msg} [${mapLayerSettings.name}]`));
277
- }
278
- }).catch((_error) => { });
279
- break;
280
- }
281
- activeViewport.invalidateRenderPlan();
282
- // force UI to update
283
- loadMapLayerSettingsFromViewport(activeViewport);
284
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
285
- const handleLayerVisibilityChange = React.useCallback((mapLayerSettings) => {
286
- if (activeViewport) {
287
- const isVisible = !mapLayerSettings.visible;
288
- const displayStyle = activeViewport.displayStyle;
289
- const indexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(mapLayerSettings.name, mapLayerSettings.source, mapLayerSettings.isOverlay);
290
- if (-1 !== indexInDisplayStyle) {
291
- // update the display style
292
- displayStyle.changeMapLayerProps({ visible: isVisible }, indexInDisplayStyle, mapLayerSettings.isOverlay);
293
- activeViewport.invalidateRenderPlan();
294
- // force UI to update
295
- loadMapLayerSettingsFromViewport(activeViewport);
296
- }
297
- }
298
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
299
- const handleMapLayersToggle = React.useCallback(() => {
300
- if (activeViewport) {
301
- const newState = !backgroundMapVisible;
302
- activeViewport.viewFlags = activeViewport.viewFlags.with("backgroundMap", newState);
303
- setBackgroundMapVisible(newState);
304
- }
305
- }, [backgroundMapVisible, setBackgroundMapVisible, activeViewport]);
306
- const handleOnMapLayerDragEnd = React.useCallback((result /* , _provided: ResponderProvided*/) => {
307
- const { destination, source } = result;
308
- if (!destination) // dropped outside of list
309
- return;
310
- // item was not moved
311
- if (destination.droppableId === source.droppableId && destination.index === source.index)
312
- return;
313
- let fromMapLayer;
314
- if (source.droppableId === "overlayMapLayers" && overlayMapLayers)
315
- fromMapLayer = overlayMapLayers[source.index];
316
- else if (source.droppableId === "backgroundMapLayers" && backgroundMapLayers)
317
- fromMapLayer = backgroundMapLayers[source.index];
318
- if (!fromMapLayer || !activeViewport)
319
- return;
320
- const displayStyle = activeViewport.displayStyle;
321
- let toMapLayer;
322
- let toIndexInDisplayStyle = -1;
323
- // If destination.index is undefined then the user dropped the map at the end of list of maps. To get the "actual" index in the style, look up index in style by name.
324
- // We need to do this because the order of layers in UI are reversed so higher layers appear above lower layers.
325
- if (undefined !== destination.index) {
326
- if (destination.droppableId === "overlayMapLayers" && overlayMapLayers)
327
- toMapLayer = overlayMapLayers[destination.index];
328
- else if (destination.droppableId === "backgroundMapLayers" && backgroundMapLayers)
329
- toMapLayer = backgroundMapLayers[destination.index];
330
- if (toMapLayer)
331
- toIndexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(toMapLayer.name, toMapLayer.source, toMapLayer.isOverlay);
332
- }
333
- const fromIndexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(fromMapLayer.name, fromMapLayer.source, fromMapLayer.isOverlay);
334
- if (fromIndexInDisplayStyle < 0)
335
- return;
336
- if (destination.droppableId !== source.droppableId) {
337
- // see if we moved from "overlayMapLayers" to "backgroundMapLayers" or vice-versa
338
- const settings = activeViewport.displayStyle.mapLayerAtIndex(fromIndexInDisplayStyle, fromMapLayer.isOverlay);
339
- if (settings) {
340
- activeViewport.displayStyle.detachMapLayerByIndex(fromIndexInDisplayStyle, fromMapLayer.isOverlay);
341
- // Manually reverse index when moved from one section to the other
342
- if (fromMapLayer.isOverlay && backgroundMapLayers) {
343
- toIndexInDisplayStyle = displayStyle.backgroundMapLayers.length - destination.index;
344
- }
345
- else if (!fromMapLayer.isOverlay && overlayMapLayers) {
346
- toIndexInDisplayStyle = overlayMapLayers.length - destination.index;
347
- }
348
- activeViewport.displayStyle.attachMapLayer({ settings, isOverlay: !fromMapLayer.isOverlay, insertIndex: toIndexInDisplayStyle });
349
- }
350
- }
351
- else {
352
- if (undefined === destination.index) {
353
- displayStyle.moveMapLayerToBottom(fromIndexInDisplayStyle, destination.droppableId === "overlayMapLayers");
354
- }
355
- else {
356
- if (toMapLayer) {
357
- if (toIndexInDisplayStyle !== -1)
358
- displayStyle.moveMapLayerToIndex(fromIndexInDisplayStyle, toIndexInDisplayStyle, toMapLayer.isOverlay);
359
- }
360
- }
361
- }
362
- // apply display style change to view
363
- activeViewport.invalidateRenderPlan();
364
- // force UI to update
365
- loadMapLayerSettingsFromViewport(activeViewport);
366
- }, [loadMapLayerSettingsFromViewport, activeViewport, overlayMapLayers, backgroundMapLayers]);
367
- const handleRefreshFromStyle = React.useCallback(() => {
368
- if (activeViewport)
369
- loadMapLayerSettingsFromViewport(activeViewport);
370
- }, [activeViewport, loadMapLayerSettingsFromViewport]);
371
- const [baseMapPanelLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Basemap.BaseMapPanelTitle"));
372
- return (React.createElement(exports.SourceMapContext.Provider, { value: {
373
- activeViewport,
374
- loadingSources,
375
- sources: mapSources ? mapSources : [],
376
- bases: baseSources ? baseSources : [],
377
- refreshFromStyle: handleRefreshFromStyle,
378
- backgroundLayers: backgroundMapLayers,
379
- overlayLayers: overlayMapLayers,
380
- mapLayerOptions,
381
- } },
382
- React.createElement("div", { className: "map-manager-top-header" },
383
- React.createElement("span", { className: "map-manager-header-label" }, baseMapPanelLabel),
384
- React.createElement("div", { className: "map-manager-header-buttons-group" },
385
- React.createElement(itwinui_react_1.ToggleSwitch, { className: "map-manager-toggle", checked: backgroundMapVisible, onChange: handleMapLayersToggle }),
386
- React.createElement(MapLayerSettingsPopupButton_1.MapLayerSettingsPopupButton, { disabled: !backgroundMapVisible }))),
387
- React.createElement("div", { className: "map-manager-container" },
388
- React.createElement("div", { className: "map-manager-basemap" },
389
- React.createElement(BasemapPanel_1.BasemapPanel, { disabled: !backgroundMapVisible })),
390
- !hideExternalMapLayersSection &&
391
- React.createElement(react_beautiful_dnd_1.DragDropContext, { onDragEnd: handleOnMapLayerDragEnd },
392
- React.createElement("div", { className: "map-manager-layer-wrapper" },
393
- React.createElement("div", { className: "map-manager-underlays" },
394
- React.createElement("span", { className: "map-manager-underlays-label" }, underlaysLabel),
395
- React.createElement(AttachLayerPopupButton_1.AttachLayerPopupButton, { disabled: !backgroundMapVisible, isOverlay: false })),
396
- React.createElement(MapLayerDroppable_1.MapLayerDroppable, { disabled: !backgroundMapVisible, isOverlay: false, layersList: backgroundMapLayers, mapTypesOptions: (_a = props.mapLayerOptions) === null || _a === void 0 ? void 0 : _a.mapTypeOptions, getContainerForClone: props.getContainerForClone, activeViewport: props.activeViewport, onMenuItemSelected: handleOnMenuItemSelection, onItemVisibilityToggleClicked: handleLayerVisibilityChange, onItemEdited: handleRefreshFromStyle })),
397
- React.createElement("div", { className: "map-manager-layer-wrapper" },
398
- React.createElement("div", { className: "map-manager-overlays" },
399
- React.createElement("span", { className: "map-manager-overlays-label" }, overlaysLabel),
400
- React.createElement(AttachLayerPopupButton_1.AttachLayerPopupButton, { disabled: !backgroundMapVisible, isOverlay: true })),
401
- React.createElement(MapLayerDroppable_1.MapLayerDroppable, { disabled: !backgroundMapVisible, isOverlay: true, layersList: overlayMapLayers, mapTypesOptions: (_b = props.mapLayerOptions) === null || _b === void 0 ? void 0 : _b.mapTypeOptions, getContainerForClone: props.getContainerForClone, activeViewport: props.activeViewport, onMenuItemSelected: handleOnMenuItemSelection, onItemVisibilityToggleClicked: handleLayerVisibilityChange, onItemEdited: handleRefreshFromStyle }))))));
402
- }
403
- exports.MapLayerManager = MapLayerManager;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ // cSpell:ignore droppable Sublayer Basemap
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.MapLayerManager = exports.useSourceMapContext = exports.SourceMapContext = void 0;
9
+ // the following quiet warning caused by react-beautiful-dnd package
10
+ /* eslint-disable @typescript-eslint/unbound-method */
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_common_1 = require("@itwin/core-common");
13
+ const core_frontend_1 = require("@itwin/core-frontend");
14
+ const itwinui_react_1 = require("@itwin/itwinui-react");
15
+ const React = require("react");
16
+ const react_beautiful_dnd_1 = require("react-beautiful-dnd");
17
+ const MapLayerPreferences_1 = require("../../MapLayerPreferences");
18
+ const AttachLayerPopupButton_1 = require("./AttachLayerPopupButton");
19
+ const BasemapPanel_1 = require("./BasemapPanel");
20
+ const MapLayerDroppable_1 = require("./MapLayerDroppable");
21
+ require("./MapLayerManager.scss");
22
+ const MapLayerSettingsPopupButton_1 = require("./MapLayerSettingsPopupButton");
23
+ const mapLayers_1 = require("../../mapLayers");
24
+ /** @internal */
25
+ exports.SourceMapContext = React.createContext({
26
+ sources: [],
27
+ loadingSources: false,
28
+ bases: [],
29
+ refreshFromStyle: () => { },
30
+ });
31
+ /** @internal */
32
+ function useSourceMapContext() {
33
+ return React.useContext(exports.SourceMapContext);
34
+ }
35
+ exports.useSourceMapContext = useSourceMapContext;
36
+ function getSubLayerProps(subLayerSettings) {
37
+ return subLayerSettings.map((subLayer) => subLayer.toJSON());
38
+ }
39
+ function getMapLayerSettingsFromViewport(viewport, getBackgroundMap, populateSubLayers = true) {
40
+ const displayStyle = viewport.displayStyle;
41
+ if (!displayStyle)
42
+ return undefined;
43
+ const layers = new Array();
44
+ const displayStyleLayers = (getBackgroundMap ? displayStyle.backgroundMapLayers : displayStyle.overlayMapLayers);
45
+ for (let layerIndex = 0; layerIndex < displayStyleLayers.length; layerIndex++) {
46
+ const layerSettings = displayStyleLayers[layerIndex];
47
+ const isOverlay = !getBackgroundMap;
48
+ const layerProvider = viewport.getMapLayerImageryProvider(layerIndex, isOverlay);
49
+ const treeVisibility = viewport.getMapLayerScaleRangeVisibility(layerIndex, isOverlay);
50
+ const popSubLayers = populateSubLayers && (layerSettings instanceof core_common_1.ImageMapLayerSettings);
51
+ layers.push({
52
+ visible: layerSettings.visible,
53
+ treeVisibility,
54
+ name: layerSettings.name,
55
+ source: layerSettings.source,
56
+ transparency: layerSettings.transparency,
57
+ transparentBackground: layerSettings.transparentBackground,
58
+ subLayers: popSubLayers ? getSubLayerProps(layerSettings.subLayers) : undefined,
59
+ showSubLayers: false,
60
+ isOverlay,
61
+ layerIndex,
62
+ provider: layerProvider,
63
+ });
64
+ }
65
+ // since we want to display higher level maps above lower maps in UI reverse their order here.
66
+ return layers.reverse();
67
+ }
68
+ // eslint-disable-next-line @typescript-eslint/naming-convention
69
+ function MapLayerManager(props) {
70
+ var _a, _b;
71
+ const [mapSources, setMapSources] = React.useState();
72
+ const [loadingSources, setLoadingSources] = React.useState(false);
73
+ const [baseSources, setBaseSources] = React.useState();
74
+ const [overlaysLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Widget.OverlayLayers"));
75
+ const [underlaysLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Widget.BackgroundLayers"));
76
+ const { activeViewport, mapLayerOptions } = props;
77
+ const hideExternalMapLayersSection = (mapLayerOptions === null || mapLayerOptions === void 0 ? void 0 : mapLayerOptions.hideExternalMapLayers) ? mapLayerOptions.hideExternalMapLayers : false;
78
+ const fetchPublicMapLayerSources = (mapLayerOptions === null || mapLayerOptions === void 0 ? void 0 : mapLayerOptions.fetchPublicMapLayerSources) ? mapLayerOptions.fetchPublicMapLayerSources : false;
79
+ // map layer settings from display style
80
+ const [backgroundMapLayers, setBackgroundMapLayers] = React.useState(getMapLayerSettingsFromViewport(activeViewport, true));
81
+ const [overlayMapLayers, setOverlayMapLayers] = React.useState(getMapLayerSettingsFromViewport(activeViewport, false));
82
+ const loadMapLayerSettingsFromViewport = React.useCallback((viewport) => {
83
+ setBackgroundMapLayers(getMapLayerSettingsFromViewport(viewport, true));
84
+ setOverlayMapLayers(getMapLayerSettingsFromViewport(viewport, false));
85
+ }, [setBackgroundMapLayers, setOverlayMapLayers]);
86
+ const [backgroundMapVisible, setBackgroundMapVisible] = React.useState(() => {
87
+ if (activeViewport) {
88
+ return activeViewport.viewFlags.backgroundMap;
89
+ }
90
+ return false;
91
+ });
92
+ React.useEffect(() => {
93
+ const updateBackgroundMapVisible = () => setBackgroundMapVisible(activeViewport.viewFlags.backgroundMap);
94
+ return activeViewport.onDisplayStyleChanged.addListener(updateBackgroundMapVisible);
95
+ }, [activeViewport]);
96
+ // 'isMounted' is used to prevent any async operation once the hook has been
97
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
98
+ const isMounted = React.useRef(false);
99
+ React.useEffect(() => {
100
+ isMounted.current = true;
101
+ return () => {
102
+ isMounted.current = false;
103
+ };
104
+ });
105
+ // Setup onTileTreeLoad events listening.
106
+ // This is needed because we need to know when the imagery provider
107
+ // is created, and be able to monitor to status change.
108
+ React.useEffect(() => {
109
+ const handleTileTreeLoad = (args) => {
110
+ // Ignore non-map tile trees
111
+ if (args.tileTree instanceof core_frontend_1.ImageryMapTileTree) {
112
+ loadMapLayerSettingsFromViewport(activeViewport);
113
+ }
114
+ };
115
+ core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.addListener(handleTileTreeLoad);
116
+ return () => {
117
+ core_frontend_1.IModelApp.tileAdmin.onTileTreeLoad.removeListener(handleTileTreeLoad);
118
+ };
119
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
120
+ React.useEffect(() => {
121
+ const handleScaleRangeVisibilityChanged = (layerIndexes) => {
122
+ const updateLayers = (array) => {
123
+ if (array === undefined)
124
+ return undefined;
125
+ return array.map((curStyledLayer) => {
126
+ const foundScaleRangeVisibility = layerIndexes.find((layerIdx) => layerIdx.index === curStyledLayer.layerIndex && layerIdx.isOverlay === curStyledLayer.isOverlay);
127
+ if (undefined === foundScaleRangeVisibility)
128
+ return curStyledLayer;
129
+ else
130
+ return { ...curStyledLayer, treeVisibility: foundScaleRangeVisibility.visibility };
131
+ });
132
+ };
133
+ setBackgroundMapLayers(updateLayers(backgroundMapLayers));
134
+ setOverlayMapLayers(updateLayers(overlayMapLayers));
135
+ };
136
+ activeViewport.onMapLayerScaleRangeVisibilityChanged.addListener(handleScaleRangeVisibilityChanged);
137
+ return () => {
138
+ activeViewport.onMapLayerScaleRangeVisibilityChanged.removeListener(handleScaleRangeVisibilityChanged);
139
+ };
140
+ }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
141
+ // Setup onMapImageryChanged events listening.
142
+ React.useEffect(() => {
143
+ const handleMapImageryChanged = (args) => {
144
+ if (args.backgroundLayers.length !== (backgroundMapLayers ? backgroundMapLayers.length : 0)
145
+ || args.overlayLayers.length !== (overlayMapLayers ? overlayMapLayers.length : 0)) {
146
+ loadMapLayerSettingsFromViewport(activeViewport);
147
+ }
148
+ };
149
+ activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.displayStyle.settings.onMapImageryChanged.addListener(handleMapImageryChanged);
150
+ return () => {
151
+ activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.displayStyle.settings.onMapImageryChanged.removeListener(handleMapImageryChanged);
152
+ };
153
+ }, [activeViewport, backgroundMapLayers, loadMapLayerSettingsFromViewport, overlayMapLayers]);
154
+ const handleProviderStatusChanged = React.useCallback((_args) => {
155
+ loadMapLayerSettingsFromViewport(activeViewport);
156
+ }, [loadMapLayerSettingsFromViewport, activeViewport]);
157
+ // Triggered whenever a provider status change
158
+ React.useEffect(() => {
159
+ backgroundMapLayers === null || backgroundMapLayers === void 0 ? void 0 : backgroundMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.addListener(handleProviderStatusChanged); });
160
+ overlayMapLayers === null || overlayMapLayers === void 0 ? void 0 : overlayMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.addListener(handleProviderStatusChanged); });
161
+ return () => {
162
+ backgroundMapLayers === null || backgroundMapLayers === void 0 ? void 0 : backgroundMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.removeListener(handleProviderStatusChanged); });
163
+ overlayMapLayers === null || overlayMapLayers === void 0 ? void 0 : overlayMapLayers.forEach((layer) => { var _a; (_a = layer.provider) === null || _a === void 0 ? void 0 : _a.onStatusChanged.removeListener(handleProviderStatusChanged); });
164
+ };
165
+ }, [backgroundMapLayers, overlayMapLayers, activeViewport, loadMapLayerSettingsFromViewport, handleProviderStatusChanged]);
166
+ // Monitor viewport updates, and refresh the widget accordingly.
167
+ // Note: This is needed for multiple viewport applications.
168
+ React.useEffect(() => {
169
+ // Update background map status
170
+ setBackgroundMapVisible(activeViewport.viewFlags.backgroundMap);
171
+ // Refresh list of layers
172
+ loadMapLayerSettingsFromViewport(activeViewport);
173
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
174
+ React.useEffect(() => {
175
+ async function fetchWmsMapData() {
176
+ const sources = [];
177
+ const bases = [];
178
+ const sourceLayers = await core_frontend_1.MapLayerSources.create(undefined, (fetchPublicMapLayerSources && !hideExternalMapLayersSection));
179
+ const iModel = core_frontend_1.IModelApp.viewManager.selectedView ? core_frontend_1.IModelApp.viewManager.selectedView.iModel : undefined;
180
+ try {
181
+ const preferenceSources = ((iModel === null || iModel === void 0 ? void 0 : iModel.iTwinId) === undefined
182
+ ? []
183
+ : await MapLayerPreferences_1.MapLayerPreferences.getSources(iModel === null || iModel === void 0 ? void 0 : iModel.iTwinId, iModel === null || iModel === void 0 ? void 0 : iModel.iModelId));
184
+ for (const source of preferenceSources)
185
+ await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(source);
186
+ }
187
+ catch (err) {
188
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, core_frontend_1.IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.ErrorLoadingLayers"), core_bentley_1.BentleyError.getErrorMessage(err)));
189
+ }
190
+ if (!isMounted.current) {
191
+ return;
192
+ }
193
+ // This is where the list of layers first gets populated... I need to update it
194
+ // MapUrlDialog gets around knowing MapLayerManager exists and vice versa by affecting the viewports displayStyle which MapLayerManager is listening for
195
+ // We know when displayStyle changes we've added a layer, this layer may not be a custom layer
196
+ sourceLayers === null || sourceLayers === void 0 ? void 0 : sourceLayers.layers.forEach((source) => { sources.push(source); });
197
+ setMapSources(sources);
198
+ sourceLayers === null || sourceLayers === void 0 ? void 0 : sourceLayers.bases.forEach((source) => { bases.push(source); });
199
+ setBaseSources(bases);
200
+ }
201
+ setLoadingSources(true);
202
+ fetchWmsMapData().then(() => {
203
+ if (isMounted.current) {
204
+ setLoadingSources(false);
205
+ }
206
+ }).catch(() => {
207
+ if (isMounted.current) {
208
+ setLoadingSources(false);
209
+ }
210
+ });
211
+ }, [setMapSources, fetchPublicMapLayerSources, hideExternalMapLayersSection]);
212
+ const updateMapSources = React.useCallback(() => {
213
+ var _a, _b;
214
+ const newSources = [];
215
+ (_b = (_a = core_frontend_1.MapLayerSources.getInstance()) === null || _a === void 0 ? void 0 : _a.layers) === null || _b === void 0 ? void 0 : _b.forEach((sourceLayer) => { newSources.push(sourceLayer); });
216
+ setMapSources(newSources);
217
+ }, [setMapSources]);
218
+ /**
219
+ * Handle change events in the MapLayerPreferences
220
+ */
221
+ React.useEffect(() => {
222
+ const handleLayerSourceChange = async (changeType, oldSource, newSource) => {
223
+ const removeSourceOnly = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
224
+ const removeSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Removed);
225
+ const addSource = (changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Replaced || changeType === MapLayerPreferences_1.MapLayerSourceChangeType.Added);
226
+ if (removeSource) {
227
+ if (oldSource) {
228
+ const succeeded = core_frontend_1.MapLayerSources.removeLayerByName(oldSource.name);
229
+ (0, core_bentley_1.assert)(succeeded);
230
+ if (!succeeded) {
231
+ return;
232
+ }
233
+ if (removeSourceOnly) {
234
+ updateMapSources();
235
+ return;
236
+ }
237
+ }
238
+ }
239
+ if (addSource) {
240
+ const sources = await core_frontend_1.MapLayerSources.addSourceToMapLayerSources(newSource);
241
+ (0, core_bentley_1.assert)(sources !== undefined);
242
+ if (sources) {
243
+ updateMapSources();
244
+ }
245
+ }
246
+ };
247
+ MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.addListener(handleLayerSourceChange);
248
+ return (() => {
249
+ MapLayerPreferences_1.MapLayerPreferences.onLayerSourceChanged.removeListener(handleLayerSourceChange);
250
+ });
251
+ }, [updateMapSources]);
252
+ // update when a different display style is loaded.
253
+ React.useEffect(() => {
254
+ const handleDisplayStyleChange = (vp) => {
255
+ loadMapLayerSettingsFromViewport(vp);
256
+ };
257
+ activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.onDisplayStyleChanged.addListener(handleDisplayStyleChange);
258
+ return () => {
259
+ activeViewport === null || activeViewport === void 0 ? void 0 : activeViewport.onDisplayStyleChanged.removeListener(handleDisplayStyleChange);
260
+ };
261
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
262
+ const handleOnMenuItemSelection = React.useCallback((action, mapLayerSettings) => {
263
+ if (!activeViewport || !activeViewport.displayStyle)
264
+ return;
265
+ const indexInDisplayStyle = activeViewport.displayStyle.findMapLayerIndexByNameAndSource(mapLayerSettings.name, mapLayerSettings.source, mapLayerSettings.isOverlay);
266
+ if (indexInDisplayStyle < 0)
267
+ return;
268
+ switch (action) {
269
+ case "delete":
270
+ activeViewport.displayStyle.detachMapLayerByIndex(indexInDisplayStyle, mapLayerSettings.isOverlay);
271
+ break;
272
+ case "zoom-to-layer":
273
+ activeViewport.displayStyle.viewMapLayerRange(indexInDisplayStyle, mapLayerSettings.isOverlay, activeViewport).then((status) => {
274
+ if (!status) {
275
+ const msg = mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Messages.NoRangeDefined");
276
+ core_frontend_1.IModelApp.notifications.outputMessage(new core_frontend_1.NotifyMessageDetails(core_frontend_1.OutputMessagePriority.Error, `${msg} [${mapLayerSettings.name}]`));
277
+ }
278
+ }).catch((_error) => { });
279
+ break;
280
+ }
281
+ activeViewport.invalidateRenderPlan();
282
+ // force UI to update
283
+ loadMapLayerSettingsFromViewport(activeViewport);
284
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
285
+ const handleLayerVisibilityChange = React.useCallback((mapLayerSettings) => {
286
+ if (activeViewport) {
287
+ const isVisible = !mapLayerSettings.visible;
288
+ const displayStyle = activeViewport.displayStyle;
289
+ const indexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(mapLayerSettings.name, mapLayerSettings.source, mapLayerSettings.isOverlay);
290
+ if (-1 !== indexInDisplayStyle) {
291
+ // update the display style
292
+ displayStyle.changeMapLayerProps({ visible: isVisible }, indexInDisplayStyle, mapLayerSettings.isOverlay);
293
+ activeViewport.invalidateRenderPlan();
294
+ // force UI to update
295
+ loadMapLayerSettingsFromViewport(activeViewport);
296
+ }
297
+ }
298
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
299
+ const handleMapLayersToggle = React.useCallback(() => {
300
+ if (activeViewport) {
301
+ const newState = !backgroundMapVisible;
302
+ activeViewport.viewFlags = activeViewport.viewFlags.with("backgroundMap", newState);
303
+ setBackgroundMapVisible(newState);
304
+ }
305
+ }, [backgroundMapVisible, setBackgroundMapVisible, activeViewport]);
306
+ const handleOnMapLayerDragEnd = React.useCallback((result /* , _provided: ResponderProvided*/) => {
307
+ const { destination, source } = result;
308
+ if (!destination) // dropped outside of list
309
+ return;
310
+ // item was not moved
311
+ if (destination.droppableId === source.droppableId && destination.index === source.index)
312
+ return;
313
+ let fromMapLayer;
314
+ if (source.droppableId === "overlayMapLayers" && overlayMapLayers)
315
+ fromMapLayer = overlayMapLayers[source.index];
316
+ else if (source.droppableId === "backgroundMapLayers" && backgroundMapLayers)
317
+ fromMapLayer = backgroundMapLayers[source.index];
318
+ if (!fromMapLayer || !activeViewport)
319
+ return;
320
+ const displayStyle = activeViewport.displayStyle;
321
+ let toMapLayer;
322
+ let toIndexInDisplayStyle = -1;
323
+ // If destination.index is undefined then the user dropped the map at the end of list of maps. To get the "actual" index in the style, look up index in style by name.
324
+ // We need to do this because the order of layers in UI are reversed so higher layers appear above lower layers.
325
+ if (undefined !== destination.index) {
326
+ if (destination.droppableId === "overlayMapLayers" && overlayMapLayers)
327
+ toMapLayer = overlayMapLayers[destination.index];
328
+ else if (destination.droppableId === "backgroundMapLayers" && backgroundMapLayers)
329
+ toMapLayer = backgroundMapLayers[destination.index];
330
+ if (toMapLayer)
331
+ toIndexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(toMapLayer.name, toMapLayer.source, toMapLayer.isOverlay);
332
+ }
333
+ const fromIndexInDisplayStyle = displayStyle.findMapLayerIndexByNameAndSource(fromMapLayer.name, fromMapLayer.source, fromMapLayer.isOverlay);
334
+ if (fromIndexInDisplayStyle < 0)
335
+ return;
336
+ if (destination.droppableId !== source.droppableId) {
337
+ // see if we moved from "overlayMapLayers" to "backgroundMapLayers" or vice-versa
338
+ const settings = activeViewport.displayStyle.mapLayerAtIndex(fromIndexInDisplayStyle, fromMapLayer.isOverlay);
339
+ if (settings) {
340
+ activeViewport.displayStyle.detachMapLayerByIndex(fromIndexInDisplayStyle, fromMapLayer.isOverlay);
341
+ // Manually reverse index when moved from one section to the other
342
+ if (fromMapLayer.isOverlay && backgroundMapLayers) {
343
+ toIndexInDisplayStyle = displayStyle.backgroundMapLayers.length - destination.index;
344
+ }
345
+ else if (!fromMapLayer.isOverlay && overlayMapLayers) {
346
+ toIndexInDisplayStyle = overlayMapLayers.length - destination.index;
347
+ }
348
+ activeViewport.displayStyle.attachMapLayer({ settings, isOverlay: !fromMapLayer.isOverlay, insertIndex: toIndexInDisplayStyle });
349
+ }
350
+ }
351
+ else {
352
+ if (undefined === destination.index) {
353
+ displayStyle.moveMapLayerToBottom(fromIndexInDisplayStyle, destination.droppableId === "overlayMapLayers");
354
+ }
355
+ else {
356
+ if (toMapLayer) {
357
+ if (toIndexInDisplayStyle !== -1)
358
+ displayStyle.moveMapLayerToIndex(fromIndexInDisplayStyle, toIndexInDisplayStyle, toMapLayer.isOverlay);
359
+ }
360
+ }
361
+ }
362
+ // apply display style change to view
363
+ activeViewport.invalidateRenderPlan();
364
+ // force UI to update
365
+ loadMapLayerSettingsFromViewport(activeViewport);
366
+ }, [loadMapLayerSettingsFromViewport, activeViewport, overlayMapLayers, backgroundMapLayers]);
367
+ const handleRefreshFromStyle = React.useCallback(() => {
368
+ if (activeViewport)
369
+ loadMapLayerSettingsFromViewport(activeViewport);
370
+ }, [activeViewport, loadMapLayerSettingsFromViewport]);
371
+ const [baseMapPanelLabel] = React.useState(mapLayers_1.MapLayersUI.localization.getLocalizedString("mapLayers:Basemap.BaseMapPanelTitle"));
372
+ return (React.createElement(exports.SourceMapContext.Provider, { value: {
373
+ activeViewport,
374
+ loadingSources,
375
+ sources: mapSources ? mapSources : [],
376
+ bases: baseSources ? baseSources : [],
377
+ refreshFromStyle: handleRefreshFromStyle,
378
+ backgroundLayers: backgroundMapLayers,
379
+ overlayLayers: overlayMapLayers,
380
+ mapLayerOptions,
381
+ } },
382
+ React.createElement("div", { className: "map-manager-top-header" },
383
+ React.createElement("span", { className: "map-manager-header-label" }, baseMapPanelLabel),
384
+ React.createElement("div", { className: "map-manager-header-buttons-group" },
385
+ React.createElement(itwinui_react_1.ToggleSwitch, { className: "map-manager-toggle", checked: backgroundMapVisible, onChange: handleMapLayersToggle }),
386
+ React.createElement(MapLayerSettingsPopupButton_1.MapLayerSettingsPopupButton, { disabled: !backgroundMapVisible }))),
387
+ React.createElement("div", { className: "map-manager-container" },
388
+ React.createElement("div", { className: "map-manager-basemap" },
389
+ React.createElement(BasemapPanel_1.BasemapPanel, { disabled: !backgroundMapVisible })),
390
+ !hideExternalMapLayersSection &&
391
+ React.createElement(react_beautiful_dnd_1.DragDropContext, { onDragEnd: handleOnMapLayerDragEnd },
392
+ React.createElement("div", { className: "map-manager-layer-wrapper" },
393
+ React.createElement("div", { className: "map-manager-underlays" },
394
+ React.createElement("span", { className: "map-manager-underlays-label" }, underlaysLabel),
395
+ React.createElement(AttachLayerPopupButton_1.AttachLayerPopupButton, { disabled: !backgroundMapVisible, isOverlay: false })),
396
+ React.createElement(MapLayerDroppable_1.MapLayerDroppable, { disabled: !backgroundMapVisible, isOverlay: false, layersList: backgroundMapLayers, mapTypesOptions: (_a = props.mapLayerOptions) === null || _a === void 0 ? void 0 : _a.mapTypeOptions, getContainerForClone: props.getContainerForClone, activeViewport: props.activeViewport, onMenuItemSelected: handleOnMenuItemSelection, onItemVisibilityToggleClicked: handleLayerVisibilityChange, onItemEdited: handleRefreshFromStyle })),
397
+ React.createElement("div", { className: "map-manager-layer-wrapper" },
398
+ React.createElement("div", { className: "map-manager-overlays" },
399
+ React.createElement("span", { className: "map-manager-overlays-label" }, overlaysLabel),
400
+ React.createElement(AttachLayerPopupButton_1.AttachLayerPopupButton, { disabled: !backgroundMapVisible, isOverlay: true })),
401
+ React.createElement(MapLayerDroppable_1.MapLayerDroppable, { disabled: !backgroundMapVisible, isOverlay: true, layersList: overlayMapLayers, mapTypesOptions: (_b = props.mapLayerOptions) === null || _b === void 0 ? void 0 : _b.mapTypeOptions, getContainerForClone: props.getContainerForClone, activeViewport: props.activeViewport, onMenuItemSelected: handleOnMenuItemSelection, onItemVisibilityToggleClicked: handleLayerVisibilityChange, onItemEdited: handleRefreshFromStyle }))))));
402
+ }
403
+ exports.MapLayerManager = MapLayerManager;
404
404
  //# sourceMappingURL=MapLayerManager.js.map