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

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 (155) 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.js +524 -524
  59. package/lib/cjs/ui/widget/MapUrlDialog.js.map +1 -1
  60. package/lib/cjs/ui/widget/MapUrlDialog.scss +100 -100
  61. package/lib/cjs/ui/widget/SelectMapFormat.d.ts +18 -18
  62. package/lib/cjs/ui/widget/SelectMapFormat.js +54 -54
  63. package/lib/cjs/ui/widget/SelectMapFormat.js.map +1 -1
  64. package/lib/cjs/ui/widget/SubLayersDataProvider.d.ts +20 -20
  65. package/lib/cjs/ui/widget/SubLayersDataProvider.js +75 -75
  66. package/lib/cjs/ui/widget/SubLayersDataProvider.js.map +1 -1
  67. package/lib/cjs/ui/widget/SubLayersPopupButton.d.ts +10 -10
  68. package/lib/cjs/ui/widget/SubLayersPopupButton.js +40 -40
  69. package/lib/cjs/ui/widget/SubLayersPopupButton.js.map +1 -1
  70. package/lib/cjs/ui/widget/SubLayersTree.d.ts +15 -15
  71. package/lib/cjs/ui/widget/SubLayersTree.js +413 -413
  72. package/lib/cjs/ui/widget/SubLayersTree.js.map +1 -1
  73. package/lib/cjs/ui/widget/SubLayersTree.scss +69 -69
  74. package/lib/cjs/ui/widget/TransparencyPopupButton.d.ts +14 -14
  75. package/lib/cjs/ui/widget/TransparencyPopupButton.js +47 -47
  76. package/lib/cjs/ui/widget/TransparencyPopupButton.js.map +1 -1
  77. package/lib/cjs/ui/widget/TransparencyPopupButton.scss +36 -36
  78. package/lib/esm/MapLayerPreferences.d.ts +88 -88
  79. package/lib/esm/MapLayerPreferences.js +307 -307
  80. package/lib/esm/MapLayerPreferences.js.map +1 -1
  81. package/lib/esm/map-layers.d.ts +6 -6
  82. package/lib/esm/map-layers.js +10 -10
  83. package/lib/esm/mapLayers.d.ts +44 -44
  84. package/lib/esm/mapLayers.js +57 -57
  85. package/lib/esm/mapLayers.js.map +1 -1
  86. package/lib/esm/ui/FeatureInfoUiItemsProvider.d.ts +11 -11
  87. package/lib/esm/ui/FeatureInfoUiItemsProvider.js +47 -47
  88. package/lib/esm/ui/FeatureInfoUiItemsProvider.js.map +1 -1
  89. package/lib/esm/ui/Interfaces.d.ts +50 -50
  90. package/lib/esm/ui/Interfaces.js +1 -1
  91. package/lib/esm/ui/Interfaces.js.map +1 -1
  92. package/lib/esm/ui/MapFeatureInfoTool.d.ts +13 -13
  93. package/lib/esm/ui/MapFeatureInfoTool.js +45 -45
  94. package/lib/esm/ui/MapFeatureInfoTool.js.map +1 -1
  95. package/lib/esm/ui/MapLayersUiItemsProvider.d.ts +8 -8
  96. package/lib/esm/ui/MapLayersUiItemsProvider.js +34 -34
  97. package/lib/esm/ui/MapLayersUiItemsProvider.js.map +1 -1
  98. package/lib/esm/ui/widget/AttachLayerPopupButton.d.ts +14 -14
  99. package/lib/esm/ui/widget/AttachLayerPopupButton.js +331 -331
  100. package/lib/esm/ui/widget/BasemapPanel.d.ts +8 -8
  101. package/lib/esm/ui/widget/BasemapPanel.js +152 -152
  102. package/lib/esm/ui/widget/BasemapPanel.js.map +1 -1
  103. package/lib/esm/ui/widget/BasemapPanel.scss +87 -87
  104. package/lib/esm/ui/widget/ConfirmMessageDialog.d.ts +21 -21
  105. package/lib/esm/ui/widget/ConfirmMessageDialog.js +18 -18
  106. package/lib/esm/ui/widget/ConfirmMessageDialog.js.map +1 -1
  107. package/lib/esm/ui/widget/FeatureInfoDataProvider.d.ts +40 -40
  108. package/lib/esm/ui/widget/FeatureInfoDataProvider.js +134 -134
  109. package/lib/esm/ui/widget/FeatureInfoDataProvider.js.map +1 -1
  110. package/lib/esm/ui/widget/FeatureInfoWidget.d.ts +7 -7
  111. package/lib/esm/ui/widget/FeatureInfoWidget.js +61 -61
  112. package/lib/esm/ui/widget/FeatureInfoWidget.js.map +1 -1
  113. package/lib/esm/ui/widget/MapLayerDroppable.d.ts +19 -19
  114. package/lib/esm/ui/widget/MapLayerDroppable.js +81 -81
  115. package/lib/esm/ui/widget/MapLayerDroppable.js.map +1 -1
  116. package/lib/esm/ui/widget/MapLayerManager.d.ts +26 -26
  117. package/lib/esm/ui/widget/MapLayerManager.js +396 -396
  118. package/lib/esm/ui/widget/MapLayerManager.js.map +1 -1
  119. package/lib/esm/ui/widget/MapLayerManager.scss +409 -409
  120. package/lib/esm/ui/widget/MapLayerSettingsMenu.d.ts +12 -12
  121. package/lib/esm/ui/widget/MapLayerSettingsMenu.js +78 -78
  122. package/lib/esm/ui/widget/MapLayerSettingsMenu.js.map +1 -1
  123. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.d.ts +7 -7
  124. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js +61 -61
  125. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.js.map +1 -1
  126. package/lib/esm/ui/widget/MapLayerSettingsPopupButton.scss +20 -20
  127. package/lib/esm/ui/widget/MapLayersWidget.d.ts +11 -11
  128. package/lib/esm/ui/widget/MapLayersWidget.js +27 -27
  129. package/lib/esm/ui/widget/MapLayersWidget.js.map +1 -1
  130. package/lib/esm/ui/widget/MapManagerSettings.d.ts +3 -3
  131. package/lib/esm/ui/widget/MapManagerSettings.js +196 -196
  132. package/lib/esm/ui/widget/MapManagerSettings.js.map +1 -1
  133. package/lib/esm/ui/widget/MapManagerSettings.scss +29 -29
  134. package/lib/esm/ui/widget/MapUrlDialog.d.ts +23 -23
  135. package/lib/esm/ui/widget/MapUrlDialog.js +520 -520
  136. package/lib/esm/ui/widget/MapUrlDialog.js.map +1 -1
  137. package/lib/esm/ui/widget/MapUrlDialog.scss +100 -100
  138. package/lib/esm/ui/widget/SelectMapFormat.d.ts +18 -18
  139. package/lib/esm/ui/widget/SelectMapFormat.js +50 -50
  140. package/lib/esm/ui/widget/SelectMapFormat.js.map +1 -1
  141. package/lib/esm/ui/widget/SubLayersDataProvider.d.ts +20 -20
  142. package/lib/esm/ui/widget/SubLayersDataProvider.js +71 -71
  143. package/lib/esm/ui/widget/SubLayersDataProvider.js.map +1 -1
  144. package/lib/esm/ui/widget/SubLayersPopupButton.d.ts +10 -10
  145. package/lib/esm/ui/widget/SubLayersPopupButton.js +36 -36
  146. package/lib/esm/ui/widget/SubLayersPopupButton.js.map +1 -1
  147. package/lib/esm/ui/widget/SubLayersTree.d.ts +15 -15
  148. package/lib/esm/ui/widget/SubLayersTree.js +408 -408
  149. package/lib/esm/ui/widget/SubLayersTree.js.map +1 -1
  150. package/lib/esm/ui/widget/SubLayersTree.scss +69 -69
  151. package/lib/esm/ui/widget/TransparencyPopupButton.d.ts +14 -14
  152. package/lib/esm/ui/widget/TransparencyPopupButton.js +43 -43
  153. package/lib/esm/ui/widget/TransparencyPopupButton.js.map +1 -1
  154. package/lib/esm/ui/widget/TransparencyPopupButton.scss +36 -36
  155. package/package.json +14 -14
@@ -1,521 +1,521 @@
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
+ 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
+ }
521
521
  //# sourceMappingURL=MapUrlDialog.js.map