@itwin/map-layers 4.0.0-dev.8 → 5.0.0-dev.2

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