@itwin/map-layers 3.0.0-extension.0 → 3.1.0-dev.5
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 +82 -1
- package/README.md +1 -1
- package/lib/cjs/MapLayerPreferences.d.ts +89 -0
- package/lib/cjs/MapLayerPreferences.d.ts.map +1 -0
- package/lib/cjs/MapLayerPreferences.js +312 -0
- package/lib/cjs/MapLayerPreferences.js.map +1 -0
- package/lib/cjs/mapLayers.d.ts +18 -13
- package/lib/cjs/mapLayers.d.ts.map +1 -1
- package/lib/cjs/mapLayers.js +25 -17
- package/lib/cjs/mapLayers.js.map +1 -1
- package/lib/cjs/public/locales/en/mapLayers.json +5 -2
- package/lib/cjs/ui/MapLayersUiItemsProvider.js +1 -1
- package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
- package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
- package/lib/cjs/ui/widget/AttachLayerPopupButton.js +5 -3
- package/lib/cjs/ui/widget/AttachLayerPopupButton.js.map +1 -1
- package/lib/cjs/ui/widget/BasemapPanel.d.ts.map +1 -1
- package/lib/cjs/ui/widget/BasemapPanel.js +5 -4
- package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
- package/lib/cjs/ui/widget/MapLayerManager.d.ts +2 -2
- package/lib/cjs/ui/widget/MapLayerManager.d.ts.map +1 -1
- package/lib/cjs/ui/widget/MapLayerManager.js +24 -10
- package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
- package/lib/cjs/ui/widget/MapLayerManager.scss +0 -7
- package/lib/cjs/ui/widget/MapManagerSettings.d.ts.map +1 -1
- package/lib/cjs/ui/widget/MapManagerSettings.js +51 -22
- package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
- package/lib/cjs/ui/widget/MapManagerSettings.scss +1 -1
- package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
- package/lib/cjs/ui/widget/MapUrlDialog.js +231 -161
- package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
- package/lib/cjs/ui/widget/SubLayersTree.d.ts.map +1 -1
- package/lib/cjs/ui/widget/SubLayersTree.js +1 -1
- package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
- package/lib/cjs/ui/widget/TransparencyPopupButton.js +2 -2
- package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
- package/lib/esm/MapLayerPreferences.d.ts +89 -0
- package/lib/esm/MapLayerPreferences.d.ts.map +1 -0
- package/lib/esm/MapLayerPreferences.js +308 -0
- package/lib/esm/MapLayerPreferences.js.map +1 -0
- package/lib/esm/mapLayers.d.ts +18 -13
- package/lib/esm/mapLayers.d.ts.map +1 -1
- package/lib/esm/mapLayers.js +26 -18
- package/lib/esm/mapLayers.js.map +1 -1
- package/lib/esm/public/locales/en/mapLayers.json +5 -2
- package/lib/esm/ui/MapLayersUiItemsProvider.js +1 -1
- package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
- package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts.map +1 -1
- package/lib/esm/ui/widget/AttachLayerPopupButton.js +6 -4
- package/lib/esm/ui/widget/AttachLayerPopupButton.js.map +1 -1
- package/lib/esm/ui/widget/BasemapPanel.d.ts.map +1 -1
- package/lib/esm/ui/widget/BasemapPanel.js +6 -5
- package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
- package/lib/esm/ui/widget/MapLayerManager.d.ts +2 -2
- package/lib/esm/ui/widget/MapLayerManager.d.ts.map +1 -1
- package/lib/esm/ui/widget/MapLayerManager.js +21 -7
- package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
- package/lib/esm/ui/widget/MapLayerManager.scss +0 -7
- package/lib/esm/ui/widget/MapManagerSettings.d.ts.map +1 -1
- package/lib/esm/ui/widget/MapManagerSettings.js +53 -24
- package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
- package/lib/esm/ui/widget/MapManagerSettings.scss +1 -1
- package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
- package/lib/esm/ui/widget/MapUrlDialog.js +233 -163
- package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
- package/lib/esm/ui/widget/SubLayersTree.d.ts.map +1 -1
- package/lib/esm/ui/widget/SubLayersTree.js +1 -1
- package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
- package/lib/esm/ui/widget/TransparencyPopupButton.js +2 -2
- package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
- package/lib/public/locales/en/mapLayers.json +5 -2
- package/package.json +34 -39
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { IModelApp, MapLayerSource, NotifyMessageDetails, OutputMessagePriority } from "@itwin/core-frontend";
|
|
6
|
+
import { BeEvent } from "@itwin/core-bentley";
|
|
7
|
+
import { MapLayersUI } from "./mapLayers";
|
|
8
|
+
/** @internal */
|
|
9
|
+
export var MapLayerSourceChangeType;
|
|
10
|
+
(function (MapLayerSourceChangeType) {
|
|
11
|
+
MapLayerSourceChangeType[MapLayerSourceChangeType["Added"] = 0] = "Added";
|
|
12
|
+
MapLayerSourceChangeType[MapLayerSourceChangeType["Removed"] = 1] = "Removed";
|
|
13
|
+
MapLayerSourceChangeType[MapLayerSourceChangeType["Replaced"] = 2] = "Replaced";
|
|
14
|
+
})(MapLayerSourceChangeType || (MapLayerSourceChangeType = {}));
|
|
15
|
+
/** A wrapper around user preferences to provide a way to store [[MapLayerSettings]].
|
|
16
|
+
*
|
|
17
|
+
* Note: This is currently internal only and used directly by the MapLayersExtension. It makes use of the IModelApp.authorizationClient if it exists.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export class MapLayerPreferences {
|
|
22
|
+
/** Store the Map Layer source preference. If the same setting exists at a higher level, an error will be thrown and the setting will not be updated.
|
|
23
|
+
*
|
|
24
|
+
* Returns false if the settings object would override some other settings object in a larger scope i.e. storing settings on model when
|
|
25
|
+
* a project setting exists with same name or map layer url.
|
|
26
|
+
* @param source source to be stored on the setting service
|
|
27
|
+
* @param storeOnIModel if true store the settings object on the model, if false store it on the project
|
|
28
|
+
*/
|
|
29
|
+
static async storeSource(source, storeOnIModel, iTwinId, iModelId) {
|
|
30
|
+
if (!MapLayersUI.iTwinConfig)
|
|
31
|
+
return false;
|
|
32
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
33
|
+
const sourceJSON = source.toJSON();
|
|
34
|
+
const mapLayerSetting = {
|
|
35
|
+
url: sourceJSON.url,
|
|
36
|
+
name: sourceJSON.name,
|
|
37
|
+
formatId: sourceJSON.formatId,
|
|
38
|
+
transparentBackground: sourceJSON.transparentBackground,
|
|
39
|
+
};
|
|
40
|
+
const result = await MapLayerPreferences.delete(sourceJSON.url, sourceJSON.name, iTwinId, iModelId, storeOnIModel);
|
|
41
|
+
if (result) {
|
|
42
|
+
await MapLayersUI.iTwinConfig.save({
|
|
43
|
+
accessToken,
|
|
44
|
+
content: mapLayerSetting,
|
|
45
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
46
|
+
key: sourceJSON.name,
|
|
47
|
+
iTwinId,
|
|
48
|
+
iModelId: storeOnIModel ? iModelId : undefined,
|
|
49
|
+
});
|
|
50
|
+
MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Added, undefined, MapLayerSource.fromJSON(mapLayerSetting));
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/** Replace the old map layer source with a new map layer source.
|
|
58
|
+
*
|
|
59
|
+
* The source is replaced at the same level that the original source is defined. (i.e. if the old source is defined at a project level, the new source will also be defined there.)
|
|
60
|
+
*
|
|
61
|
+
* @param oldSource
|
|
62
|
+
* @param newSource
|
|
63
|
+
* @param projectId
|
|
64
|
+
* @param iModelId
|
|
65
|
+
*/
|
|
66
|
+
static async replaceSource(oldSource, newSource, projectId, iModelId) {
|
|
67
|
+
if (!MapLayersUI.iTwinConfig)
|
|
68
|
+
return;
|
|
69
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
70
|
+
let storeOnIModel = false;
|
|
71
|
+
try {
|
|
72
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
73
|
+
accessToken,
|
|
74
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
75
|
+
key: oldSource.name,
|
|
76
|
+
iTwinId: projectId,
|
|
77
|
+
iModelId,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
catch (_err) {
|
|
81
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
82
|
+
accessToken,
|
|
83
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
84
|
+
key: oldSource.name,
|
|
85
|
+
iTwinId: projectId,
|
|
86
|
+
});
|
|
87
|
+
storeOnIModel = true;
|
|
88
|
+
}
|
|
89
|
+
const mapLayerSetting = {
|
|
90
|
+
url: newSource.url,
|
|
91
|
+
name: newSource.name,
|
|
92
|
+
formatId: newSource.formatId,
|
|
93
|
+
transparentBackground: newSource.transparentBackground,
|
|
94
|
+
};
|
|
95
|
+
await MapLayersUI.iTwinConfig.save({
|
|
96
|
+
accessToken,
|
|
97
|
+
key: `${MapLayerPreferences._preferenceNamespace}.${newSource.name}`,
|
|
98
|
+
iTwinId: projectId,
|
|
99
|
+
iModelId: storeOnIModel ? iModelId : undefined,
|
|
100
|
+
content: mapLayerSetting,
|
|
101
|
+
});
|
|
102
|
+
MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Replaced, oldSource, newSource);
|
|
103
|
+
}
|
|
104
|
+
/** Deletes the provided MapLayerSource by name from both the iTwin or iModel level.
|
|
105
|
+
*
|
|
106
|
+
* @param source The source to delete. The name is used to identify the source.
|
|
107
|
+
* @param iTwinId
|
|
108
|
+
* @param iModelId
|
|
109
|
+
*/
|
|
110
|
+
static async deleteByName(source, iTwinId, iModelId) {
|
|
111
|
+
if (!MapLayersUI.iTwinConfig)
|
|
112
|
+
return;
|
|
113
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
114
|
+
try {
|
|
115
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
116
|
+
accessToken,
|
|
117
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
118
|
+
key: source.name,
|
|
119
|
+
iTwinId,
|
|
120
|
+
iModelId,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
catch (_err) {
|
|
124
|
+
// failed to store based on iModelId, attempt using iTwinId
|
|
125
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
126
|
+
accessToken,
|
|
127
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
128
|
+
key: source.name,
|
|
129
|
+
iTwinId,
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Removed, source, undefined);
|
|
133
|
+
}
|
|
134
|
+
/** Deletes the current setting with the provided key if it is defined at the same preference level.
|
|
135
|
+
*
|
|
136
|
+
* If the preference is defined within a different level, false will be returned indicating the setting should not be overriden.
|
|
137
|
+
*
|
|
138
|
+
* The two potential preference levels are iTwin and iModel.
|
|
139
|
+
*
|
|
140
|
+
* @param url
|
|
141
|
+
* @param name
|
|
142
|
+
* @param iTwinId
|
|
143
|
+
* @param iModelId
|
|
144
|
+
* @param storeOnIModel
|
|
145
|
+
*/
|
|
146
|
+
static async delete(url, name, iTwinId, iModelId, storeOnIModel) {
|
|
147
|
+
if (!MapLayersUI.iTwinConfig)
|
|
148
|
+
return true;
|
|
149
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
150
|
+
const iTwinPreferenceByName = await MapLayersUI.iTwinConfig.get({
|
|
151
|
+
accessToken,
|
|
152
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
153
|
+
key: name,
|
|
154
|
+
iTwinId,
|
|
155
|
+
});
|
|
156
|
+
if (undefined !== iTwinPreferenceByName && storeOnIModel) {
|
|
157
|
+
const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerExistsAsProjectSetting", { layer: iTwinPreferenceByName.name });
|
|
158
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
else if (iTwinPreferenceByName) {
|
|
162
|
+
const infoMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerExistsOverwriting", { layer: iTwinPreferenceByName.name });
|
|
163
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));
|
|
164
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
165
|
+
accessToken,
|
|
166
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
167
|
+
key: iTwinPreferenceByName.name,
|
|
168
|
+
iTwinId,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// check if setting with url already exists, if it does, delete it
|
|
172
|
+
const settingFromUrl = await MapLayerPreferences.getByUrl(url, iTwinId, undefined);
|
|
173
|
+
if (settingFromUrl && storeOnIModel) {
|
|
174
|
+
const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerWithUrlExistsAsProjectSetting", { url: settingFromUrl.url, name: settingFromUrl.name });
|
|
175
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
else if (settingFromUrl) {
|
|
179
|
+
const infoMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerWithUrlExistsOverwriting", { url: settingFromUrl.url, oldName: settingFromUrl.name, newName: name });
|
|
180
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));
|
|
181
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
182
|
+
accessToken,
|
|
183
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
184
|
+
key: settingFromUrl.name,
|
|
185
|
+
iTwinId,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
if (iModelId) { // delete any settings on model so user can update them if theres collisions
|
|
189
|
+
const settingOnIModelFromName = await MapLayersUI.iTwinConfig.get({
|
|
190
|
+
accessToken,
|
|
191
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
192
|
+
key: name,
|
|
193
|
+
iTwinId,
|
|
194
|
+
iModelId,
|
|
195
|
+
});
|
|
196
|
+
const settingFromUrlOnIModel = await MapLayerPreferences.getByUrl(url, iTwinId, iModelId);
|
|
197
|
+
if (settingOnIModelFromName) {
|
|
198
|
+
const infoMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerExistsOverwriting", { layer: settingOnIModelFromName.name });
|
|
199
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));
|
|
200
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
201
|
+
accessToken,
|
|
202
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
203
|
+
key: settingOnIModelFromName.name,
|
|
204
|
+
iTwinId,
|
|
205
|
+
iModelId,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
if (settingFromUrlOnIModel) {
|
|
209
|
+
const infoMessage = IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.LayerWithUrlExistsOverwriting", { url: settingFromUrlOnIModel.url, oldName: settingFromUrlOnIModel.name, newName: name });
|
|
210
|
+
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));
|
|
211
|
+
await MapLayersUI.iTwinConfig.delete({
|
|
212
|
+
accessToken,
|
|
213
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
214
|
+
key: settingFromUrlOnIModel.name,
|
|
215
|
+
iTwinId,
|
|
216
|
+
iModelId,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
/** Attempts to get a map layer based off a specific url.
|
|
223
|
+
* @param url
|
|
224
|
+
* @param projectId
|
|
225
|
+
* @param iModelId
|
|
226
|
+
*/
|
|
227
|
+
static async getByUrl(url, projectId, iModelId) {
|
|
228
|
+
var _a;
|
|
229
|
+
if (!MapLayersUI.iTwinConfig)
|
|
230
|
+
return undefined;
|
|
231
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
232
|
+
const settingResponse = await MapLayersUI.iTwinConfig.get({
|
|
233
|
+
accessToken,
|
|
234
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
235
|
+
key: "",
|
|
236
|
+
iTwinId: projectId,
|
|
237
|
+
iModelId,
|
|
238
|
+
});
|
|
239
|
+
if (undefined === settingResponse || 0 === settingResponse.length)
|
|
240
|
+
return undefined;
|
|
241
|
+
let savedMapLayer;
|
|
242
|
+
(_a = settingResponse.settingsMap) === null || _a === void 0 ? void 0 : _a.forEach((savedLayer) => {
|
|
243
|
+
if (savedLayer.url === url) {
|
|
244
|
+
savedMapLayer = savedLayer;
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
return savedMapLayer;
|
|
248
|
+
}
|
|
249
|
+
/** Get all MapLayerSources from the user's preferences, iTwin setting and iModel settings.
|
|
250
|
+
* @param projectId id of the project
|
|
251
|
+
* @param iModelId id of the iModel
|
|
252
|
+
* @throws if any of the calls to grab settings fail.
|
|
253
|
+
*/
|
|
254
|
+
static async getSources(projectId, iModelId) {
|
|
255
|
+
if (!MapLayersUI.iTwinConfig)
|
|
256
|
+
return [];
|
|
257
|
+
const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;
|
|
258
|
+
const mapLayerList = [];
|
|
259
|
+
try {
|
|
260
|
+
const userResultByProject = await MapLayersUI.iTwinConfig.get({
|
|
261
|
+
accessToken,
|
|
262
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
263
|
+
key: "",
|
|
264
|
+
iTwinId: projectId,
|
|
265
|
+
});
|
|
266
|
+
if (undefined !== userResultByProject)
|
|
267
|
+
mapLayerList.push(userResultByProject);
|
|
268
|
+
}
|
|
269
|
+
catch (err) {
|
|
270
|
+
throw new Error(IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.ErrorRetrieveUserProject", { errorMessage: err }));
|
|
271
|
+
}
|
|
272
|
+
try {
|
|
273
|
+
const userResultByIModel = await MapLayersUI.iTwinConfig.get({
|
|
274
|
+
accessToken,
|
|
275
|
+
namespace: MapLayerPreferences._preferenceNamespace,
|
|
276
|
+
key: "",
|
|
277
|
+
iTwinId: projectId,
|
|
278
|
+
iModelId,
|
|
279
|
+
});
|
|
280
|
+
if (undefined !== userResultByIModel)
|
|
281
|
+
mapLayerList.push(userResultByIModel);
|
|
282
|
+
}
|
|
283
|
+
catch (err) {
|
|
284
|
+
throw new Error(IModelApp.localization.getLocalizedString("mapLayers:CustomAttach.ErrorRetrieveUserProject", { errorMessage: err }));
|
|
285
|
+
}
|
|
286
|
+
const savedMapLayerSources = [];
|
|
287
|
+
for (const mapLayer of mapLayerList) {
|
|
288
|
+
mapLayer.forEach((savedLayer) => {
|
|
289
|
+
const mapLayerSource = MapLayerSource.fromJSON(savedLayer);
|
|
290
|
+
if (mapLayerSource)
|
|
291
|
+
savedMapLayerSources.push(mapLayerSource);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return savedMapLayerSources;
|
|
295
|
+
}
|
|
296
|
+
static get _preferenceNamespace() {
|
|
297
|
+
return "MapLayerSource-SettingsService";
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/** Event raised whenever a source is added, replaced or removed:
|
|
301
|
+
* changeType : Type of changed occurred.
|
|
302
|
+
* oldSource : Source that was removed or replaced.
|
|
303
|
+
* newSource : Source that was added or replacement of oldSource.
|
|
304
|
+
*
|
|
305
|
+
* @see [[MapLayerSourceChangeType]]
|
|
306
|
+
*/
|
|
307
|
+
MapLayerPreferences.onLayerSourceChanged = new BeEvent(); // Used to notify the frontend that it needs to update its list of available layers
|
|
308
|
+
//# sourceMappingURL=MapLayerPreferences.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapLayerPreferences.js","sourceRoot":"","sources":["../../src/MapLayerPreferences.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC9G,OAAO,EAAE,OAAO,EAAc,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAU1C,gBAAgB;AAChB,MAAM,CAAN,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,yEAAS,CAAA;IACT,6EAAW,CAAA;IACX,+EAAY,CAAA;AACd,CAAC,EAJW,wBAAwB,KAAxB,wBAAwB,QAInC;AASD;;;;;GAKG;AACH,MAAM,OAAO,mBAAmB;IAU9B;;;;;;OAMG;IACI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,MAAsB,EAAE,aAAsB,EAAE,OAAmB,EAAE,QAAoB;QACvH,IAAI,CAAC,WAAW,CAAC,WAAW;YAC1B,OAAO,KAAK,CAAC;QACf,MAAM,WAAW,GAAG,SAAS,KAAK,SAAS,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC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AAE,SAAS;gBAClB,QAAQ;aACT,CAAC,CAAC;YACH,IAAI,SAAS,KAAK,kBAAkB;gBAClC,YAAY,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;SACzC;QAAC,OAAO,GAAQ,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,YAAY,CAAC,kBAAkB,CAAC,iDAAiD,EAAE,EAAE,YAAY,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;SACtI;QAED,MAAM,oBAAoB,GAAqB,EAAE,CAAC;QAClD,KAAK,MAAM,QAAQ,IAAI,YAAY,EAAE;YACnC,QAAQ,CAAC,OAAO,CAAC,CAAC,UAAe,EAAE,EAAE;gBACnC,MAAM,cAAc,GAAG,cAAc,CAAC,QAAQ,CAAC,UAAwC,CAAC,CAAC;gBACzF,IAAI,cAAc;oBAChB,oBAAoB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,oBAAoB,CAAC;IAC9B,CAAC;IAEO,MAAM,KAAK,oBAAoB;QACrC,OAAO,gCAAgC,CAAC;IAC1C,CAAC;;AA/SD;;;;;;GAMG;AACoB,wCAAoB,GAAG,IAAI,OAAO,EAA0G,CAAC,CAAC,mFAAmF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { IModelApp, MapLayerSource, NotifyMessageDetails, OutputMessagePriority } from \"@itwin/core-frontend\";\r\nimport { BeEvent, GuidString } from \"@itwin/core-bentley\";\r\nimport { MapLayersUI } from \"./mapLayers\";\r\n\r\n/** @internal */\r\nexport interface MapLayerPreferencesContent {\r\n url: string;\r\n name: string;\r\n formatId: string;\r\n transparentBackground: boolean | undefined;\r\n}\r\n\r\n/** @internal */\r\nexport enum MapLayerSourceChangeType {\r\n Added = 0,\r\n Removed = 1,\r\n Replaced = 2,\r\n}\r\n\r\n/** @internal */\r\nexport interface MapLayerSourceArg {\r\n readonly source: MapLayerSource;\r\n readonly iTwinId: GuidString;\r\n readonly iModelId: GuidString;\r\n}\r\n\r\n/** A wrapper around user preferences to provide a way to store [[MapLayerSettings]].\r\n *\r\n * Note: This is currently internal only and used directly by the MapLayersExtension. It makes use of the IModelApp.authorizationClient if it exists.\r\n *\r\n * @internal\r\n */\r\nexport class MapLayerPreferences {\r\n /** Event raised whenever a source is added, replaced or removed:\r\n * changeType : Type of changed occurred.\r\n * oldSource : Source that was removed or replaced.\r\n * newSource : Source that was added or replacement of oldSource.\r\n *\r\n * @see [[MapLayerSourceChangeType]]\r\n */\r\n public static readonly onLayerSourceChanged = new BeEvent<(changeType: MapLayerSourceChangeType, oldSource?: MapLayerSource, newSource?: MapLayerSource) => void>(); // Used to notify the frontend that it needs to update its list of available layers\r\n\r\n /** Store the Map Layer source preference. If the same setting exists at a higher level, an error will be thrown and the setting will not be updated.\r\n *\r\n * Returns false if the settings object would override some other settings object in a larger scope i.e. storing settings on model when\r\n * a project setting exists with same name or map layer url.\r\n * @param source source to be stored on the setting service\r\n * @param storeOnIModel if true store the settings object on the model, if false store it on the project\r\n */\r\n public static async storeSource(source: MapLayerSource, storeOnIModel: boolean, iTwinId: GuidString, iModelId: GuidString): Promise<boolean> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return false;\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n const sourceJSON = source.toJSON();\r\n const mapLayerSetting: MapLayerPreferencesContent = {\r\n url: sourceJSON.url,\r\n name: sourceJSON.name,\r\n formatId: sourceJSON.formatId,\r\n transparentBackground: sourceJSON.transparentBackground,\r\n };\r\n\r\n const result: boolean = await MapLayerPreferences.delete(sourceJSON.url, sourceJSON.name, iTwinId, iModelId, storeOnIModel);\r\n if (result) {\r\n await MapLayersUI.iTwinConfig.save({\r\n accessToken,\r\n content: mapLayerSetting,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: sourceJSON.name,\r\n iTwinId,\r\n iModelId: storeOnIModel ? iModelId : undefined,\r\n });\r\n MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Added, undefined, MapLayerSource.fromJSON(mapLayerSetting));\r\n return true;\r\n } else {\r\n return false;\r\n }\r\n }\r\n\r\n /** Replace the old map layer source with a new map layer source.\r\n *\r\n * The source is replaced at the same level that the original source is defined. (i.e. if the old source is defined at a project level, the new source will also be defined there.)\r\n *\r\n * @param oldSource\r\n * @param newSource\r\n * @param projectId\r\n * @param iModelId\r\n */\r\n public static async replaceSource(oldSource: MapLayerSource, newSource: MapLayerSource, projectId: GuidString, iModelId: GuidString): Promise<void> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return;\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n let storeOnIModel = false;\r\n try {\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: oldSource.name,\r\n iTwinId: projectId,\r\n iModelId,\r\n });\r\n } catch (_err) {\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: oldSource.name,\r\n iTwinId: projectId,\r\n });\r\n storeOnIModel = true;\r\n }\r\n\r\n const mapLayerSetting: MapLayerPreferencesContent = {\r\n url: newSource.url,\r\n name: newSource.name,\r\n formatId: newSource.formatId,\r\n transparentBackground: newSource.transparentBackground,\r\n };\r\n\r\n await MapLayersUI.iTwinConfig.save({\r\n accessToken,\r\n key: `${MapLayerPreferences._preferenceNamespace}.${newSource.name}`,\r\n iTwinId: projectId,\r\n iModelId: storeOnIModel ? iModelId : undefined,\r\n content: mapLayerSetting,\r\n });\r\n\r\n MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Replaced, oldSource, newSource);\r\n }\r\n\r\n /** Deletes the provided MapLayerSource by name from both the iTwin or iModel level.\r\n *\r\n * @param source The source to delete. The name is used to identify the source.\r\n * @param iTwinId\r\n * @param iModelId\r\n */\r\n public static async deleteByName(source: MapLayerSource, iTwinId: GuidString, iModelId: GuidString): Promise<void> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return;\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n try {\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: source.name,\r\n iTwinId,\r\n iModelId,\r\n });\r\n } catch (_err) {\r\n // failed to store based on iModelId, attempt using iTwinId\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: source.name,\r\n iTwinId,\r\n });\r\n }\r\n\r\n MapLayerPreferences.onLayerSourceChanged.raiseEvent(MapLayerSourceChangeType.Removed, source, undefined);\r\n }\r\n\r\n /** Deletes the current setting with the provided key if it is defined at the same preference level.\r\n *\r\n * If the preference is defined within a different level, false will be returned indicating the setting should not be overriden.\r\n *\r\n * The two potential preference levels are iTwin and iModel.\r\n *\r\n * @param url\r\n * @param name\r\n * @param iTwinId\r\n * @param iModelId\r\n * @param storeOnIModel\r\n */\r\n private static async delete(url: string, name: string, iTwinId: GuidString, iModelId: GuidString, storeOnIModel: boolean): Promise<boolean> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return true;\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n const iTwinPreferenceByName = await MapLayersUI.iTwinConfig.get({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: name,\r\n iTwinId,\r\n });\r\n\r\n if (undefined !== iTwinPreferenceByName && storeOnIModel) {\r\n const errorMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerExistsAsProjectSetting\", { layer: iTwinPreferenceByName.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));\r\n return false;\r\n } else if (iTwinPreferenceByName) {\r\n const infoMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerExistsOverwriting\", { layer: iTwinPreferenceByName.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: iTwinPreferenceByName.name,\r\n iTwinId,\r\n });\r\n }\r\n\r\n // check if setting with url already exists, if it does, delete it\r\n const settingFromUrl = await MapLayerPreferences.getByUrl(url, iTwinId, undefined);\r\n if (settingFromUrl && storeOnIModel) {\r\n const errorMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerWithUrlExistsAsProjectSetting\", { url: settingFromUrl.url, name: settingFromUrl.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));\r\n return false;\r\n } else if (settingFromUrl) {\r\n const infoMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerWithUrlExistsOverwriting\", { url: settingFromUrl.url, oldName: settingFromUrl.name, newName: name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: settingFromUrl.name,\r\n iTwinId,\r\n });\r\n }\r\n\r\n if (iModelId) { // delete any settings on model so user can update them if theres collisions\r\n const settingOnIModelFromName = await MapLayersUI.iTwinConfig.get({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: name,\r\n iTwinId,\r\n iModelId,\r\n });\r\n const settingFromUrlOnIModel = await MapLayerPreferences.getByUrl(url, iTwinId, iModelId);\r\n if (settingOnIModelFromName) {\r\n const infoMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerExistsOverwriting\", { layer: settingOnIModelFromName.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: settingOnIModelFromName.name,\r\n iTwinId,\r\n iModelId,\r\n });\r\n }\r\n if (settingFromUrlOnIModel) {\r\n const infoMessage = IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.LayerWithUrlExistsOverwriting\", { url: settingFromUrlOnIModel.url, oldName: settingFromUrlOnIModel.name, newName: name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, infoMessage));\r\n await MapLayersUI.iTwinConfig.delete({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: settingFromUrlOnIModel.name,\r\n iTwinId,\r\n iModelId,\r\n });\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /** Attempts to get a map layer based off a specific url.\r\n * @param url\r\n * @param projectId\r\n * @param iModelId\r\n */\r\n public static async getByUrl(url: string, projectId: string, iModelId?: string): Promise<MapLayerPreferencesContent | undefined> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return undefined;\r\n\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n const settingResponse = await MapLayersUI.iTwinConfig.get({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: \"\",\r\n iTwinId: projectId,\r\n iModelId,\r\n });\r\n\r\n if (undefined === settingResponse || 0 === settingResponse.length)\r\n return undefined;\r\n\r\n let savedMapLayer;\r\n settingResponse.settingsMap?.forEach((savedLayer: any) => {\r\n if (savedLayer.url === url) {\r\n savedMapLayer = savedLayer;\r\n }\r\n });\r\n return savedMapLayer;\r\n }\r\n\r\n /** Get all MapLayerSources from the user's preferences, iTwin setting and iModel settings.\r\n * @param projectId id of the project\r\n * @param iModelId id of the iModel\r\n * @throws if any of the calls to grab settings fail.\r\n */\r\n public static async getSources(projectId: GuidString, iModelId: GuidString): Promise<MapLayerSource[]> {\r\n if (!MapLayersUI.iTwinConfig)\r\n return [];\r\n const accessToken = undefined !== IModelApp.authorizationClient ? (await IModelApp.authorizationClient.getAccessToken()) : undefined;\r\n\r\n const mapLayerList = [];\r\n\r\n try {\r\n const userResultByProject = await MapLayersUI.iTwinConfig.get({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: \"\",\r\n iTwinId: projectId,\r\n });\r\n if (undefined !== userResultByProject)\r\n mapLayerList.push(userResultByProject);\r\n } catch (err: any) {\r\n throw new Error(IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.ErrorRetrieveUserProject\", { errorMessage: err }));\r\n }\r\n\r\n try {\r\n const userResultByIModel = await MapLayersUI.iTwinConfig.get({\r\n accessToken,\r\n namespace: MapLayerPreferences._preferenceNamespace,\r\n key: \"\",\r\n iTwinId: projectId,\r\n iModelId,\r\n });\r\n if (undefined !== userResultByIModel)\r\n mapLayerList.push(userResultByIModel);\r\n } catch (err: any) {\r\n throw new Error(IModelApp.localization.getLocalizedString(\"mapLayers:CustomAttach.ErrorRetrieveUserProject\", { errorMessage: err }));\r\n }\r\n\r\n const savedMapLayerSources: MapLayerSource[] = [];\r\n for (const mapLayer of mapLayerList) {\r\n mapLayer.forEach((savedLayer: any) => {\r\n const mapLayerSource = MapLayerSource.fromJSON(savedLayer as MapLayerPreferencesContent);\r\n if (mapLayerSource)\r\n savedMapLayerSources.push(mapLayerSource);\r\n });\r\n }\r\n return savedMapLayerSources;\r\n }\r\n\r\n private static get _preferenceNamespace() {\r\n return \"MapLayerSource-SettingsService\";\r\n }\r\n}\r\n"]}
|
package/lib/esm/mapLayers.d.ts
CHANGED
|
@@ -1,25 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { UserPreferencesAccess } from "@itwin/core-frontend";
|
|
2
|
+
/** MapLayersUI is use when the package is used as a dependency to another app.
|
|
3
3
|
* '''ts
|
|
4
|
-
*
|
|
5
|
-
* // so it can be explicitly added to a stage via a FrontstageDef.
|
|
6
|
-
* await MapLayersUI.initialize (registerItemsProvider);
|
|
4
|
+
* await MapLayersUI.initialize(registerItemsProvider);
|
|
7
5
|
* '''
|
|
8
6
|
* @beta
|
|
9
7
|
*/
|
|
10
8
|
export declare class MapLayersUI {
|
|
11
9
|
private static _defaultNs;
|
|
12
10
|
private static _uiItemsProvider;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*
|
|
11
|
+
private static _itemsProviderRegistered?;
|
|
12
|
+
private static _iTwinConfig?;
|
|
13
|
+
static get iTwinConfig(): UserPreferencesAccess | undefined;
|
|
14
|
+
/** Used to initialize the Map Layers.
|
|
15
|
+
*
|
|
16
|
+
* If `registerItemsProvider` is true, the UiItemsProvider will automatically insert the UI items into the host applications UI.
|
|
17
|
+
* If it is false, explicitly add widget definition to a specific FrontStage definition using the following syntax.
|
|
18
|
+
*
|
|
19
|
+
* ```tsx
|
|
20
|
+
* <Widget id={MapLayersWidgetControl.id} label={MapLayersWidgetControl.label} control={MapLayersWidgetControl}
|
|
18
21
|
* iconSpec={MapLayersWidgetControl.iconSpec} />,
|
|
19
|
-
*
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* If an iTwinConfig is provided, it will be used to load the MapLayerSources that are stored.
|
|
20
25
|
*/
|
|
21
|
-
static initialize(registerItemsProvider?: boolean): Promise<void>;
|
|
22
|
-
/** Unregisters
|
|
26
|
+
static initialize(registerItemsProvider?: boolean, iTwinConfig?: UserPreferencesAccess): Promise<void>;
|
|
27
|
+
/** Unregisters internationalization service namespace and UiItemManager / control */
|
|
23
28
|
static terminate(): void;
|
|
24
29
|
/** The internationalization service namespace. */
|
|
25
30
|
static get localizationNamespace(): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapLayers.d.ts","sourceRoot":"","sources":["../../src/mapLayers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapLayers.d.ts","sourceRoot":"","sources":["../../src/mapLayers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAa,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAIxE;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAe;IACxC,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAA2B;IAC1D,OAAO,CAAC,MAAM,CAAC,wBAAwB,CAAC,CAAU;IAElD,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAwB;IACpD,WAAkB,WAAW,IAAI,qBAAqB,GAAG,SAAS,CAA8B;IAEhG;;;;;;;;;;;OAWG;WACiB,UAAU,CAAC,qBAAqB,UAAO,EAAE,WAAW,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;IAchH,qFAAqF;WACvE,SAAS;IAWvB,kDAAkD;IAClD,WAAkB,qBAAqB,IAAI,MAAM,CAEhD;CACF"}
|
package/lib/esm/mapLayers.js
CHANGED
|
@@ -3,40 +3,48 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import { IModelApp } from "@itwin/core-frontend";
|
|
6
|
-
import { MapLayersUiItemsProvider
|
|
6
|
+
import { MapLayersUiItemsProvider } from "./ui/MapLayersUiItemsProvider";
|
|
7
7
|
import { UiItemsManager } from "@itwin/appui-abstract";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* MapLayersApi is use when the package is used as a dependency to another app and not used as an extension.
|
|
8
|
+
/** MapLayersUI is use when the package is used as a dependency to another app.
|
|
11
9
|
* '''ts
|
|
12
|
-
*
|
|
13
|
-
* // so it can be explicitly added to a stage via a FrontstageDef.
|
|
14
|
-
* await MapLayersUI.initialize (registerItemsProvider);
|
|
10
|
+
* await MapLayersUI.initialize(registerItemsProvider);
|
|
15
11
|
* '''
|
|
16
12
|
* @beta
|
|
17
13
|
*/
|
|
18
14
|
export class MapLayersUI {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
15
|
+
static get iTwinConfig() { return this._iTwinConfig; }
|
|
16
|
+
/** Used to initialize the Map Layers.
|
|
17
|
+
*
|
|
18
|
+
* If `registerItemsProvider` is true, the UiItemsProvider will automatically insert the UI items into the host applications UI.
|
|
19
|
+
* If it is false, explicitly add widget definition to a specific FrontStage definition using the following syntax.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <Widget id={MapLayersWidgetControl.id} label={MapLayersWidgetControl.label} control={MapLayersWidgetControl}
|
|
24
23
|
* iconSpec={MapLayersWidgetControl.iconSpec} />,
|
|
25
|
-
*
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* If an iTwinConfig is provided, it will be used to load the MapLayerSources that are stored.
|
|
26
27
|
*/
|
|
27
|
-
static async initialize(registerItemsProvider = true) {
|
|
28
|
+
static async initialize(registerItemsProvider = true, iTwinConfig) {
|
|
29
|
+
MapLayersUI._iTwinConfig = iTwinConfig;
|
|
28
30
|
// register namespace containing localized strings for this package
|
|
29
31
|
await IModelApp.localization.registerNamespace(this.localizationNamespace);
|
|
30
32
|
// _uiItemsProvider always created to provide access to localization.
|
|
31
33
|
MapLayersUI._uiItemsProvider = new MapLayersUiItemsProvider(IModelApp.localization);
|
|
32
|
-
if (registerItemsProvider)
|
|
34
|
+
if (registerItemsProvider) {
|
|
33
35
|
UiItemsManager.register(MapLayersUI._uiItemsProvider);
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
}
|
|
37
|
+
MapLayersUI._itemsProviderRegistered = registerItemsProvider;
|
|
36
38
|
}
|
|
37
|
-
/** Unregisters
|
|
39
|
+
/** Unregisters internationalization service namespace and UiItemManager / control */
|
|
38
40
|
static terminate() {
|
|
39
41
|
IModelApp.localization.unregisterNamespace(this.localizationNamespace);
|
|
42
|
+
if (MapLayersUI._itemsProviderRegistered !== undefined) {
|
|
43
|
+
if (MapLayersUI._itemsProviderRegistered) {
|
|
44
|
+
UiItemsManager.unregister(MapLayersUI._uiItemsProvider.id);
|
|
45
|
+
}
|
|
46
|
+
MapLayersUI._itemsProviderRegistered = undefined;
|
|
47
|
+
}
|
|
40
48
|
}
|
|
41
49
|
/** The internationalization service namespace. */
|
|
42
50
|
static get localizationNamespace() {
|
package/lib/esm/mapLayers.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapLayers.js","sourceRoot":"","sources":["../../src/mapLayers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"mapLayers.js","sourceRoot":"","sources":["../../src/mapLayers.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IAMf,MAAM,KAAK,WAAW,KAAwC,OAAO,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;IAEhG;;;;;;;;;;;OAWG;IACI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,qBAAqB,GAAG,IAAI,EAAE,WAAmC;QAC9F,WAAW,CAAC,YAAY,GAAG,WAAW,CAAC;QAEvC,mEAAmE;QACnE,MAAM,SAAS,CAAC,YAAY,CAAC,iBAAiB,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAE3E,qEAAqE;QACrE,WAAW,CAAC,gBAAgB,GAAG,IAAI,wBAAwB,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACpF,IAAI,qBAAqB,EAAE;YACzB,cAAc,CAAC,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;SACvD;QACD,WAAW,CAAC,wBAAwB,GAAG,qBAAqB,CAAC;IAC/D,CAAC;IAED,qFAAqF;IAC9E,MAAM,CAAC,SAAS;QACrB,SAAS,CAAC,YAAY,CAAC,mBAAmB,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAEvE,IAAI,WAAW,CAAC,wBAAwB,KAAK,SAAS,EAAE;YACtD,IAAI,WAAW,CAAC,wBAAwB,EAAE;gBACxC,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;aAC5D;YACD,WAAW,CAAC,wBAAwB,GAAG,SAAS,CAAC;SAClD;IACH,CAAC;IAED,kDAAkD;IAC3C,MAAM,KAAK,qBAAqB;QACrC,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;;AAhDc,sBAAU,GAAG,WAAW,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { IModelApp, UserPreferencesAccess } from \"@itwin/core-frontend\";\r\nimport { MapLayersUiItemsProvider } from \"./ui/MapLayersUiItemsProvider\";\r\nimport { UiItemsManager } from \"@itwin/appui-abstract\";\r\n\r\n/** MapLayersUI is use when the package is used as a dependency to another app.\r\n * '''ts\r\n * await MapLayersUI.initialize(registerItemsProvider);\r\n * '''\r\n * @beta\r\n */\r\nexport class MapLayersUI {\r\n private static _defaultNs = \"mapLayers\";\r\n private static _uiItemsProvider: MapLayersUiItemsProvider;\r\n private static _itemsProviderRegistered?: boolean;\r\n\r\n private static _iTwinConfig?: UserPreferencesAccess;\r\n public static get iTwinConfig(): UserPreferencesAccess | undefined { return this._iTwinConfig; }\r\n\r\n /** Used to initialize the Map Layers.\r\n *\r\n * If `registerItemsProvider` is true, the UiItemsProvider will automatically insert the UI items into the host applications UI.\r\n * If it is false, explicitly add widget definition to a specific FrontStage definition using the following syntax.\r\n *\r\n * ```tsx\r\n * <Widget id={MapLayersWidgetControl.id} label={MapLayersWidgetControl.label} control={MapLayersWidgetControl}\r\n * iconSpec={MapLayersWidgetControl.iconSpec} />,\r\n * ```\r\n *\r\n * If an iTwinConfig is provided, it will be used to load the MapLayerSources that are stored.\r\n */\r\n public static async initialize(registerItemsProvider = true, iTwinConfig?: UserPreferencesAccess): Promise<void> {\r\n MapLayersUI._iTwinConfig = iTwinConfig;\r\n\r\n // register namespace containing localized strings for this package\r\n await IModelApp.localization.registerNamespace(this.localizationNamespace);\r\n\r\n // _uiItemsProvider always created to provide access to localization.\r\n MapLayersUI._uiItemsProvider = new MapLayersUiItemsProvider(IModelApp.localization);\r\n if (registerItemsProvider) {\r\n UiItemsManager.register(MapLayersUI._uiItemsProvider);\r\n }\r\n MapLayersUI._itemsProviderRegistered = registerItemsProvider;\r\n }\r\n\r\n /** Unregisters internationalization service namespace and UiItemManager / control */\r\n public static terminate() {\r\n IModelApp.localization.unregisterNamespace(this.localizationNamespace);\r\n\r\n if (MapLayersUI._itemsProviderRegistered !== undefined) {\r\n if (MapLayersUI._itemsProviderRegistered) {\r\n UiItemsManager.unregister(MapLayersUI._uiItemsProvider.id);\r\n }\r\n MapLayersUI._itemsProviderRegistered = undefined;\r\n }\r\n }\r\n\r\n /** The internationalization service namespace. */\r\n public static get localizationNamespace(): string {\r\n return this._defaultNs;\r\n }\r\n}\r\n"]}
|
|
@@ -63,6 +63,7 @@
|
|
|
63
63
|
"MapLayerEditError": "Failed to edit '{{layerName}}'",
|
|
64
64
|
"MapLayerLayerSettingsConversionError": "Conversion to layer settings failed",
|
|
65
65
|
"MapLayerLayerSourceCreationFailed": "Map Layer Source creation failed",
|
|
66
|
+
"MapLayerPreferencesStoreFailed": "Failed to save map layer definition in preferences",
|
|
66
67
|
"MapLayerValidationFailed": "Map layer validation failed for URL: {{sourceUrl}}"
|
|
67
68
|
},
|
|
68
69
|
"Widget": {
|
|
@@ -81,7 +82,7 @@
|
|
|
81
82
|
"ZoomToLayer": "Zoom to layer"
|
|
82
83
|
},
|
|
83
84
|
"Settings": {
|
|
84
|
-
"ElevationOffset": "Elevation Offset
|
|
85
|
+
"ElevationOffset": "Elevation Offset",
|
|
85
86
|
"ElevationTypeGeodetic": "None",
|
|
86
87
|
"ElevationTypeGeoid": "Geoid Separation",
|
|
87
88
|
"ElevationTypeGround": "Terrain Elevation",
|
|
@@ -91,7 +92,9 @@
|
|
|
91
92
|
"InvalidElevationError": "Invalid Elevation",
|
|
92
93
|
"InvalidElevationDetails": "Please enter a valid number for elevation.",
|
|
93
94
|
"Mask": "Mask by Models",
|
|
94
|
-
"
|
|
95
|
+
"MaskTransparency": "Mask Transparency",
|
|
96
|
+
"ModelHeight": "Model Height",
|
|
97
|
+
"OverrideMaskTransparency": "Override Mask Transparency",
|
|
95
98
|
"Settings": "Settings",
|
|
96
99
|
"ShowMapLayers": "Show Map Layers",
|
|
97
100
|
"Terrain": "Terrain",
|
|
@@ -22,7 +22,7 @@ export class MapLayersUiItemsProvider {
|
|
|
22
22
|
if (stageUsage === StageUsage.General && location === StagePanelLocation.Right && section === StagePanelSection.Start) {
|
|
23
23
|
widgets.push({
|
|
24
24
|
id: "map-layers:mapLayersWidget",
|
|
25
|
-
label:
|
|
25
|
+
label: IModelApp.localization.getLocalizedString("mapLayers:Widget.Label"),
|
|
26
26
|
icon: "icon-map",
|
|
27
27
|
getWidgetContent: () => React.createElement(MapLayersWidget, { mapLayerOptions: mapLayerOptions }), // eslint-disable-line react/display-name
|
|
28
28
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapLayersUiItemsProvider.js","sourceRoot":"","sources":["../../../src/ui/MapLayersUiItemsProvider.tsx"],"names":[],"mappings":"AAAA;;;+FAG+F;AA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AC,CAAC;IAC7E,CAAC;;AALa,yBAAE,GAAG,iBAAiB,CAAC;AACvB,+BAAQ,GAAG,UAAU,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport * as React from \"react\";\r\nimport { AbstractWidgetProps, StagePanelLocation, StagePanelSection, StageUsage, UiItemsProvider } from \"@itwin/appui-abstract\";\r\nimport { Localization } from \"@itwin/core-common\";\r\nimport { MapLayersWidget } from \"./widget/MapLayersWidget\";\r\nimport { ConfigurableCreateInfo, WidgetControl } from \"@itwin/appui-react\";\r\nimport { IModelApp } from \"@itwin/core-frontend\";\r\nimport { MapLayerOptions } from \"./Interfaces\";\r\n\r\nexport class MapLayersUiItemsProvider implements UiItemsProvider {\r\n public readonly id = \"MapLayersUiItemsProvider\";\r\n public static localization: Localization;\r\n\r\n public constructor(localization: Localization) {\r\n MapLayersUiItemsProvider.localization = localization;\r\n }\r\n\r\n public provideWidgets(_stageId: string, stageUsage: string, location: StagePanelLocation, section: StagePanelSection | undefined): ReadonlyArray<AbstractWidgetProps> {\r\n const widgets: AbstractWidgetProps[] = [];\r\n const mapLayerOptions: MapLayerOptions = {\r\n hideExternalMapLayers: false,\r\n mapTypeOptions: { supportTileUrl: false, supportWmsAuthentication: true },\r\n fetchPublicMapLayerSources: false,\r\n };\r\n\r\n if (stageUsage === StageUsage.General && location === StagePanelLocation.Right && section === StagePanelSection.Start) {\r\n widgets.push({\r\n id: \"map-layers:mapLayersWidget\",\r\n label: IModelApp.localization.getLocalizedString(\"mapLayers:Widget.Label\"),\r\n icon: \"icon-map\",\r\n getWidgetContent: () => <MapLayersWidget mapLayerOptions={mapLayerOptions} />, // eslint-disable-line react/display-name\r\n });\r\n }\r\n\r\n return widgets;\r\n }\r\n}\r\n\r\n/** MapLayersWidgetControl provides a widget to attach and remove maps layers from the active view's display style.\r\n * ``` tsx\r\n * <Widget id={MapLayersWidgetControl.id} label={MapLayersWidgetControl.label} control={MapLayersWidgetControl}\r\n * iconSpec={MapLayersWidgetControl.iconSpec} />,\r\n * ```\r\n */\r\nexport class MapLayersWidgetControl extends WidgetControl {\r\n public static id = \"MapLayersWidget\";\r\n public static iconSpec = \"icon-map\";\r\n\r\n public static get label(): string {\r\n return IModelApp.localization.getLocalizedString(\"mapLayers:Widget.Label\");\r\n }\r\n\r\n constructor(info: ConfigurableCreateInfo, mapLayerOptions: MapLayerOptions | undefined) {\r\n super(info, mapLayerOptions);\r\n\r\n this.reactNode = <MapLayersWidget mapLayerOptions={mapLayerOptions} />;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AttachLayerPopupButton.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/AttachLayerPopupButton.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"AttachLayerPopupButton.d.ts","sourceRoot":"","sources":["../../../../src/ui/widget/AttachLayerPopupButton.tsx"],"names":[],"mappings":";AA0TA,gBAAgB;AAChB,oBAAY,qBAAqB;IAC/B,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,IAAI,IAAA;CACL;AACD,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,qBAAqB,CAAC;CACpC;AAED,gBAAgB;AAEhB,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,eAqHxE"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
4
|
*--------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as React from "react";
|
|
6
|
-
import { IModelApp,
|
|
6
|
+
import { IModelApp, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority } from "@itwin/core-frontend";
|
|
7
7
|
import { RelativePosition } from "@itwin/appui-abstract";
|
|
8
8
|
import * as UiCore from "@itwin/core-react";
|
|
9
9
|
import { ModalDialogManager } from "@itwin/appui-react";
|
|
@@ -12,6 +12,7 @@ import { MapUrlDialog } from "./MapUrlDialog";
|
|
|
12
12
|
import { MapLayersUiItemsProvider } from "../MapLayersUiItemsProvider";
|
|
13
13
|
import { ConfirmMessageDialog } from "./ConfirmMessageDialog";
|
|
14
14
|
import { Button, Input } from "@itwin/itwinui-react";
|
|
15
|
+
import { MapLayerPreferences } from "../../MapLayerPreferences";
|
|
15
16
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
16
17
|
function AttachLayerPanel({ isOverlay, onLayerAttached }) {
|
|
17
18
|
var _a, _b;
|
|
@@ -160,11 +161,12 @@ function AttachLayerPanel({ isOverlay, onLayerAttached }) {
|
|
|
160
161
|
const handleYesConfirmation = React.useCallback(async (source) => {
|
|
161
162
|
const layerName = source.name;
|
|
162
163
|
if (!!iTwinId && !!iModelId) {
|
|
163
|
-
|
|
164
|
+
try {
|
|
165
|
+
await MapLayerPreferences.deleteByName(source, iTwinId, iModelId);
|
|
164
166
|
const msg = MapLayersUiItemsProvider.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefSuccess", { layerName });
|
|
165
167
|
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
|
|
166
168
|
}
|
|
167
|
-
|
|
169
|
+
catch (err) {
|
|
168
170
|
const msg = MapLayersUiItemsProvider.localization.getLocalizedString("mapLayers:CustomAttach.RemoveLayerDefError", { layerName });
|
|
169
171
|
IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
|
|
170
172
|
}
|
|
@@ -197,7 +199,7 @@ function AttachLayerPanel({ isOverlay, onLayerAttached }) {
|
|
|
197
199
|
return (React.createElement("div", { className: "map-manager-header" },
|
|
198
200
|
(loading || loadingSources) && React.createElement(UiCore.LoadingSpinner, { message: loadingMapSources }),
|
|
199
201
|
React.createElement("div", { className: "map-manager-source-listbox-header" },
|
|
200
|
-
React.createElement(Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged }),
|
|
202
|
+
React.createElement(Input, { type: "text", className: "map-manager-source-list-filter", placeholder: placeholderLabel, value: sourceFilterString, onChange: handleFilterTextChanged, size: "small" }),
|
|
201
203
|
React.createElement(Button, { className: "map-manager-add-source-button", title: addCustomLayerToolTip, onClick: handleAddNewMapSource }, addCustomLayerLabel)),
|
|
202
204
|
React.createElement("div", { className: "map-manager-sources" },
|
|
203
205
|
React.createElement(UiCore.Listbox, { id: "map-sources", selectedValue: layerNameToAdd, className: "map-manager-source-list", onKeyPress: handleKeypressOnSourceList, onListboxValueChange: onListboxValueChange }, filteredOptions === null || filteredOptions === void 0 ? void 0 : filteredOptions.map((source) => React.createElement(UiCore.ListboxItem, { key: source.name, className: "map-source-list-entry", value: source.name, onMouseEnter: () => setLayerNameUnderCursor(source.name), onMouseLeave: () => setLayerNameUnderCursor(undefined) },
|