@itwin/map-layers 4.0.0-dev.28 → 4.0.0-dev.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/lib/cjs/MapLayerPreferences.d.ts +88 -88
  2. package/lib/cjs/MapLayerPreferences.js +311 -311
  3. package/lib/cjs/MapLayerPreferences.js.map +1 -1
  4. package/lib/cjs/map-layers.d.ts +6 -6
  5. package/lib/cjs/map-layers.js +22 -22
  6. package/lib/cjs/mapLayers.d.ts +44 -44
  7. package/lib/cjs/mapLayers.js +61 -61
  8. package/lib/cjs/mapLayers.js.map +1 -1
  9. package/lib/cjs/ui/FeatureInfoUiItemsProvider.d.ts +11 -11
  10. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js +51 -51
  11. package/lib/cjs/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  12. package/lib/cjs/ui/Interfaces.d.ts +50 -50
  13. package/lib/cjs/ui/Interfaces.js +2 -2
  14. package/lib/cjs/ui/Interfaces.js.map +1 -1
  15. package/lib/cjs/ui/MapFeatureInfoTool.d.ts +13 -13
  16. package/lib/cjs/ui/MapFeatureInfoTool.js +50 -50
  17. package/lib/cjs/ui/MapFeatureInfoTool.js.map +1 -1
  18. package/lib/cjs/ui/MapLayersUiItemsProvider.d.ts +8 -8
  19. package/lib/cjs/ui/MapLayersUiItemsProvider.js +38 -38
  20. package/lib/cjs/ui/MapLayersUiItemsProvider.js.map +1 -1
  21. package/lib/cjs/ui/widget/AttachLayerPopupButton.d.ts +14 -14
  22. package/lib/cjs/ui/widget/AttachLayerPopupButton.js +335 -335
  23. package/lib/cjs/ui/widget/BasemapPanel.d.ts +8 -8
  24. package/lib/cjs/ui/widget/BasemapPanel.js +156 -156
  25. package/lib/cjs/ui/widget/BasemapPanel.js.map +1 -1
  26. package/lib/cjs/ui/widget/BasemapPanel.scss +87 -87
  27. package/lib/cjs/ui/widget/ConfirmMessageDialog.d.ts +21 -21
  28. package/lib/cjs/ui/widget/ConfirmMessageDialog.js +22 -22
  29. package/lib/cjs/ui/widget/ConfirmMessageDialog.js.map +1 -1
  30. package/lib/cjs/ui/widget/FeatureInfoDataProvider.d.ts +40 -40
  31. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js +138 -138
  32. package/lib/cjs/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  33. package/lib/cjs/ui/widget/FeatureInfoWidget.d.ts +7 -7
  34. package/lib/cjs/ui/widget/FeatureInfoWidget.js +65 -65
  35. package/lib/cjs/ui/widget/FeatureInfoWidget.js.map +1 -1
  36. package/lib/cjs/ui/widget/MapLayerDroppable.d.ts +19 -19
  37. package/lib/cjs/ui/widget/MapLayerDroppable.js +85 -85
  38. package/lib/cjs/ui/widget/MapLayerDroppable.js.map +1 -1
  39. package/lib/cjs/ui/widget/MapLayerManager.d.ts +26 -26
  40. package/lib/cjs/ui/widget/MapLayerManager.js +401 -401
  41. package/lib/cjs/ui/widget/MapLayerManager.js.map +1 -1
  42. package/lib/cjs/ui/widget/MapLayerManager.scss +409 -409
  43. package/lib/cjs/ui/widget/MapLayerSettingsMenu.d.ts +12 -12
  44. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js +82 -82
  45. package/lib/cjs/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  46. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.d.ts +7 -7
  47. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js +65 -65
  48. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  49. package/lib/cjs/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  50. package/lib/cjs/ui/widget/MapLayersWidget.d.ts +11 -11
  51. package/lib/cjs/ui/widget/MapLayersWidget.js +31 -31
  52. package/lib/cjs/ui/widget/MapLayersWidget.js.map +1 -1
  53. package/lib/cjs/ui/widget/MapManagerSettings.d.ts +3 -3
  54. package/lib/cjs/ui/widget/MapManagerSettings.js +200 -200
  55. package/lib/cjs/ui/widget/MapManagerSettings.js.map +1 -1
  56. package/lib/cjs/ui/widget/MapManagerSettings.scss +29 -29
  57. package/lib/cjs/ui/widget/MapUrlDialog.d.ts +23 -23
  58. package/lib/cjs/ui/widget/MapUrlDialog.d.ts.map +1 -1
  59. package/lib/cjs/ui/widget/MapUrlDialog.js +530 -524
  60. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  61. package/lib/cjs/ui/widget/MapUrlDialog.scss +100 -100
  62. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +18 -18
  63. package/lib/cjs/ui/widget/SelectMapFormat.js +54 -54
  64. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  65. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +20 -20
  66. package/lib/cjs/ui/widget/SubLayersDataProvider.js +75 -75
  67. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  68. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +10 -10
  69. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  70. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  71. package/lib/cjs/ui/widget/SubLayersTree.d.ts +15 -15
  72. package/lib/cjs/ui/widget/SubLayersTree.js +413 -413
  73. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  74. package/lib/cjs/ui/widget/SubLayersTree.scss +69 -69
  75. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +14 -14
  76. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  77. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  78. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +36 -36
  79. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  80. package/lib/esm/MapLayerPreferences.js +307 -307
  81. package/lib/esm/MapLayerPreferences.js.map +1 -1
  82. package/lib/esm/map-layers.d.ts +6 -6
  83. package/lib/esm/map-layers.js +10 -10
  84. package/lib/esm/mapLayers.d.ts +44 -44
  85. package/lib/esm/mapLayers.js +57 -57
  86. package/lib/esm/mapLayers.js.map +1 -1
  87. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +11 -11
  88. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +47 -47
  89. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  90. package/lib/esm/ui/Interfaces.d.ts +50 -50
  91. package/lib/esm/ui/Interfaces.js +1 -1
  92. package/lib/esm/ui/Interfaces.js.map +1 -1
  93. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  94. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  95. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  96. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  97. package/lib/esm/ui/MapLayersUiItemsProvider.js +34 -34
  98. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  99. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +14 -14
  100. package/lib/esm/ui/widget/AttachLayerPopupButton.js +331 -331
  101. package/lib/esm/ui/widget/BasemapPanel.d.ts +8 -8
  102. package/lib/esm/ui/widget/BasemapPanel.js +152 -152
  103. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  104. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  105. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +21 -21
  106. package/lib/esm/ui/widget/ConfirmMessageDialog.js +18 -18
  107. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  108. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +40 -40
  109. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +134 -134
  110. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  111. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +7 -7
  112. package/lib/esm/ui/widget/FeatureInfoWidget.js +61 -61
  113. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  114. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +19 -19
  115. package/lib/esm/ui/widget/MapLayerDroppable.js +81 -81
  116. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  117. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  118. package/lib/esm/ui/widget/MapLayerManager.js +396 -396
  119. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  120. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  121. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +12 -12
  122. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +78 -78
  123. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  124. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +7 -7
  125. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  126. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  127. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  128. package/lib/esm/ui/widget/MapLayersWidget.d.ts +11 -11
  129. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  130. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  131. package/lib/esm/ui/widget/MapManagerSettings.d.ts +3 -3
  132. package/lib/esm/ui/widget/MapManagerSettings.js +196 -196
  133. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  134. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  135. package/lib/esm/ui/widget/MapUrlDialog.d.ts +23 -23
  136. package/lib/esm/ui/widget/MapUrlDialog.d.ts.map +1 -1
  137. package/lib/esm/ui/widget/MapUrlDialog.js +526 -520
  138. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  139. package/lib/esm/ui/widget/MapUrlDialog.scss +100 -100
  140. package/lib/esm/ui/widget/SelectMapFormat.d.ts +18 -18
  141. package/lib/esm/ui/widget/SelectMapFormat.js +50 -50
  142. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  143. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +20 -20
  144. package/lib/esm/ui/widget/SubLayersDataProvider.js +71 -71
  145. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  146. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +10 -10
  147. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  148. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  149. package/lib/esm/ui/widget/SubLayersTree.d.ts +15 -15
  150. package/lib/esm/ui/widget/SubLayersTree.js +408 -408
  151. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  152. package/lib/esm/ui/widget/SubLayersTree.scss +69 -69
  153. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +14 -14
  154. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  155. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  156. package/lib/esm/ui/widget/TransparencyPopupButton.scss +36 -36
  157. package/package.json +16 -16
@@ -1,521 +1,527 @@
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 Modeless WMTS
6
- import { DialogButtonType, SpecialKey } from "@itwin/appui-abstract";
7
- import { UiFramework } from "@itwin/appui-react";
8
- import { Button, Input, LabeledInput, ProgressLinear, Radio } from "@itwin/itwinui-react";
9
- import { IModelApp, MapLayerSource, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, } from "@itwin/core-frontend";
10
- import { Dialog, Icon, useCrossOriginPopup } from "@itwin/core-react";
11
- import * as React from "react";
12
- import { MapLayerPreferences } from "../../MapLayerPreferences";
13
- import { MapLayersUI } from "../../mapLayers";
14
- import "./MapUrlDialog.scss";
15
- import { BeEvent, Guid } from "@itwin/core-bentley";
16
- import { SelectMapFormat } from "./SelectMapFormat";
17
- export const MAP_TYPES = {
18
- wms: "WMS",
19
- arcGis: "ArcGIS",
20
- wmts: "WMTS",
21
- tileUrl: "TileURL",
22
- arcGisFeature: "ArcGISFeature",
23
- };
24
- // eslint-disable-next-line @typescript-eslint/naming-convention
25
- export function MapUrlDialog(props) {
26
- const { isOverlay, onOkResult, mapTypesOptions } = props;
27
- const getMapUrlFromProps = React.useCallback(() => {
28
- if (props.mapLayerSourceToEdit) {
29
- return props.mapLayerSourceToEdit.url;
30
- }
31
- else if (props.layerRequiringCredentials?.url) {
32
- return props.layerRequiringCredentials.url;
33
- }
34
- return "";
35
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
36
- const getMapNameFromProps = React.useCallback(() => {
37
- if (props.mapLayerSourceToEdit) {
38
- return props.mapLayerSourceToEdit.name;
39
- }
40
- else if (props.layerRequiringCredentials?.name) {
41
- return props.layerRequiringCredentials.name;
42
- }
43
- return "";
44
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
45
- const getFormatFromProps = React.useCallback(() => {
46
- if (props.mapLayerSourceToEdit) {
47
- return props.mapLayerSourceToEdit.formatId;
48
- }
49
- else if (props.layerRequiringCredentials?.formatId) {
50
- return props.layerRequiringCredentials.formatId;
51
- }
52
- return undefined;
53
- }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
54
- const [dialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
55
- const [typeLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
56
- const [nameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
57
- const [nameInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
58
- const [urlLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
59
- const [urlInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
60
- const [iTwinSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
61
- const [modelSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
62
- const [missingCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
63
- const [invalidCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
64
- const [externalLoginTitle] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
65
- const [externalLoginFailedMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
66
- const [externalLoginSucceededMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
67
- const [externalLoginWaitingMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
68
- const [externalLoginTryAgainLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
69
- const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
70
- const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
71
- const [layerAttachPending, setLayerAttachPending] = React.useState(false);
72
- const [layerAuthPending, setLayerAuthPending] = React.useState(false);
73
- const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
74
- const [mapName, setMapName] = React.useState(getMapNameFromProps());
75
- const [userName, setUserName] = React.useState("");
76
- const [password, setPassword] = React.useState("");
77
- const [noSaveSettingsWarning] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
78
- const [passwordLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
79
- const [passwordRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
80
- const [userNameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
81
- const [userNameRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
82
- const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
83
- const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
84
- const [showOauthPopup, setShowOauthPopup] = React.useState(false);
85
- const [externalLoginUrl, setExternalLoginUrl] = React.useState();
86
- const [onOauthProcessEnd] = React.useState(new BeEvent());
87
- const [accessClient, setAccessClient] = React.useState();
88
- const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
89
- const [mapType, setMapType] = React.useState(getFormatFromProps() ?? "ArcGIS");
90
- // 'isMounted' is used to prevent any async operation once the hook has been
91
- // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
92
- const isMounted = React.useRef(false);
93
- React.useEffect(() => {
94
- isMounted.current = true;
95
- return () => {
96
- isMounted.current = false;
97
- };
98
- }, []);
99
- const [isSettingsStorageAvailable] = React.useState(MapLayersUI.iTwinConfig && props?.activeViewport?.iModel?.iTwinId);
100
- const [hasImodelContext] = React.useState(props?.activeViewport?.iModel?.iTwinId !== undefined
101
- && props.activeViewport.iModel.iTwinId !== Guid.empty
102
- && props?.activeViewport?.iModel?.iModelId !== undefined
103
- && props?.activeViewport.iModel.iModelId !== Guid.empty);
104
- // Even though the settings storage is available,
105
- // we don't always want to enable it in the UI.
106
- const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
107
- const [layerRequiringCredentialsIdx] = React.useState(() => {
108
- if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
109
- return undefined;
110
- }
111
- const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
112
- if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
113
- return undefined;
114
- }
115
- else {
116
- return indexInDisplayStyle;
117
- }
118
- });
119
- const handleCancel = React.useCallback(() => {
120
- if (props.onCancelResult) {
121
- props.onCancelResult();
122
- return;
123
- }
124
- UiFramework.dialogs.modal.close();
125
- }, [props]);
126
- const onUsernameChange = React.useCallback((event) => {
127
- setUserName(event.target.value);
128
- if (invalidCredentialsProvided)
129
- setInvalidCredentialsProvided(false);
130
- }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
131
- const onPasswordChange = React.useCallback((event) => {
132
- setPassword(event.target.value);
133
- if (invalidCredentialsProvided)
134
- setInvalidCredentialsProvided(false);
135
- }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
136
- const handleArcGisLogin = React.useCallback(() => {
137
- setLayerAuthPending(true);
138
- setShowOauthPopup(true);
139
- if (oauthProcessSucceeded === false) {
140
- setOAuthProcessSucceeded(undefined);
141
- }
142
- }, [oauthProcessSucceeded]);
143
- // return true if authorization is needed
144
- const updateAuthState = React.useCallback(async (source, sourceValidation) => {
145
- const sourceRequireAuth = (sourceValidation.status === MapLayerSourceStatus.RequireAuth);
146
- const invalidCredentials = (sourceValidation.status === MapLayerSourceStatus.InvalidCredentials);
147
- if (sourceRequireAuth) {
148
- const settings = source.toLayerSettings();
149
- if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
150
- try {
151
- const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
152
- if (tokenEndpoint !== undefined) {
153
- const loginUrl = tokenEndpoint.getLoginUrl();
154
- setExternalLoginUrl(loginUrl);
155
- }
156
- }
157
- catch (_error) {
158
- }
159
- }
160
- }
161
- setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
162
- if (invalidCredentials) {
163
- setInvalidCredentialsProvided(true);
164
- }
165
- else if (invalidCredentialsProvided) {
166
- setInvalidCredentialsProvided(false); // flag reset
167
- }
168
- return sourceRequireAuth || invalidCredentials;
169
- }, [accessClient, invalidCredentialsProvided]);
170
- const updateAttachedLayer = React.useCallback(async (source, validation) => {
171
- const vp = props?.activeViewport;
172
- if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
173
- const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
174
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
175
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
176
- return true;
177
- }
178
- // Layer is already attached,
179
- vp.displayStyle.changeMapLayerProps({
180
- subLayers: validation.subLayers,
181
- }, layerRequiringCredentialsIdx, isOverlay);
182
- vp.displayStyle.changeMapLayerCredentials(layerRequiringCredentialsIdx, isOverlay, source.userName, source.password);
183
- // Either initial attach/initialize failed or the layer failed to load at least one tile
184
- // because of an invalid token; in both cases tile tree needs to be fully reset
185
- const provider = vp.getMapLayerImageryProvider(layerRequiringCredentialsIdx, isOverlay);
186
- provider?.resetStatus();
187
- vp.resetMapLayer(layerRequiringCredentialsIdx, isOverlay);
188
- vp.invalidateRenderPlan();
189
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
190
- // don't call it if the dialog needs to remains open.
191
- onOkResult();
192
- return true;
193
- }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
194
- // Returns true if no further input is needed from end-user.
195
- const doAttach = React.useCallback(async (source, validation) => {
196
- const vp = props?.activeViewport;
197
- if (vp === undefined || source === undefined) {
198
- const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
199
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
200
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
201
- return true;
202
- }
203
- // Update service settings if storage is available and we are not prompting user for credentials
204
- if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
205
- const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
206
- if (vp.iModel.iTwinId && !(await MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
207
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
208
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msgError));
209
- }
210
- }
211
- const settings = source.toLayerSettings(validation.subLayers);
212
- if (settings) {
213
- vp.displayStyle.attachMapLayer({ settings, isOverlay });
214
- const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
215
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
216
- }
217
- else {
218
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
219
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
220
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
221
- }
222
- vp.invalidateRenderPlan();
223
- // This handler will close the layer source handler, and therefore the MapUrl dialog.
224
- // don't call it if the dialog needs to remains open.
225
- onOkResult();
226
- return true;
227
- }, [hasImodelContext, isOverlay, onOkResult, props?.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
228
- // Validate the layer source and attempt to attach (or update) the layer.
229
- // Returns true if no further input is needed from end-user (i.e. close the dialog)
230
- const attemptAttachSource = React.useCallback(async (source) => {
231
- try {
232
- const validation = await source.validateSource(true);
233
- if (validation.status === MapLayerSourceStatus.Valid) {
234
- if (layerRequiringCredentialsIdx === undefined) {
235
- return await doAttach(source, validation);
236
- }
237
- else {
238
- return await updateAttachedLayer(source, validation);
239
- }
240
- }
241
- else if (validation.status === MapLayerSourceStatus.InvalidCoordinateSystem) {
242
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCoordinateSystem");
243
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
244
- return true;
245
- }
246
- else {
247
- const authNeeded = await updateAuthState(source, validation);
248
- if (authNeeded) {
249
- return false;
250
- }
251
- else {
252
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
253
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, `${msg} ${source.url}`));
254
- return true;
255
- }
256
- }
257
- return false;
258
- }
259
- catch (error) {
260
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
261
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
262
- return true;
263
- }
264
- }, [updateAuthState, doAttach, layerRequiringCredentialsIdx, updateAttachedLayer]);
265
- const onNameChange = React.useCallback((event) => {
266
- setMapName(event.target.value);
267
- }, [setMapName]);
268
- const onRadioChange = React.useCallback((event) => {
269
- setSettingsStorageRadio(event.target.value);
270
- }, [setSettingsStorageRadio]);
271
- const onUrlChange = React.useCallback((event) => {
272
- setMapUrl(event.target.value);
273
- }, [setMapUrl]);
274
- const createSource = React.useCallback(() => {
275
- let source;
276
- if (mapUrl && mapName) {
277
- source = MapLayerSource.fromJSON({
278
- url: mapUrl,
279
- name: mapName,
280
- formatId: mapType
281
- });
282
- // Set credentials separately since they are not part of JSON
283
- if (source) {
284
- source.userName = userName || undefined; // When there is no value, empty string is always returned, in this case force it to undefined,
285
- source.password = password || undefined;
286
- }
287
- }
288
- return source;
289
- }, [mapName, mapType, mapUrl, password, userName]);
290
- const handleOk = React.useCallback(() => {
291
- const source = createSource();
292
- if (source === undefined || props.mapLayerSourceToEdit) {
293
- UiFramework.dialogs.modal.close();
294
- onOkResult();
295
- if (source === undefined) {
296
- // Close the dialog and inform end user something went wrong.
297
- const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
298
- const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
299
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
300
- return;
301
- }
302
- // Simply change the source definition in the setting service
303
- if (props.mapLayerSourceToEdit !== undefined) {
304
- const vp = props.activeViewport;
305
- void (async () => {
306
- if (isSettingsStorageAvailable && vp?.iModel?.iTwinId) {
307
- try {
308
- await MapLayerPreferences.replaceSource(props.mapLayerSourceToEdit, source, vp.iModel.iTwinId, vp?.iModel.iModelId);
309
- }
310
- catch (err) {
311
- const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: props.mapLayerSourceToEdit?.name });
312
- IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
313
- return;
314
- }
315
- }
316
- })();
317
- return;
318
- }
319
- }
320
- setLayerAttachPending(true);
321
- // Attach source asynchronously.
322
- void (async () => {
323
- try {
324
- const closeDialog = await attemptAttachSource(source);
325
- if (isMounted.current) {
326
- setLayerAttachPending(false);
327
- }
328
- // In theory the modal dialog should always get closed by the parent
329
- // AttachLayerPanel's 'onOkResult' handler. We close it here just in case.
330
- if (closeDialog) {
331
- UiFramework.dialogs.modal.close();
332
- onOkResult();
333
- }
334
- }
335
- catch (_error) {
336
- onOkResult();
337
- UiFramework.dialogs.modal.close();
338
- }
339
- })();
340
- }, [createSource, props.mapLayerSourceToEdit, props.activeViewport, onOkResult, mapUrl, isSettingsStorageAvailable, attemptAttachSource]);
341
- React.useEffect(() => {
342
- const handleOAuthProcessEnd = (success, _state) => {
343
- onOauthProcessEnd.raiseEvent(success, _state);
344
- };
345
- // Currently only arcgis support AccessClient
346
- const ac = IModelApp.mapLayerFormatRegistry.getAccessClient(MAP_TYPES.arcGis);
347
- if (ac?.onOAuthProcessEnd) {
348
- setAccessClient(ac); // cache it, so we dont need to make another lookup;
349
- ac.onOAuthProcessEnd.addListener(handleOAuthProcessEnd);
350
- }
351
- setAccessClientInitialized(true);
352
- return () => {
353
- if (ac?.onOAuthProcessEnd) {
354
- ac.onOAuthProcessEnd.removeListener(handleOAuthProcessEnd);
355
- }
356
- setAccessClient(undefined);
357
- setAccessClientInitialized(false);
358
- };
359
- }, [mapType, onOauthProcessEnd, setAccessClient]);
360
- // After a map type change, make sure the different Oauth states are reset.
361
- React.useEffect(() => {
362
- // Reset few states
363
- setServerRequireCredentials(false);
364
- setInvalidCredentialsProvided(false);
365
- setShowOauthPopup(false);
366
- setOAuthProcessSucceeded(undefined);
367
- setExternalLoginUrl(undefined);
368
- }, [mapType]);
369
- // The first time the dialog is loaded and we already know the layer requires auth. (i.e ImageryProvider already made an attempt)
370
- // makes a request to discover the authentification types and adjust UI accordingly (i.e. username/password fields, Oauth popup)
371
- // Without this effect, user would have to manually click the 'OK' button in order to trigger the layer connection.
372
- React.useEffect(() => {
373
- // Attach source asynchronously.
374
- void (async () => {
375
- if (isAccessClientInitialized && props.layerRequiringCredentials?.url !== undefined && props.layerRequiringCredentials?.name !== undefined) {
376
- try {
377
- const source = MapLayerSource.fromJSON({
378
- url: props.layerRequiringCredentials.url,
379
- name: props.layerRequiringCredentials.name,
380
- formatId: props.layerRequiringCredentials.formatId
381
- });
382
- if (source !== undefined) {
383
- setLayerAttachPending(true);
384
- const validation = await source.validateSource(true);
385
- if (isMounted.current) {
386
- setLayerAttachPending(false);
387
- }
388
- await updateAuthState(source, validation);
389
- }
390
- }
391
- catch (_error) { }
392
- }
393
- })();
394
- }, [isAccessClientInitialized,
395
- props.layerRequiringCredentials?.formatId,
396
- props.layerRequiringCredentials?.name,
397
- props.layerRequiringCredentials?.url,
398
- updateAuthState]);
399
- const dialogContainer = React.useRef(null);
400
- const readyToSave = React.useCallback(() => {
401
- const credentialsSet = !!userName && !!password;
402
- return (!!mapUrl && !!mapName)
403
- && !layerAttachPending
404
- && (!serverRequireCredentials || credentialsSet)
405
- && !invalidCredentialsProvided
406
- && (externalLoginUrl === undefined || (externalLoginUrl !== undefined && oauthProcessSucceeded));
407
- }, [userName, password, mapUrl, mapName, serverRequireCredentials, layerAttachPending, invalidCredentialsProvided, externalLoginUrl, oauthProcessSucceeded]);
408
- const buttonCluster = React.useMemo(() => [
409
- { type: DialogButtonType.OK, onClick: handleOk, disabled: !readyToSave() },
410
- { type: DialogButtonType.Cancel, onClick: handleCancel },
411
- ], [readyToSave, handleCancel, handleOk]);
412
- const handleOnKeyDown = React.useCallback((event) => {
413
- if (event.key === SpecialKey.Enter) {
414
- if (readyToSave())
415
- handleOk();
416
- }
417
- }, [handleOk, readyToSave]);
418
- // onOauthProcessEnd events handler
419
- React.useEffect(() => {
420
- const handleOauthProcess = (success, _state) => {
421
- setLayerAuthPending(false);
422
- if (success) {
423
- setOAuthProcessSucceeded(true);
424
- setShowOauthPopup(false);
425
- setLayerAttachPending(false);
426
- handleOk(); // Add the layer the same way the user would do by clicking 'ok'
427
- }
428
- else {
429
- setShowOauthPopup(false);
430
- setLayerAttachPending(false);
431
- setOAuthProcessSucceeded(false);
432
- }
433
- };
434
- onOauthProcessEnd.addListener(handleOauthProcess);
435
- return () => {
436
- onOauthProcessEnd.removeListener(handleOauthProcess);
437
- };
438
- }, [handleOk, onOauthProcessEnd]);
439
- //
440
- // Monitors authentication method changes
441
- React.useEffect(() => {
442
- if (serverRequireCredentials && oauthProcessSucceeded === undefined && externalLoginUrl !== undefined) {
443
- handleArcGisLogin();
444
- }
445
- }, [oauthProcessSucceeded, externalLoginUrl, handleArcGisLogin, serverRequireCredentials]);
446
- // Monitors Oauth2 popup was closed
447
- const handleOAuthPopupClose = React.useCallback(() => {
448
- setShowOauthPopup(false);
449
- setLayerAuthPending(false);
450
- if (oauthProcessSucceeded === undefined)
451
- setOAuthProcessSucceeded(false); // indicates there was a failed attempt
452
- }, [oauthProcessSucceeded]);
453
- // Utility function to get warning message section
454
- function renderWarningMessage() {
455
- let node;
456
- let warningMessage;
457
- // Get the proper warning message
458
- if (showOauthPopup) {
459
- warningMessage = externalLoginWaitingMsg;
460
- }
461
- else if (oauthProcessSucceeded === false) {
462
- warningMessage = externalLoginFailedMsg;
463
- }
464
- else if (oauthProcessSucceeded === true) {
465
- warningMessage = externalLoginSucceededMsg;
466
- }
467
- else if (invalidCredentialsProvided) {
468
- warningMessage = invalidCredentialsLabel;
469
- }
470
- else if (serverRequireCredentials && (!userName || !password)) {
471
- warningMessage = missingCredentialsLabel;
472
- }
473
- // Sometimes we want to add an extra node, such as a button
474
- let extraNode;
475
- if (oauthProcessSucceeded === false) {
476
- extraNode = React.createElement("div", null,
477
- React.createElement(Button, { onClick: handleArcGisLogin }, externalLoginTryAgainLabel));
478
- }
479
- if (warningMessage !== undefined) {
480
- return (React.createElement("div", { className: "map-layer-source-warnMessage" },
481
- React.createElement(Icon, { className: "map-layer-source-warnMessage-icon", iconSpec: "icon-status-warning" }),
482
- React.createElement("span", { className: "map-layer-source-warnMessage-label" }, warningMessage),
483
- extraNode));
484
- }
485
- else {
486
- return (React.createElement("span", { className: "map-layer-source-placeholder" }, "\u00A0"));
487
- }
488
- return node;
489
- }
490
- // Use a hook to display the popup.
491
- // The display of the popup is controlled by the 'showOauthPopup' state variable.
492
- useCrossOriginPopup(showOauthPopup, externalLoginUrl, externalLoginTitle, 450, 450, handleOAuthPopupClose);
493
- return (React.createElement("div", { ref: dialogContainer },
494
- React.createElement(Dialog, { className: "map-layer-url-dialog", title: dialogTitle, opened: true, resizable: true, movable: true, modal: true, buttonCluster: buttonCluster, onClose: handleCancel, onEscape: handleCancel, minHeight: 120, maxWidth: 600, titleStyle: { paddingLeft: "10px" }, footerStyle: { paddingBottom: "10px", paddingRight: "10px" }, trapFocus: false },
495
- React.createElement("div", { className: "map-layer-url-dialog-content" },
496
- React.createElement("div", { className: "map-layer-source-url" },
497
- React.createElement("span", { className: "map-layer-source-label" }, typeLabel),
498
- React.createElement(SelectMapFormat, { value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, mapTypesOptions: mapTypesOptions }),
499
- React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
500
- React.createElement(Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
501
- React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
502
- React.createElement(Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
503
- serverRequireCredentials
504
- && externalLoginUrl === undefined // external login is handled in popup
505
- && props.mapLayerSourceToEdit === undefined &&
506
- React.createElement(React.Fragment, null,
507
- React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
508
- React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
509
- React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
510
- React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
511
- isSettingsStorageAvailable &&
512
- React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
513
- React.createElement("div", null,
514
- React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
515
- React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
516
- renderWarningMessage(),
517
- (layerAttachPending || layerAuthPending) &&
518
- React.createElement("div", { className: "map-layer-source-progressBar" },
519
- React.createElement(ProgressLinear, { indeterminate: true })))));
520
- }
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 Modeless WMTS
6
+ import { DialogButtonType, SpecialKey } from "@itwin/appui-abstract";
7
+ import { UiFramework } from "@itwin/appui-react";
8
+ import { Button, Input, LabeledInput, ProgressLinear, Radio } from "@itwin/itwinui-react";
9
+ import { IModelApp, MapLayerSource, MapLayerSourceStatus, NotifyMessageDetails, OutputMessagePriority, } from "@itwin/core-frontend";
10
+ import { Dialog, Icon, useCrossOriginPopup } from "@itwin/core-react";
11
+ import * as React from "react";
12
+ import { MapLayerPreferences } from "../../MapLayerPreferences";
13
+ import { MapLayersUI } from "../../mapLayers";
14
+ import "./MapUrlDialog.scss";
15
+ import { BeEvent, Guid } from "@itwin/core-bentley";
16
+ import { SelectMapFormat } from "./SelectMapFormat";
17
+ export const MAP_TYPES = {
18
+ wms: "WMS",
19
+ arcGis: "ArcGIS",
20
+ wmts: "WMTS",
21
+ tileUrl: "TileURL",
22
+ arcGisFeature: "ArcGISFeature",
23
+ };
24
+ // eslint-disable-next-line @typescript-eslint/naming-convention
25
+ export function MapUrlDialog(props) {
26
+ const { isOverlay, onOkResult, mapTypesOptions } = props;
27
+ const getMapUrlFromProps = React.useCallback(() => {
28
+ if (props.mapLayerSourceToEdit) {
29
+ return props.mapLayerSourceToEdit.url;
30
+ }
31
+ else if (props.layerRequiringCredentials?.url) {
32
+ return props.layerRequiringCredentials.url;
33
+ }
34
+ return "";
35
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
36
+ const getMapNameFromProps = React.useCallback(() => {
37
+ if (props.mapLayerSourceToEdit) {
38
+ return props.mapLayerSourceToEdit.name;
39
+ }
40
+ else if (props.layerRequiringCredentials?.name) {
41
+ return props.layerRequiringCredentials.name;
42
+ }
43
+ return "";
44
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
45
+ const getFormatFromProps = React.useCallback(() => {
46
+ if (props.mapLayerSourceToEdit) {
47
+ return props.mapLayerSourceToEdit.formatId;
48
+ }
49
+ else if (props.layerRequiringCredentials?.formatId) {
50
+ return props.layerRequiringCredentials.formatId;
51
+ }
52
+ return undefined;
53
+ }, [props.layerRequiringCredentials, props.mapLayerSourceToEdit]);
54
+ const [dialogTitle] = React.useState(MapLayersUI.localization.getLocalizedString(props.layerRequiringCredentials || props.mapLayerSourceToEdit ? "mapLayers:CustomAttach.EditCustomLayer" : "mapLayers:CustomAttach.AttachCustomLayer"));
55
+ const [typeLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Type"));
56
+ const [nameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.Name"));
57
+ const [nameInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NameInputPlaceHolder"));
58
+ const [urlLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.URL"));
59
+ const [urlInputPlaceHolder] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.UrlInputPlaceHolder"));
60
+ const [iTwinSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnITwinSettings"));
61
+ const [modelSettingsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.StoreOnModelSettings"));
62
+ const [missingCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MissingCredentials"));
63
+ const [invalidCredentialsLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCredentials"));
64
+ const [externalLoginTitle] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLogin"));
65
+ const [externalLoginFailedMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginFailed"));
66
+ const [externalLoginSucceededMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginSucceeded"));
67
+ const [externalLoginWaitingMsg] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginWaiting"));
68
+ const [externalLoginTryAgainLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ExternalLoginTryAgain"));
69
+ const [serverRequireCredentials, setServerRequireCredentials] = React.useState(false);
70
+ const [invalidCredentialsProvided, setInvalidCredentialsProvided] = React.useState(false);
71
+ const [layerAttachPending, setLayerAttachPending] = React.useState(false);
72
+ const [layerAuthPending, setLayerAuthPending] = React.useState(false);
73
+ const [mapUrl, setMapUrl] = React.useState(getMapUrlFromProps());
74
+ const [mapName, setMapName] = React.useState(getMapNameFromProps());
75
+ const [userName, setUserName] = React.useState("");
76
+ const [password, setPassword] = React.useState("");
77
+ const [noSaveSettingsWarning] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.NoSaveSettingsWarning"));
78
+ const [passwordLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Password"));
79
+ const [passwordRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.PasswordRequired"));
80
+ const [userNameLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.Username"));
81
+ const [userNameRequiredLabel] = React.useState(MapLayersUI.localization.getLocalizedString("mapLayers:AuthenticationInputs.UsernameRequired"));
82
+ const [settingsStorage, setSettingsStorageRadio] = React.useState("iTwin");
83
+ const [oauthProcessSucceeded, setOAuthProcessSucceeded] = React.useState(undefined);
84
+ const [showOauthPopup, setShowOauthPopup] = React.useState(false);
85
+ const [externalLoginUrl, setExternalLoginUrl] = React.useState();
86
+ const [onOauthProcessEnd] = React.useState(new BeEvent());
87
+ const [accessClient, setAccessClient] = React.useState();
88
+ const [isAccessClientInitialized, setAccessClientInitialized] = React.useState(false);
89
+ const [mapType, setMapType] = React.useState(getFormatFromProps() ?? "ArcGIS");
90
+ // 'isMounted' is used to prevent any async operation once the hook has been
91
+ // unloaded. Otherwise we get a 'Can't perform a React state update on an unmounted component.' warning in the console.
92
+ const isMounted = React.useRef(false);
93
+ React.useEffect(() => {
94
+ isMounted.current = true;
95
+ return () => {
96
+ isMounted.current = false;
97
+ };
98
+ }, []);
99
+ const [isSettingsStorageAvailable] = React.useState(MapLayersUI.iTwinConfig && props?.activeViewport?.iModel?.iTwinId);
100
+ const [hasImodelContext] = React.useState(props?.activeViewport?.iModel?.iTwinId !== undefined
101
+ && props.activeViewport.iModel.iTwinId !== Guid.empty
102
+ && props?.activeViewport?.iModel?.iModelId !== undefined
103
+ && props?.activeViewport.iModel.iModelId !== Guid.empty);
104
+ // Even though the settings storage is available,
105
+ // we don't always want to enable it in the UI.
106
+ const [settingsStorageDisabled] = React.useState(!isSettingsStorageAvailable || props.mapLayerSourceToEdit !== undefined || props.layerRequiringCredentials !== undefined);
107
+ const [layerRequiringCredentialsIdx] = React.useState(() => {
108
+ if (props.layerRequiringCredentials === undefined || !props.layerRequiringCredentials.name || !props.layerRequiringCredentials.url) {
109
+ return undefined;
110
+ }
111
+ const indexInDisplayStyle = props.activeViewport?.displayStyle.findMapLayerIndexByNameAndSource(props.layerRequiringCredentials.name, props.layerRequiringCredentials.url, isOverlay);
112
+ if (indexInDisplayStyle === undefined || indexInDisplayStyle < 0) {
113
+ return undefined;
114
+ }
115
+ else {
116
+ return indexInDisplayStyle;
117
+ }
118
+ });
119
+ const handleCancel = React.useCallback(() => {
120
+ if (props.onCancelResult) {
121
+ props.onCancelResult();
122
+ return;
123
+ }
124
+ UiFramework.dialogs.modal.close();
125
+ }, [props]);
126
+ const onUsernameChange = React.useCallback((event) => {
127
+ setUserName(event.target.value);
128
+ if (invalidCredentialsProvided)
129
+ setInvalidCredentialsProvided(false);
130
+ }, [setUserName, invalidCredentialsProvided, setInvalidCredentialsProvided]);
131
+ const onPasswordChange = React.useCallback((event) => {
132
+ setPassword(event.target.value);
133
+ if (invalidCredentialsProvided)
134
+ setInvalidCredentialsProvided(false);
135
+ }, [setPassword, invalidCredentialsProvided, setInvalidCredentialsProvided]);
136
+ const handleArcGisLogin = React.useCallback(() => {
137
+ setLayerAuthPending(true);
138
+ setShowOauthPopup(true);
139
+ if (oauthProcessSucceeded === false) {
140
+ setOAuthProcessSucceeded(undefined);
141
+ }
142
+ }, [oauthProcessSucceeded]);
143
+ // return true if authorization is needed
144
+ const updateAuthState = React.useCallback(async (source, sourceValidation) => {
145
+ const sourceRequireAuth = (sourceValidation.status === MapLayerSourceStatus.RequireAuth);
146
+ const invalidCredentials = (sourceValidation.status === MapLayerSourceStatus.InvalidCredentials);
147
+ if (sourceRequireAuth) {
148
+ const settings = source.toLayerSettings();
149
+ if (accessClient !== undefined && accessClient.getTokenServiceEndPoint !== undefined && settings !== undefined) {
150
+ try {
151
+ const tokenEndpoint = await accessClient.getTokenServiceEndPoint(settings.url);
152
+ if (tokenEndpoint !== undefined) {
153
+ const loginUrl = tokenEndpoint.getLoginUrl();
154
+ setExternalLoginUrl(loginUrl);
155
+ }
156
+ }
157
+ catch (_error) {
158
+ }
159
+ }
160
+ }
161
+ setServerRequireCredentials(sourceRequireAuth || invalidCredentials);
162
+ if (invalidCredentials) {
163
+ setInvalidCredentialsProvided(true);
164
+ }
165
+ else if (invalidCredentialsProvided) {
166
+ setInvalidCredentialsProvided(false); // flag reset
167
+ }
168
+ return sourceRequireAuth || invalidCredentials;
169
+ }, [accessClient, invalidCredentialsProvided]);
170
+ const updateAttachedLayer = React.useCallback(async (source, validation) => {
171
+ const vp = props?.activeViewport;
172
+ if (vp === undefined || source === undefined || layerRequiringCredentialsIdx === undefined) {
173
+ const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
174
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
175
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
176
+ return true;
177
+ }
178
+ // Layer is already attached,
179
+ vp.displayStyle.changeMapLayerProps({
180
+ subLayers: validation.subLayers,
181
+ }, layerRequiringCredentialsIdx, isOverlay);
182
+ vp.displayStyle.changeMapLayerCredentials(layerRequiringCredentialsIdx, isOverlay, source.userName, source.password);
183
+ // Either initial attach/initialize failed or the layer failed to load at least one tile
184
+ // because of an invalid token; in both cases tile tree needs to be fully reset
185
+ const provider = vp.getMapLayerImageryProvider(layerRequiringCredentialsIdx, isOverlay);
186
+ provider?.resetStatus();
187
+ vp.resetMapLayer(layerRequiringCredentialsIdx, isOverlay);
188
+ vp.invalidateRenderPlan();
189
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
190
+ // don't call it if the dialog needs to remains open.
191
+ onOkResult();
192
+ return true;
193
+ }, [isOverlay, layerRequiringCredentialsIdx, onOkResult, props.activeViewport]);
194
+ // Returns true if no further input is needed from end-user.
195
+ const doAttach = React.useCallback(async (source, validation) => {
196
+ const vp = props?.activeViewport;
197
+ if (vp === undefined || source === undefined) {
198
+ const error = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachMissingViewOrSource");
199
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
200
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
201
+ return true;
202
+ }
203
+ // Update service settings if storage is available and we are not prompting user for credentials
204
+ if (!settingsStorageDisabled && !props.layerRequiringCredentials) {
205
+ const storeOnIModel = (hasImodelContext ? "Model" === settingsStorage : undefined);
206
+ if (vp.iModel.iTwinId && !(await MapLayerPreferences.storeSource(source, vp.iModel.iTwinId, vp.iModel.iModelId, storeOnIModel))) {
207
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerPreferencesStoreFailed");
208
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msgError));
209
+ }
210
+ }
211
+ // Some sources have a single non-visible sub-layer (i.e. ArcGIS World Topo Map); to avoid having a layer with no content (and no way to change the sub-layer visibility)
212
+ // we force the sub-layer visibility to ON.
213
+ let subLayers = validation.subLayers;
214
+ if (validation.subLayers && validation.subLayers.length === 1 && validation.subLayers[0].visible === false) {
215
+ subLayers = [{ ...validation.subLayers[0], visible: true }];
216
+ }
217
+ const settings = source.toLayerSettings(subLayers);
218
+ if (settings) {
219
+ vp.displayStyle.attachMapLayer({ settings, isOverlay });
220
+ const msg = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerAttached", { sourceName: source.name, sourceUrl: source.url });
221
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Info, msg));
222
+ }
223
+ else {
224
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSettingsConversionError");
225
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.MapLayerAttachError", { error: msgError, sourceUrl: source.url });
226
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
227
+ }
228
+ vp.invalidateRenderPlan();
229
+ // This handler will close the layer source handler, and therefore the MapUrl dialog.
230
+ // don't call it if the dialog needs to remains open.
231
+ onOkResult();
232
+ return true;
233
+ }, [hasImodelContext, isOverlay, onOkResult, props?.activeViewport, props.layerRequiringCredentials, settingsStorage, settingsStorageDisabled]);
234
+ // Validate the layer source and attempt to attach (or update) the layer.
235
+ // Returns true if no further input is needed from end-user (i.e. close the dialog)
236
+ const attemptAttachSource = React.useCallback(async (source) => {
237
+ try {
238
+ const validation = await source.validateSource(true);
239
+ if (validation.status === MapLayerSourceStatus.Valid) {
240
+ if (layerRequiringCredentialsIdx === undefined) {
241
+ return await doAttach(source, validation);
242
+ }
243
+ else {
244
+ return await updateAttachedLayer(source, validation);
245
+ }
246
+ }
247
+ else if (validation.status === MapLayerSourceStatus.InvalidCoordinateSystem) {
248
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.InvalidCoordinateSystem");
249
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
250
+ return true;
251
+ }
252
+ else {
253
+ const authNeeded = await updateAuthState(source, validation);
254
+ if (authNeeded) {
255
+ return false;
256
+ }
257
+ else {
258
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:CustomAttach.ValidationError");
259
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, `${msg} ${source.url}`));
260
+ return true;
261
+ }
262
+ }
263
+ return false;
264
+ }
265
+ catch (error) {
266
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error, sourceUrl: source.url });
267
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
268
+ return true;
269
+ }
270
+ }, [updateAuthState, doAttach, layerRequiringCredentialsIdx, updateAttachedLayer]);
271
+ const onNameChange = React.useCallback((event) => {
272
+ setMapName(event.target.value);
273
+ }, [setMapName]);
274
+ const onRadioChange = React.useCallback((event) => {
275
+ setSettingsStorageRadio(event.target.value);
276
+ }, [setSettingsStorageRadio]);
277
+ const onUrlChange = React.useCallback((event) => {
278
+ setMapUrl(event.target.value);
279
+ }, [setMapUrl]);
280
+ const createSource = React.useCallback(() => {
281
+ let source;
282
+ if (mapUrl && mapName) {
283
+ source = MapLayerSource.fromJSON({
284
+ url: mapUrl,
285
+ name: mapName,
286
+ formatId: mapType
287
+ });
288
+ // Set credentials separately since they are not part of JSON
289
+ if (source) {
290
+ source.userName = userName || undefined; // When there is no value, empty string is always returned, in this case force it to undefined,
291
+ source.password = password || undefined;
292
+ }
293
+ }
294
+ return source;
295
+ }, [mapName, mapType, mapUrl, password, userName]);
296
+ const handleOk = React.useCallback(() => {
297
+ const source = createSource();
298
+ if (source === undefined || props.mapLayerSourceToEdit) {
299
+ UiFramework.dialogs.modal.close();
300
+ onOkResult();
301
+ if (source === undefined) {
302
+ // Close the dialog and inform end user something went wrong.
303
+ const msgError = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerLayerSourceCreationFailed");
304
+ const msg = MapLayersUI.localization.getLocalizedString("mapLayers:Messages.MapLayerAttachError", { error: msgError, sourceUrl: mapUrl });
305
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, msg));
306
+ return;
307
+ }
308
+ // Simply change the source definition in the setting service
309
+ if (props.mapLayerSourceToEdit !== undefined) {
310
+ const vp = props.activeViewport;
311
+ void (async () => {
312
+ if (isSettingsStorageAvailable && vp?.iModel?.iTwinId) {
313
+ try {
314
+ await MapLayerPreferences.replaceSource(props.mapLayerSourceToEdit, source, vp.iModel.iTwinId, vp?.iModel.iModelId);
315
+ }
316
+ catch (err) {
317
+ const errorMessage = IModelApp.localization.getLocalizedString("mapLayers:Messages.MapLayerEditError", { layerName: props.mapLayerSourceToEdit?.name });
318
+ IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Error, errorMessage));
319
+ return;
320
+ }
321
+ }
322
+ })();
323
+ return;
324
+ }
325
+ }
326
+ setLayerAttachPending(true);
327
+ // Attach source asynchronously.
328
+ void (async () => {
329
+ try {
330
+ const closeDialog = await attemptAttachSource(source);
331
+ if (isMounted.current) {
332
+ setLayerAttachPending(false);
333
+ }
334
+ // In theory the modal dialog should always get closed by the parent
335
+ // AttachLayerPanel's 'onOkResult' handler. We close it here just in case.
336
+ if (closeDialog) {
337
+ UiFramework.dialogs.modal.close();
338
+ onOkResult();
339
+ }
340
+ }
341
+ catch (_error) {
342
+ onOkResult();
343
+ UiFramework.dialogs.modal.close();
344
+ }
345
+ })();
346
+ }, [createSource, props.mapLayerSourceToEdit, props.activeViewport, onOkResult, mapUrl, isSettingsStorageAvailable, attemptAttachSource]);
347
+ React.useEffect(() => {
348
+ const handleOAuthProcessEnd = (success, _state) => {
349
+ onOauthProcessEnd.raiseEvent(success, _state);
350
+ };
351
+ // Currently only arcgis support AccessClient
352
+ const ac = IModelApp.mapLayerFormatRegistry.getAccessClient(MAP_TYPES.arcGis);
353
+ if (ac?.onOAuthProcessEnd) {
354
+ setAccessClient(ac); // cache it, so we dont need to make another lookup;
355
+ ac.onOAuthProcessEnd.addListener(handleOAuthProcessEnd);
356
+ }
357
+ setAccessClientInitialized(true);
358
+ return () => {
359
+ if (ac?.onOAuthProcessEnd) {
360
+ ac.onOAuthProcessEnd.removeListener(handleOAuthProcessEnd);
361
+ }
362
+ setAccessClient(undefined);
363
+ setAccessClientInitialized(false);
364
+ };
365
+ }, [mapType, onOauthProcessEnd, setAccessClient]);
366
+ // After a map type change, make sure the different Oauth states are reset.
367
+ React.useEffect(() => {
368
+ // Reset few states
369
+ setServerRequireCredentials(false);
370
+ setInvalidCredentialsProvided(false);
371
+ setShowOauthPopup(false);
372
+ setOAuthProcessSucceeded(undefined);
373
+ setExternalLoginUrl(undefined);
374
+ }, [mapType]);
375
+ // The first time the dialog is loaded and we already know the layer requires auth. (i.e ImageryProvider already made an attempt)
376
+ // makes a request to discover the authentification types and adjust UI accordingly (i.e. username/password fields, Oauth popup)
377
+ // Without this effect, user would have to manually click the 'OK' button in order to trigger the layer connection.
378
+ React.useEffect(() => {
379
+ // Attach source asynchronously.
380
+ void (async () => {
381
+ if (isAccessClientInitialized && props.layerRequiringCredentials?.url !== undefined && props.layerRequiringCredentials?.name !== undefined) {
382
+ try {
383
+ const source = MapLayerSource.fromJSON({
384
+ url: props.layerRequiringCredentials.url,
385
+ name: props.layerRequiringCredentials.name,
386
+ formatId: props.layerRequiringCredentials.formatId
387
+ });
388
+ if (source !== undefined) {
389
+ setLayerAttachPending(true);
390
+ const validation = await source.validateSource(true);
391
+ if (isMounted.current) {
392
+ setLayerAttachPending(false);
393
+ }
394
+ await updateAuthState(source, validation);
395
+ }
396
+ }
397
+ catch (_error) { }
398
+ }
399
+ })();
400
+ }, [isAccessClientInitialized,
401
+ props.layerRequiringCredentials?.formatId,
402
+ props.layerRequiringCredentials?.name,
403
+ props.layerRequiringCredentials?.url,
404
+ updateAuthState]);
405
+ const dialogContainer = React.useRef(null);
406
+ const readyToSave = React.useCallback(() => {
407
+ const credentialsSet = !!userName && !!password;
408
+ return (!!mapUrl && !!mapName)
409
+ && !layerAttachPending
410
+ && (!serverRequireCredentials || credentialsSet)
411
+ && !invalidCredentialsProvided
412
+ && (externalLoginUrl === undefined || (externalLoginUrl !== undefined && oauthProcessSucceeded));
413
+ }, [userName, password, mapUrl, mapName, serverRequireCredentials, layerAttachPending, invalidCredentialsProvided, externalLoginUrl, oauthProcessSucceeded]);
414
+ const buttonCluster = React.useMemo(() => [
415
+ { type: DialogButtonType.OK, onClick: handleOk, disabled: !readyToSave() },
416
+ { type: DialogButtonType.Cancel, onClick: handleCancel },
417
+ ], [readyToSave, handleCancel, handleOk]);
418
+ const handleOnKeyDown = React.useCallback((event) => {
419
+ if (event.key === SpecialKey.Enter) {
420
+ if (readyToSave())
421
+ handleOk();
422
+ }
423
+ }, [handleOk, readyToSave]);
424
+ // onOauthProcessEnd events handler
425
+ React.useEffect(() => {
426
+ const handleOauthProcess = (success, _state) => {
427
+ setLayerAuthPending(false);
428
+ if (success) {
429
+ setOAuthProcessSucceeded(true);
430
+ setShowOauthPopup(false);
431
+ setLayerAttachPending(false);
432
+ handleOk(); // Add the layer the same way the user would do by clicking 'ok'
433
+ }
434
+ else {
435
+ setShowOauthPopup(false);
436
+ setLayerAttachPending(false);
437
+ setOAuthProcessSucceeded(false);
438
+ }
439
+ };
440
+ onOauthProcessEnd.addListener(handleOauthProcess);
441
+ return () => {
442
+ onOauthProcessEnd.removeListener(handleOauthProcess);
443
+ };
444
+ }, [handleOk, onOauthProcessEnd]);
445
+ //
446
+ // Monitors authentication method changes
447
+ React.useEffect(() => {
448
+ if (serverRequireCredentials && oauthProcessSucceeded === undefined && externalLoginUrl !== undefined) {
449
+ handleArcGisLogin();
450
+ }
451
+ }, [oauthProcessSucceeded, externalLoginUrl, handleArcGisLogin, serverRequireCredentials]);
452
+ // Monitors Oauth2 popup was closed
453
+ const handleOAuthPopupClose = React.useCallback(() => {
454
+ setShowOauthPopup(false);
455
+ setLayerAuthPending(false);
456
+ if (oauthProcessSucceeded === undefined)
457
+ setOAuthProcessSucceeded(false); // indicates there was a failed attempt
458
+ }, [oauthProcessSucceeded]);
459
+ // Utility function to get warning message section
460
+ function renderWarningMessage() {
461
+ let node;
462
+ let warningMessage;
463
+ // Get the proper warning message
464
+ if (showOauthPopup) {
465
+ warningMessage = externalLoginWaitingMsg;
466
+ }
467
+ else if (oauthProcessSucceeded === false) {
468
+ warningMessage = externalLoginFailedMsg;
469
+ }
470
+ else if (oauthProcessSucceeded === true) {
471
+ warningMessage = externalLoginSucceededMsg;
472
+ }
473
+ else if (invalidCredentialsProvided) {
474
+ warningMessage = invalidCredentialsLabel;
475
+ }
476
+ else if (serverRequireCredentials && (!userName || !password)) {
477
+ warningMessage = missingCredentialsLabel;
478
+ }
479
+ // Sometimes we want to add an extra node, such as a button
480
+ let extraNode;
481
+ if (oauthProcessSucceeded === false) {
482
+ extraNode = React.createElement("div", null,
483
+ React.createElement(Button, { onClick: handleArcGisLogin }, externalLoginTryAgainLabel));
484
+ }
485
+ if (warningMessage !== undefined) {
486
+ return (React.createElement("div", { className: "map-layer-source-warnMessage" },
487
+ React.createElement(Icon, { className: "map-layer-source-warnMessage-icon", iconSpec: "icon-status-warning" }),
488
+ React.createElement("span", { className: "map-layer-source-warnMessage-label" }, warningMessage),
489
+ extraNode));
490
+ }
491
+ else {
492
+ return (React.createElement("span", { className: "map-layer-source-placeholder" }, "\u00A0"));
493
+ }
494
+ return node;
495
+ }
496
+ // Use a hook to display the popup.
497
+ // The display of the popup is controlled by the 'showOauthPopup' state variable.
498
+ useCrossOriginPopup(showOauthPopup, externalLoginUrl, externalLoginTitle, 450, 450, handleOAuthPopupClose);
499
+ return (React.createElement("div", { ref: dialogContainer },
500
+ React.createElement(Dialog, { className: "map-layer-url-dialog", title: dialogTitle, opened: true, resizable: true, movable: true, modal: true, buttonCluster: buttonCluster, onClose: handleCancel, onEscape: handleCancel, minHeight: 120, maxWidth: 600, titleStyle: { paddingLeft: "10px" }, footerStyle: { paddingBottom: "10px", paddingRight: "10px" }, trapFocus: false },
501
+ React.createElement("div", { className: "map-layer-url-dialog-content" },
502
+ React.createElement("div", { className: "map-layer-source-url" },
503
+ React.createElement("span", { className: "map-layer-source-label" }, typeLabel),
504
+ React.createElement(SelectMapFormat, { value: mapType, disabled: props.layerRequiringCredentials !== undefined || props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, onChange: setMapType, mapTypesOptions: mapTypesOptions }),
505
+ React.createElement("span", { className: "map-layer-source-label" }, nameLabel),
506
+ React.createElement(Input, { className: "map-layer-source-input", placeholder: nameInputPlaceHolder, onChange: onNameChange, value: mapName, disabled: props.layerRequiringCredentials !== undefined || layerAttachPending || layerAuthPending }),
507
+ React.createElement("span", { className: "map-layer-source-label" }, urlLabel),
508
+ React.createElement(Input, { className: "map-layer-source-input", placeholder: urlInputPlaceHolder, onKeyPress: handleOnKeyDown, onChange: onUrlChange, disabled: props.mapLayerSourceToEdit !== undefined || layerAttachPending || layerAuthPending, value: mapUrl }),
509
+ serverRequireCredentials
510
+ && externalLoginUrl === undefined // external login is handled in popup
511
+ && props.mapLayerSourceToEdit === undefined &&
512
+ React.createElement(React.Fragment, null,
513
+ React.createElement("span", { className: "map-layer-source-label" }, userNameLabel),
514
+ React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", placeholder: serverRequireCredentials ? userNameRequiredLabel : userNameLabel, status: (!userName && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onUsernameChange, value: userName, size: "small" }),
515
+ React.createElement("span", { className: "map-layer-source-label" }, passwordLabel),
516
+ React.createElement(LabeledInput, { className: "map-layer-source-input", displayStyle: "inline", type: "password", placeholder: serverRequireCredentials ? passwordRequiredLabel : passwordLabel, status: (!password && serverRequireCredentials) || invalidCredentialsProvided ? "warning" : undefined, disabled: layerAttachPending || layerAuthPending, onChange: onPasswordChange, onKeyPress: handleOnKeyDown, value: password, size: "small" })),
517
+ isSettingsStorageAvailable &&
518
+ React.createElement("div", { title: settingsStorageDisabled ? noSaveSettingsWarning : "" }, hasImodelContext &&
519
+ React.createElement("div", null,
520
+ React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "iTwin", label: iTwinSettingsLabel, checked: settingsStorage === "iTwin", onChange: onRadioChange }),
521
+ React.createElement(Radio, { disabled: settingsStorageDisabled, name: "settingsStorage", value: "Model", label: modelSettingsLabel, checked: settingsStorage === "Model", onChange: onRadioChange }))))),
522
+ renderWarningMessage(),
523
+ (layerAttachPending || layerAuthPending) &&
524
+ React.createElement("div", { className: "map-layer-source-progressBar" },
525
+ React.createElement(ProgressLinear, { indeterminate: true })))));
526
+ }
521
527
  //# sourceMappingURL=MapUrlDialog.js.map