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