@itwin/map-layers-formats 5.16.0-dev.4 → 5.16.0-dev.6

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 (40) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.d.ts.map +1 -1
  3. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.js +22 -8
  4. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  5. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.d.ts.map +1 -1
  6. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.js +15 -3
  7. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  8. package/lib/cjs/AzureMaps/AzureMapsImageryProvider.d.ts.map +1 -1
  9. package/lib/cjs/AzureMaps/AzureMapsImageryProvider.js +2 -1
  10. package/lib/cjs/AzureMaps/AzureMapsImageryProvider.js.map +1 -1
  11. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -1
  12. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js +4 -1
  13. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -1
  14. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesFormat.d.ts.map +1 -1
  15. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesFormat.js +28 -11
  16. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesFormat.js.map +1 -1
  17. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesProvider.d.ts +1 -0
  18. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesProvider.d.ts.map +1 -1
  19. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesProvider.js +22 -0
  20. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesProvider.js.map +1 -1
  21. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.d.ts.map +1 -1
  22. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.js +23 -9
  23. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  24. package/lib/esm/ArcGisFeature/esriPBuffer.gen.d.ts.map +1 -1
  25. package/lib/esm/ArcGisFeature/esriPBuffer.gen.js +15 -3
  26. package/lib/esm/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  27. package/lib/esm/AzureMaps/AzureMapsImageryProvider.d.ts.map +1 -1
  28. package/lib/esm/AzureMaps/AzureMapsImageryProvider.js +2 -1
  29. package/lib/esm/AzureMaps/AzureMapsImageryProvider.js.map +1 -1
  30. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -1
  31. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js +4 -1
  32. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -1
  33. package/lib/esm/OgcApiFeatures/OgcApiFeaturesFormat.d.ts.map +1 -1
  34. package/lib/esm/OgcApiFeatures/OgcApiFeaturesFormat.js +29 -12
  35. package/lib/esm/OgcApiFeatures/OgcApiFeaturesFormat.js.map +1 -1
  36. package/lib/esm/OgcApiFeatures/OgcApiFeaturesProvider.d.ts +1 -0
  37. package/lib/esm/OgcApiFeatures/OgcApiFeaturesProvider.d.ts.map +1 -1
  38. package/lib/esm/OgcApiFeatures/OgcApiFeaturesProvider.js +23 -1
  39. package/lib/esm/OgcApiFeatures/OgcApiFeaturesProvider.js.map +1 -1
  40. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"AzureMapsImageryProvider.d.ts","sourceRoot":"","sources":["../../../src/AzureMaps/AzureMapsImageryProvider.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAa,uBAAuB,EAA8E,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtK,gBAAgB;AAChB,eAAO,MAAM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pI;AAQD;;;GAGG;AACH,qBAAa,6BAA8B,SAAQ,uBAAuB;IACpB,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAC;gBAAnE,QAAQ,EAAE,qBAAqB,EAAmB,gBAAgB,CAAC,EAAE,MAAM,YAAA;IAI9F,OAAO,CAAC,sBAAsB;IAWR,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IAuB1F,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAQvF,kGAAkG;IAClF,YAAY,CAAC,KAAK,EAAE,gBAAgB,GAAG,IAAI;IAOrC,eAAe,CAAC,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAInG"}
@@ -51,7 +51,8 @@ class AzureMapsLayerImageryProvider extends core_frontend_1.MapLayerImageryProvi
51
51
  if (tileUrl.length === 0)
52
52
  return undefined;
53
53
  const tileResponse = await this.makeTileRequest(tileUrl);
54
- if (tileResponse.status === 401 || tileResponse.status === 403) {
54
+ // A status in a response managed by the fetch handler is not classified here.
55
+ if (!this.isManagedByHandler(tileResponse) && (tileResponse.status === 401 || tileResponse.status === 403)) {
55
56
  this.reportAzureAuthFailure();
56
57
  return undefined;
57
58
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AzureMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/AzureMaps/AzureMapsImageryProvider.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AASH,kEAOC;AAbD,wDAAsK;AAEtK,gBAAgB;AACH,QAAA,iCAAiC,GAAG,kBAAkB,CAAC;AAEpE,gBAAgB;AAChB,SAAgB,2BAA2B,CAAC,SAAkC,EAAE,uBAAgC;IAC9G,mGAAmG;I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AAkB,CAAC,2CAA2C,CAAC,EAAE,CAAC,CAAC,CAAC;QACvK,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,KAAuB,EAAE,GAAmB;QAChF,4DAA4D;QAC5D,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AA1DD,sEA0DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayersFormats\r\n */\r\n\r\nimport { ImageMapLayerSettings, type ImageSource, type MapLayerKey } from \"@itwin/core-common\";\r\nimport { IModelApp, MapLayerImageryProvider, MapLayerImageryProviderStatus, NotifyMessageDetails, OutputMessagePriority, ScreenViewport } from \"@itwin/core-frontend\";\r\n\r\n/** @internal */\r\nexport const azureMapsSubscriptionKeyParameter = \"subscription-key\";\r\n\r\n/** @internal */\r\nexport function getAzureMapsSubscriptionKey(accessKey: MapLayerKey | undefined, fallbackSubscriptionKey?: string): string | undefined {\r\n // A layer access key takes precedence, but an empty value falls through to the configured fallback\r\n // rather than disabling auth outright.\r\n if (accessKey !== undefined && accessKey.value.length > 0)\r\n return accessKey.value;\r\n\r\n return fallbackSubscriptionKey !== undefined && fallbackSubscriptionKey.length > 0 ? fallbackSubscriptionKey : undefined;\r\n}\r\n\r\nclass AzureMapsRequireAuthError extends Error {\r\n public constructor() {\r\n super(`Azure Maps requires a non-empty ${azureMapsSubscriptionKeyParameter} credential`);\r\n }\r\n}\r\n\r\n/**\r\n * Azure Maps imagery provider.\r\n * @beta\r\n */\r\nexport class AzureMapsLayerImageryProvider extends MapLayerImageryProvider {\r\n public constructor(settings: ImageMapLayerSettings, private readonly _subscriptionKey?: string) {\r\n super(settings, true);\r\n }\r\n\r\n private reportAzureAuthFailure(): void {\r\n this.setStatus(MapLayerImageryProviderStatus.RequireAuth);\r\n if (this._hasSuccessfullyFetchedTile) {\r\n const msg = IModelApp.localization.getLocalizedString(\"iModelJs:MapLayers.Messages.LoadTileTokenError\", { layerName: this._settings.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Warning, msg));\r\n }\r\n }\r\n\r\n // The base loadTile marks `_hasSuccessfullyFetchedTile` as soon as a response is received, before\r\n // inspecting its status. Azure returns 401/403 for missing/invalid credentials, so this override\r\n // detects that before the success is recorded, ensuring no spurious token warning on the first fetch.\r\n public override async loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined> {\r\n try {\r\n const tileUrl = await this.constructUrl(row, column, zoomLevel);\r\n if (tileUrl.length === 0)\r\n return undefined;\r\n\r\n const tileResponse = await this.makeTileRequest(tileUrl);\r\n if (tileResponse.status === 401 || tileResponse.status === 403) {\r\n this.reportAzureAuthFailure();\r\n return undefined;\r\n }\r\n\r\n this._hasSuccessfullyFetchedTile = true;\r\n return await this.getImageFromTileResponse(tileResponse, zoomLevel);\r\n } catch (error) {\r\n if (error instanceof AzureMapsRequireAuthError)\r\n this.reportAzureAuthFailure();\r\n\r\n return undefined;\r\n }\r\n }\r\n\r\n public override async constructUrl(y: number, x: number, zoom: number): Promise<string> {\r\n const subscriptionKey = getAzureMapsSubscriptionKey(this._settings.accessKey, this._subscriptionKey);\r\n if (undefined === subscriptionKey)\r\n throw new AzureMapsRequireAuthError();\r\n\r\n return `${this._settings.url}&${azureMapsSubscriptionKeyParameter}=${encodeURIComponent(subscriptionKey)}&api-version=2.0&zoom=${zoom}&x=${x}&y=${y}`;\r\n }\r\n\r\n /** @deprecated in 5.0 - might be removed in next major version. Use [addAttributions] instead. */\r\n public override addLogoCards(cards: HTMLTableElement): void {\r\n if (!cards.dataset.azureMapsLogoCard) {\r\n cards.dataset.azureMapsLogoCard = \"true\";\r\n cards.appendChild(IModelApp.makeLogoCard({ heading: \"Azure Maps\", notice: IModelApp.localization.getLocalizedString(\"iModelJs:BackgroundMap.AzureMapsCopyright\") }));\r\n }\r\n }\r\n\r\n public override async addAttributions(cards: HTMLTableElement, _vp: ScreenViewport): Promise<void> {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return Promise.resolve(this.addLogoCards(cards));\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"AzureMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/AzureMaps/AzureMapsImageryProvider.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AASH,kEAOC;AAbD,wDAAsK;AAEtK,gBAAgB;AACH,QAAA,iCAAiC,GAAG,kBAAkB,CAAC;AAEpE,gBAAgB;AAChB,SAAgB,2BAA2B,CAAC,SAAkC,EAAE,uBAAgC;IAC9G,mGAAmG;IACnG,uCAAuC;IACvC,IAAI,SAAS,KAAK,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC;QACvD,OAAO,SAAS,CAAC,KAAK,CAAC;IAEzB,OAAO,uBAAuB,KAAK,SAAS,IAAI,uBAAuB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC3H,CAAC;AAED,MAAM,yBAA0B,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,mCAAmC,yCAAiC,aAAa,CAAC,CAAC;IAC3F,CAAC;CACF;AAED;;;GAGG;AACH,MAAa,6BAA8B,SAAQ,uCAAuB;IACH;IAArE,YAAmB,QAA+B,EAAmB,gBAAyB;QAC5F,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAD6C,qBAAgB,GAAhB,gBAAgB,CAAS;IAE9F,CAAC;IAEO,sBAAsB;QAC5B,IAAI,CAAC,SAAS,CAAC,6CAA6B,CAAC,WAAW,CAAC,CAAC;QAC1D,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC;YACrC,MAAM,GAAG,GAAG,yBAAS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,CAAC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACrG,IAAI,SAAS,KAAK,eAAe;YAC/B,MAAM,IAAI,yBAAyB,EAAE,CAAC;QAExC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,yCAAiC,IAAI,kBAAkB,CAAC,eAAe,CAAC,yBAAyB,IAAI,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;IACxJ,CAAC;IAED,kGAAkG;IAClF,YAAY,CAAC,KAAuB;QAClD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,iBAAiB,EAAE,CAAC;YACrC,KAAK,CAAC,OAAO,CAAC,iBAAiB,GAAG,MAAM,CAAC;YACzC,KAAK,CAAC,WAAW,CAAC,yBAAS,CAAC,YAAY,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,yBAAS,CAAC,YAAY,CAAC,kBAAkB,CAAC,2CAA2C,CAAC,EAAE,CAAC,CAAC,CAAC;QACvK,CAAC;IACH,CAAC;IAEe,KAAK,CAAC,eAAe,CAAC,KAAuB,EAAE,GAAmB;QAChF,4DAA4D;QAC5D,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC;IACnD,CAAC;CACF;AA3DD,sEA2DC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayersFormats\r\n */\r\n\r\nimport { ImageMapLayerSettings, type ImageSource, type MapLayerKey } from \"@itwin/core-common\";\r\nimport { IModelApp, MapLayerImageryProvider, MapLayerImageryProviderStatus, NotifyMessageDetails, OutputMessagePriority, ScreenViewport } from \"@itwin/core-frontend\";\r\n\r\n/** @internal */\r\nexport const azureMapsSubscriptionKeyParameter = \"subscription-key\";\r\n\r\n/** @internal */\r\nexport function getAzureMapsSubscriptionKey(accessKey: MapLayerKey | undefined, fallbackSubscriptionKey?: string): string | undefined {\r\n // A layer access key takes precedence, but an empty value falls through to the configured fallback\r\n // rather than disabling auth outright.\r\n if (accessKey !== undefined && accessKey.value.length > 0)\r\n return accessKey.value;\r\n\r\n return fallbackSubscriptionKey !== undefined && fallbackSubscriptionKey.length > 0 ? fallbackSubscriptionKey : undefined;\r\n}\r\n\r\nclass AzureMapsRequireAuthError extends Error {\r\n public constructor() {\r\n super(`Azure Maps requires a non-empty ${azureMapsSubscriptionKeyParameter} credential`);\r\n }\r\n}\r\n\r\n/**\r\n * Azure Maps imagery provider.\r\n * @beta\r\n */\r\nexport class AzureMapsLayerImageryProvider extends MapLayerImageryProvider {\r\n public constructor(settings: ImageMapLayerSettings, private readonly _subscriptionKey?: string) {\r\n super(settings, true);\r\n }\r\n\r\n private reportAzureAuthFailure(): void {\r\n this.setStatus(MapLayerImageryProviderStatus.RequireAuth);\r\n if (this._hasSuccessfullyFetchedTile) {\r\n const msg = IModelApp.localization.getLocalizedString(\"iModelJs:MapLayers.Messages.LoadTileTokenError\", { layerName: this._settings.name });\r\n IModelApp.notifications.outputMessage(new NotifyMessageDetails(OutputMessagePriority.Warning, msg));\r\n }\r\n }\r\n\r\n // The base loadTile marks `_hasSuccessfullyFetchedTile` as soon as a response is received, before\r\n // inspecting its status. Azure returns 401/403 for missing/invalid credentials, so this override\r\n // detects that before the success is recorded, ensuring no spurious token warning on the first fetch.\r\n public override async loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined> {\r\n try {\r\n const tileUrl = await this.constructUrl(row, column, zoomLevel);\r\n if (tileUrl.length === 0)\r\n return undefined;\r\n\r\n const tileResponse = await this.makeTileRequest(tileUrl);\r\n // A status in a response managed by the fetch handler is not classified here.\r\n if (!this.isManagedByHandler(tileResponse) && (tileResponse.status === 401 || tileResponse.status === 403)) {\r\n this.reportAzureAuthFailure();\r\n return undefined;\r\n }\r\n\r\n this._hasSuccessfullyFetchedTile = true;\r\n return await this.getImageFromTileResponse(tileResponse, zoomLevel);\r\n } catch (error) {\r\n if (error instanceof AzureMapsRequireAuthError)\r\n this.reportAzureAuthFailure();\r\n\r\n return undefined;\r\n }\r\n }\r\n\r\n public override async constructUrl(y: number, x: number, zoom: number): Promise<string> {\r\n const subscriptionKey = getAzureMapsSubscriptionKey(this._settings.accessKey, this._subscriptionKey);\r\n if (undefined === subscriptionKey)\r\n throw new AzureMapsRequireAuthError();\r\n\r\n return `${this._settings.url}&${azureMapsSubscriptionKeyParameter}=${encodeURIComponent(subscriptionKey)}&api-version=2.0&zoom=${zoom}&x=${x}&y=${y}`;\r\n }\r\n\r\n /** @deprecated in 5.0 - might be removed in next major version. Use [addAttributions] instead. */\r\n public override addLogoCards(cards: HTMLTableElement): void {\r\n if (!cards.dataset.azureMapsLogoCard) {\r\n cards.dataset.azureMapsLogoCard = \"true\";\r\n cards.appendChild(IModelApp.makeLogoCard({ heading: \"Azure Maps\", notice: IModelApp.localization.getLocalizedString(\"iModelJs:BackgroundMap.AzureMapsCopyright\") }));\r\n }\r\n }\r\n\r\n public override async addAttributions(cards: HTMLTableElement, _vp: ScreenViewport): Promise<void> {\r\n // eslint-disable-next-line @typescript-eslint/no-deprecated\r\n return Promise.resolve(this.addLogoCards(cards));\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleMapsImageryProvider.d.ts","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":"AAIA;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAkC,iBAAiB,EAAE,uBAAuB,EAAwB,cAAc,EAAQ,MAAM,sBAAsB,CAAC;AAC/K,OAAO,EAAE,8BAA8B,EAAqB,wBAAwB,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AA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iClG"}
@@ -182,7 +182,10 @@ class GoogleMapsImageryProvider extends core_frontend_1.MapLayerImageryProvider
182
182
  else {
183
183
  core_bentley_1.Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);
184
184
  }
185
- this._hadUnrecoverableError = true; // Prevent from doing more invalid requests
185
+ // A response managed by the fetch handler is not classified here: the handler reports failures
186
+ // by throwing MapLayerAuthenticationFailedError, and must not have the layer given up on.
187
+ if (!this.isManagedByHandler(tileResponse))
188
+ this._hadUnrecoverableError = true; // Prevent from doing more invalid requests
186
189
  return undefined;
187
190
  }
188
191
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GoogleMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0E;AAE1E,wDAA+K;AAE/K,uFAAwF;AACxF,uEAAiE;AAEjE,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD;;;EAGE;AACF,MAAa,yBAA0B,SAAQ,uCAAuB;IAE5D,UAAU,CAAsB;IAChC,sBAAsB,GAAG,KAAK,CAAC;IAC/B,SAAS,GAAG,GAAG,CAAC;IAChB,eAAe,CAA4B;IAC3C,eAAe,CAA2C;IAC1D,cAAc,CAAqB;IAC3C,YAAY,QAA+B,EAAE,cAAyC;QACpF,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACtB,IAAI,CAAC,UAAU,GAAG,IAAI,mCAAmB,EAAE,CAAC;QAC5C,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;IACxC,CAAC;IACD,IAAoB,QAAQ,KAAa,OAAO,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEjD,KAAK,CAAC,UAAU;QAC9B,MAAM,cAAc,GAAG,oCAAe,CAAC,6BAA6B,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACrF,IAAI,CAAC,eAAe,GAAG,cAAc,CAAC;QACtC,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AAC,CAAC,IAAI,EAAE,EAAE;wBAC/B,4DAA4D;wBAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;wBAC5B,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;4BAC7C,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;4BAClB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBACtB,CAAC;oBACH,CAAC,CAAC,CAAC;gBACL,CAAC;YACH,CAAC;YACD,OAAO,KAAU,EAAE,CAAC;gBAClB,qBAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,qCAAqC,KAAK,EAAE,OAAO,IAAE,eAAe,EAAE,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;QAED,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC9C,OAAO,CAAC,GAAG,GAAG,GAAG,yBAAS,CAAC,UAAU,iCAAiC,CAAC;QACvE,OAAO,CAAC,KAAK,CAAC,OAAO,GAAG,oBAAoB,CAAC;QAE7C,KAAK,CAAC,WAAW,CAAC,yBAAS,CAAC,YAAY,CAAC;YACvC,OAAO;YACP,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AAxPD,8DAwPC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayersFormats\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, Logger } from \"@itwin/core-bentley\";\r\nimport { ImageMapLayerSettings, ImageSource } from \"@itwin/core-common\";\r\nimport { DecorateContext, GoogleMapsDecorator, IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapTile, QuadIdProps, ScreenViewport, Tile } from \"@itwin/core-frontend\";\r\nimport { GoogleMapsCreateSessionOptions, GoogleMapsSession, GoogleMapsSessionManager, ViewportInfo } from \"./GoogleMapsSession.js\";\r\nimport { NativeGoogleMapsSessionManager } from \"../internal/NativeGoogleMapsSession.js\";\r\nimport { GoogleMapsUtils } from \"../internal/GoogleMapsUtils.js\";\r\n\r\nconst loggerCategory = \"MapLayersFormats.GoogleMaps\";\r\n\r\n/*\r\n* Google Maps imagery provider\r\n* @beta\r\n*/\r\nexport class GoogleMapsImageryProvider extends MapLayerImageryProvider {\r\n\r\n private _decorator: GoogleMapsDecorator;\r\n private _hadUnrecoverableError = false;\r\n private _tileSize = 256;\r\n private _sessionManager?: GoogleMapsSessionManager;\r\n private _sessionOptions: GoogleMapsCreateSessionOptions|undefined;\r\n private _activeSession?: GoogleMapsSession;\r\n constructor(settings: ImageMapLayerSettings, sessionManager?: GoogleMapsSessionManager) {\r\n super(settings, true);\r\n this._decorator = new GoogleMapsDecorator();\r\n this._sessionManager = sessionManager;\r\n }\r\n public override get tileSize(): number { return this._tileSize; }\r\n\r\n public override async initialize(): Promise<void> {\r\n const sessionOptions = GoogleMapsUtils.getSessionOptionsFromMapLayer(this._settings);\r\n this._sessionOptions = sessionOptions;\r\n this._sessionManager = await this.getSessionManager();\r\n this._activeSession = await this._sessionManager.createSession(sessionOptions);\r\n this._tileSize = this._activeSession.getTileSize();\r\n const isActivated = await this._decorator.activate(sessionOptions.mapType);\r\n if (!isActivated) {\r\n const msg = `Failed to activate decorator`;\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n }\r\n\r\n protected async getSessionManager(): Promise<GoogleMapsSessionManager> {\r\n if (this._sessionManager)\r\n return this._sessionManager;\r\n\r\n if (this._settings.accessKey?.value) {\r\n return new NativeGoogleMapsSessionManager(this._settings.accessKey.value);\r\n } else {\r\n const msg = `Missing GoogleMaps api key`;\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n }\r\n\r\n protected createCreateSessionOptions(settings: ImageMapLayerSettings): GoogleMapsCreateSessionOptions {\r\n const requestedProperties = settings.properties;\r\n if (requestedProperties === undefined) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const layerPropertyKeys = Object.keys(requestedProperties);\r\n if (!layerPropertyKeys.includes(\"mapType\") ||\r\n !layerPropertyKeys.includes(\"language\") ||\r\n !layerPropertyKeys.includes(\"region\")) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const properties = this._settings.properties;\r\n if (properties === undefined) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const createSessionOptions: GoogleMapsCreateSessionOptions = {\r\n mapType: requestedProperties.mapType as GoogleMapsCreateSessionOptions[\"mapType\"],\r\n region: properties.region as string,\r\n language: properties.language as string,\r\n };\r\n\r\n if (Array.isArray(properties.layerTypes) && properties.layerTypes.length > 0) {\r\n createSessionOptions.layerTypes = properties.layerTypes as GoogleMapsCreateSessionOptions[\"layerTypes\"];\r\n }\r\n\r\n if (properties.scale !== undefined) {\r\n createSessionOptions.scale = properties.scale as GoogleMapsCreateSessionOptions[\"scale\"];\r\n }\r\n\r\n if (properties.overlay !== undefined) {\r\n createSessionOptions.overlay = properties.overlay as boolean;\r\n }\r\n\r\n if (properties.apiOptions !== undefined) {\r\n createSessionOptions.apiOptions = properties.apiOptions as string[];\r\n }\r\n\r\n return createSessionOptions;\r\n }\r\n\r\n // not used, see loadTile\r\n public async constructUrl(_row: number, _column: number, _level: number): Promise<string> {\r\n return \"\";\r\n }\r\n\r\n public async fetchViewportInfo(rectangle: MapCartoRectangle, zoomLevel: number): Promise<ViewportInfo> {\r\n if (!this._activeSession) {\r\n Logger.logError(loggerCategory, `Session is not initialized`);\r\n throw new BentleyError(BentleyStatus.ERROR, \"Session is not initialized\");\r\n }\r\n\r\n const req = this._activeSession.getViewportInfoRequest(rectangle, zoomLevel);\r\n const request = new Request(req.url, {method: \"GET\"});\r\n if (req.authorization) {\r\n request.headers.set(\"Authorization\", req.authorization);\r\n }\r\n // Add the session token to the request\r\n const response = await fetch(request);\r\n if (!response.ok) {\r\n Logger.logError(loggerCategory, `Error while loading viewport info: ${response.statusText}`);\r\n throw new BentleyError(BentleyStatus.ERROR, `Error while loading viewport info: ${response.statusText}`);\r\n }\r\n return response.json() as Promise<ViewportInfo>;\r\n }\r\n\r\n private async fetchAttributions(tiles: Set<Tile>): Promise<string[]> {\r\n const zooms = new Set<number>();\r\n const matchingAttributions: string[] = [];\r\n\r\n // Viewport info requests must be made for a specific zoom level\r\n tiles.forEach((tile) => zooms.add(tile.depth));\r\n\r\n for (const zoom of zooms) {\r\n let cartoRect: MapCartoRectangle|undefined;\r\n for (const tile of tiles) {\r\n if (tile.depth === zoom && tile instanceof MapTile) {\r\n const extent = this.getEPSG4326Extent(tile.quadId.row, tile.quadId.column, tile.depth);\r\n const rect = MapCartoRectangle.fromDegrees(extent.longitudeLeft, extent.latitudeBottom, extent.longitudeRight, extent.latitudeTop)\r\n if (cartoRect)\r\n cartoRect.union(rect);\r\n else\r\n cartoRect = rect;\r\n }\r\n }\r\n if (cartoRect && this._activeSession) {\r\n try {\r\n const viewportInfo = await this.fetchViewportInfo(cartoRect, zoom);\r\n if (viewportInfo?.copyright) {\r\n matchingAttributions.push(viewportInfo.copyright);\r\n }\r\n } catch (error:any) {\r\n Logger.logError(loggerCategory, `Error while loading viewport info: ${error?.message??\"Unknown error\"}`);\r\n }\r\n }\r\n }\r\n\r\n return matchingAttributions;\r\n }\r\n private async logJsonError(tileResponse: Response) {\r\n try {\r\n const error = await tileResponse.json();\r\n Logger.logError(loggerCategory, `Error while loading tile: ${error?.message}`);\r\n } catch {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n }\r\n }\r\n\r\n public override async loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined> {\r\n const tilePos: QuadIdProps = {row, column, level: zoomLevel};\r\n if (this._hadUnrecoverableError)\r\n return undefined;\r\n\r\n if (this._activeSession === undefined || this._sessionOptions === undefined) {\r\n Logger.logError(loggerCategory, `Session manager is not initialized`);\r\n return undefined;\r\n }\r\n\r\n try {\r\n let tileRequest = this._activeSession.getTileRequest(tilePos);\r\n let tileResponse: Response = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);\r\n if (!tileResponse.ok) {\r\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\") && this._sessionManager) {\r\n try {\r\n // Session might have expired, lets try to refresh it\r\n this._activeSession = await this._sessionManager.createSession(this._sessionOptions);\r\n tileRequest = this._activeSession.getTileRequest(tilePos);\r\n tileResponse = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);\r\n if (!tileResponse.ok) {\r\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\")) {\r\n await this.logJsonError(tileResponse);\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n }\r\n this._hadUnrecoverableError = true; // Prevent from doing more invalid requests\r\n return undefined;\r\n }\r\n }\r\n catch {\r\n await this.logJsonError(tileResponse);\r\n }\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n return undefined;\r\n }\r\n }\r\n return await this.getImageFromTileResponse(tileResponse, zoomLevel);\r\n } catch (error: any) {\r\n if (error?.code === 401) {\r\n Logger.logError(loggerCategory, `Authorize to load tile: ${error.message}`);\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${error.message}`);\r\n }\r\n return undefined;\r\n }\r\n }\r\n\r\n public override decorate(context: DecorateContext): void {\r\n this._decorator.decorate(context);\r\n }\r\n\r\n private getSelectedTiles(vp: ScreenViewport) {\r\n return IModelApp.tileAdmin.getTilesForUser(vp)?.selected;\r\n }\r\n\r\n public override async addAttributions(cards: HTMLTableElement, vp: ScreenViewport): Promise<void> {\r\n const lines: string[] = [];\r\n const seen = new Set<string>();\r\n const tiles = this.getSelectedTiles(vp);\r\n if (tiles) {\r\n try {\r\n const attrList = await this.fetchAttributions(tiles);\r\n for (const attr of attrList) {\r\n attr.split(\",\").forEach((line) => {\r\n // The same info is often returned for multiple zoom levels.\r\n const trimmed = line.trim();\r\n if (trimmed.length > 0 && !seen.has(trimmed)) {\r\n seen.add(trimmed);\r\n lines.push(trimmed);\r\n }\r\n });\r\n }\r\n }\r\n catch (error: any) {\r\n Logger.logError(loggerCategory, `Error while loading attributions: ${error?.message??\"Unknown error\"}`);\r\n }\r\n }\r\n\r\n const iconSrc = document.createElement(\"img\");\r\n iconSrc.src = `${IModelApp.publicPath}images/GoogleMaps_Logo_Gray.svg`;\r\n iconSrc.style.padding = \"10px 10px 5px 10px\";\r\n\r\n cards.appendChild(IModelApp.makeLogoCard({\r\n iconSrc,\r\n heading: \"Google Maps\",\r\n noticeLines: lines\r\n }));\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"GoogleMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAA0E;AAE1E,wDAA+K;AAE/K,uFAAwF;AACxF,uEAAiE;AAEjE,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD;;;EAGE;AACF,MAAa,yBAA0B,SAAQ,uCAAuB;IAE5D,UAAU,CAAsB;IAChC,sBAAsB,GAAG,KAAK,CAAC;IAC/B,SAAS,GAAG,GAAG,CAAC;IAChB,eAAe,CAA4B;IAC3C,eAAe,CAA2C;IAC1D,cAAc,CAAqB;IAC3C,YAAY,QAA+B,EAAE,cAAyC;QACpF,KA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Y,CAAC;YACvC,OAAO;YACP,OAAO,EAAE,aAAa;YACtB,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC,CAAC;IACN,CAAC;CACF;AA3PD,8DA2PC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module MapLayersFormats\r\n */\r\n\r\nimport { BentleyError, BentleyStatus, Logger } from \"@itwin/core-bentley\";\r\nimport { ImageMapLayerSettings, ImageSource } from \"@itwin/core-common\";\r\nimport { DecorateContext, GoogleMapsDecorator, IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapTile, QuadIdProps, ScreenViewport, Tile } from \"@itwin/core-frontend\";\r\nimport { GoogleMapsCreateSessionOptions, GoogleMapsSession, GoogleMapsSessionManager, ViewportInfo } from \"./GoogleMapsSession.js\";\r\nimport { NativeGoogleMapsSessionManager } from \"../internal/NativeGoogleMapsSession.js\";\r\nimport { GoogleMapsUtils } from \"../internal/GoogleMapsUtils.js\";\r\n\r\nconst loggerCategory = \"MapLayersFormats.GoogleMaps\";\r\n\r\n/*\r\n* Google Maps imagery provider\r\n* @beta\r\n*/\r\nexport class GoogleMapsImageryProvider extends MapLayerImageryProvider {\r\n\r\n private _decorator: GoogleMapsDecorator;\r\n private _hadUnrecoverableError = false;\r\n private _tileSize = 256;\r\n private _sessionManager?: GoogleMapsSessionManager;\r\n private _sessionOptions: GoogleMapsCreateSessionOptions|undefined;\r\n private _activeSession?: GoogleMapsSession;\r\n constructor(settings: ImageMapLayerSettings, sessionManager?: GoogleMapsSessionManager) {\r\n super(settings, true);\r\n this._decorator = new GoogleMapsDecorator();\r\n this._sessionManager = sessionManager;\r\n }\r\n public override get tileSize(): number { return this._tileSize; }\r\n\r\n public override async initialize(): Promise<void> {\r\n const sessionOptions = GoogleMapsUtils.getSessionOptionsFromMapLayer(this._settings);\r\n this._sessionOptions = sessionOptions;\r\n this._sessionManager = await this.getSessionManager();\r\n this._activeSession = await this._sessionManager.createSession(sessionOptions);\r\n this._tileSize = this._activeSession.getTileSize();\r\n const isActivated = await this._decorator.activate(sessionOptions.mapType);\r\n if (!isActivated) {\r\n const msg = `Failed to activate decorator`;\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n }\r\n\r\n protected async getSessionManager(): Promise<GoogleMapsSessionManager> {\r\n if (this._sessionManager)\r\n return this._sessionManager;\r\n\r\n if (this._settings.accessKey?.value) {\r\n return new NativeGoogleMapsSessionManager(this._settings.accessKey.value);\r\n } else {\r\n const msg = `Missing GoogleMaps api key`;\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n }\r\n\r\n protected createCreateSessionOptions(settings: ImageMapLayerSettings): GoogleMapsCreateSessionOptions {\r\n const requestedProperties = settings.properties;\r\n if (requestedProperties === undefined) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const layerPropertyKeys = Object.keys(requestedProperties);\r\n if (!layerPropertyKeys.includes(\"mapType\") ||\r\n !layerPropertyKeys.includes(\"language\") ||\r\n !layerPropertyKeys.includes(\"region\")) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const properties = this._settings.properties;\r\n if (properties === undefined) {\r\n const msg = \"Missing session options\";\r\n Logger.logError(loggerCategory, msg);\r\n throw new BentleyError(BentleyStatus.ERROR, msg);\r\n }\r\n\r\n const createSessionOptions: GoogleMapsCreateSessionOptions = {\r\n mapType: requestedProperties.mapType as GoogleMapsCreateSessionOptions[\"mapType\"],\r\n region: properties.region as string,\r\n language: properties.language as string,\r\n };\r\n\r\n if (Array.isArray(properties.layerTypes) && properties.layerTypes.length > 0) {\r\n createSessionOptions.layerTypes = properties.layerTypes as GoogleMapsCreateSessionOptions[\"layerTypes\"];\r\n }\r\n\r\n if (properties.scale !== undefined) {\r\n createSessionOptions.scale = properties.scale as GoogleMapsCreateSessionOptions[\"scale\"];\r\n }\r\n\r\n if (properties.overlay !== undefined) {\r\n createSessionOptions.overlay = properties.overlay as boolean;\r\n }\r\n\r\n if (properties.apiOptions !== undefined) {\r\n createSessionOptions.apiOptions = properties.apiOptions as string[];\r\n }\r\n\r\n return createSessionOptions;\r\n }\r\n\r\n // not used, see loadTile\r\n public async constructUrl(_row: number, _column: number, _level: number): Promise<string> {\r\n return \"\";\r\n }\r\n\r\n public async fetchViewportInfo(rectangle: MapCartoRectangle, zoomLevel: number): Promise<ViewportInfo> {\r\n if (!this._activeSession) {\r\n Logger.logError(loggerCategory, `Session is not initialized`);\r\n throw new BentleyError(BentleyStatus.ERROR, \"Session is not initialized\");\r\n }\r\n\r\n const req = this._activeSession.getViewportInfoRequest(rectangle, zoomLevel);\r\n const request = new Request(req.url, {method: \"GET\"});\r\n if (req.authorization) {\r\n request.headers.set(\"Authorization\", req.authorization);\r\n }\r\n // Add the session token to the request\r\n const response = await fetch(request);\r\n if (!response.ok) {\r\n Logger.logError(loggerCategory, `Error while loading viewport info: ${response.statusText}`);\r\n throw new BentleyError(BentleyStatus.ERROR, `Error while loading viewport info: ${response.statusText}`);\r\n }\r\n return response.json() as Promise<ViewportInfo>;\r\n }\r\n\r\n private async fetchAttributions(tiles: Set<Tile>): Promise<string[]> {\r\n const zooms = new Set<number>();\r\n const matchingAttributions: string[] = [];\r\n\r\n // Viewport info requests must be made for a specific zoom level\r\n tiles.forEach((tile) => zooms.add(tile.depth));\r\n\r\n for (const zoom of zooms) {\r\n let cartoRect: MapCartoRectangle|undefined;\r\n for (const tile of tiles) {\r\n if (tile.depth === zoom && tile instanceof MapTile) {\r\n const extent = this.getEPSG4326Extent(tile.quadId.row, tile.quadId.column, tile.depth);\r\n const rect = MapCartoRectangle.fromDegrees(extent.longitudeLeft, extent.latitudeBottom, extent.longitudeRight, extent.latitudeTop)\r\n if (cartoRect)\r\n cartoRect.union(rect);\r\n else\r\n cartoRect = rect;\r\n }\r\n }\r\n if (cartoRect && this._activeSession) {\r\n try {\r\n const viewportInfo = await this.fetchViewportInfo(cartoRect, zoom);\r\n if (viewportInfo?.copyright) {\r\n matchingAttributions.push(viewportInfo.copyright);\r\n }\r\n } catch (error:any) {\r\n Logger.logError(loggerCategory, `Error while loading viewport info: ${error?.message??\"Unknown error\"}`);\r\n }\r\n }\r\n }\r\n\r\n return matchingAttributions;\r\n }\r\n private async logJsonError(tileResponse: Response) {\r\n try {\r\n const error = await tileResponse.json();\r\n Logger.logError(loggerCategory, `Error while loading tile: ${error?.message}`);\r\n } catch {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n }\r\n }\r\n\r\n public override async loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined> {\r\n const tilePos: QuadIdProps = {row, column, level: zoomLevel};\r\n if (this._hadUnrecoverableError)\r\n return undefined;\r\n\r\n if (this._activeSession === undefined || this._sessionOptions === undefined) {\r\n Logger.logError(loggerCategory, `Session manager is not initialized`);\r\n return undefined;\r\n }\r\n\r\n try {\r\n let tileRequest = this._activeSession.getTileRequest(tilePos);\r\n let tileResponse: Response = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);\r\n if (!tileResponse.ok) {\r\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\") && this._sessionManager) {\r\n try {\r\n // Session might have expired, lets try to refresh it\r\n this._activeSession = await this._sessionManager.createSession(this._sessionOptions);\r\n tileRequest = this._activeSession.getTileRequest(tilePos);\r\n tileResponse = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);\r\n if (!tileResponse.ok) {\r\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\")) {\r\n await this.logJsonError(tileResponse);\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n }\r\n // A response managed by the fetch handler is not classified here: the handler reports failures\r\n // by throwing MapLayerAuthenticationFailedError, and must not have the layer given up on.\r\n if (!this.isManagedByHandler(tileResponse))\r\n this._hadUnrecoverableError = true; // Prevent from doing more invalid requests\r\n return undefined;\r\n }\r\n }\r\n catch {\r\n await this.logJsonError(tileResponse);\r\n }\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\r\n return undefined;\r\n }\r\n }\r\n return await this.getImageFromTileResponse(tileResponse, zoomLevel);\r\n } catch (error: any) {\r\n if (error?.code === 401) {\r\n Logger.logError(loggerCategory, `Authorize to load tile: ${error.message}`);\r\n } else {\r\n Logger.logError(loggerCategory, `Error while loading tile: ${error.message}`);\r\n }\r\n return undefined;\r\n }\r\n }\r\n\r\n public override decorate(context: DecorateContext): void {\r\n this._decorator.decorate(context);\r\n }\r\n\r\n private getSelectedTiles(vp: ScreenViewport) {\r\n return IModelApp.tileAdmin.getTilesForUser(vp)?.selected;\r\n }\r\n\r\n public override async addAttributions(cards: HTMLTableElement, vp: ScreenViewport): Promise<void> {\r\n const lines: string[] = [];\r\n const seen = new Set<string>();\r\n const tiles = this.getSelectedTiles(vp);\r\n if (tiles) {\r\n try {\r\n const attrList = await this.fetchAttributions(tiles);\r\n for (const attr of attrList) {\r\n attr.split(\",\").forEach((line) => {\r\n // The same info is often returned for multiple zoom levels.\r\n const trimmed = line.trim();\r\n if (trimmed.length > 0 && !seen.has(trimmed)) {\r\n seen.add(trimmed);\r\n lines.push(trimmed);\r\n }\r\n });\r\n }\r\n }\r\n catch (error: any) {\r\n Logger.logError(loggerCategory, `Error while loading attributions: ${error?.message??\"Unknown error\"}`);\r\n }\r\n }\r\n\r\n const iconSrc = document.createElement(\"img\");\r\n iconSrc.src = `${IModelApp.publicPath}images/GoogleMaps_Logo_Gray.svg`;\r\n iconSrc.style.padding = \"10px 10px 5px 10px\";\r\n\r\n cards.appendChild(IModelApp.makeLogoCard({\r\n iconSrc,\r\n heading: \"Google Maps\",\r\n noticeLines: lines\r\n }));\r\n }\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"OgcApiFeaturesFormat.d.ts","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesFormat.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAoB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAqB,qBAAqB,EAAa,uBAAuB,EAAwB,wBAAwB,EAAyB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/M,gBAAgB;AAChB,qBAAa,4BAA6B,SAAQ,qBAAqB;IACrE,OAAuB,QAAQ,SAAoB;WAC5B,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,uBAAuB,GAAG,SAAS;WAErF,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAiInG"}
1
+ {"version":3,"file":"OgcApiFeaturesFormat.d.ts","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesFormat.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAoB,MAAM,oBAAoB,CAAC;AAC7E,OAAO,EAAsE,qBAAqB,EAAqE,uBAAuB,EAAwB,wBAAwB,EAAyB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAGxT,gBAAgB;AAChB,qBAAa,4BAA6B,SAAQ,qBAAqB;IACrE,OAAuB,QAAQ,SAAoB;WAC5B,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,uBAAuB,GAAG,SAAS;WAErF,QAAQ,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,wBAAwB,CAAC;CAmJnG"}
@@ -22,10 +22,12 @@ class OgcApiFeaturesMapLayerFormat extends core_frontend_1.ImageryMapLayerFormat
22
22
  headers,
23
23
  };
24
24
  // Classify HTTP failures before parsing JSON, using the final response URL to enforce origin trust after redirects.
25
- const classifyResponseFailure = (httpResponse, requestedUrl) => {
25
+ const classifyResponseFailure = async ({ response: httpResponse, managedByHandler }, requestedUrl) => {
26
26
  if (httpResponse.ok)
27
27
  return undefined;
28
- if (httpResponse.status === 401 || httpResponse.status === 403) {
28
+ // A handler-managed response gets none of the legacy origin/authentication classification: an
29
+ // authentication failure would have been thrown as MapLayerAuthenticationFailedError.
30
+ if (!managedByHandler && (httpResponse.status === 401 || httpResponse.status === 403)) {
29
31
  const challengedUrl = httpResponse.url || requestedUrl;
30
32
  if (!core_frontend_1.IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(challengedUrl, source.url)) {
31
33
  let blockedOrigin;
@@ -39,15 +41,28 @@ class OgcApiFeaturesMapLayerFormat extends core_frontend_1.ImageryMapLayerFormat
39
41
  }
40
42
  return { status: core_frontend_1.MapLayerSourceStatus.InvalidUrl };
41
43
  };
42
- let url = (0, core_frontend_1.appendQueryParams)(source.url, source.savedQueryParams);
43
- url = (0, core_frontend_1.appendQueryParams)(url, source.unsavedQueryParams);
44
+ const url = (0, core_frontend_1.appendQueryParams)(source.url, source.collectQueryParams());
44
45
  const allowLandingCredentials = core_frontend_1.IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(url, source.url);
45
46
  if (headers && allowLandingCredentials)
46
47
  core_frontend_1.IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(url, source.url);
47
- let response = await fetch(url, allowLandingCredentials ? opts : { method: "GET" });
48
- const landingFailure = classifyResponseFailure(response, url);
48
+ // Routes each validation request through the registered fetch handler (if any); a
49
+ // MapLayerAuthenticationFailedError thrown by the handler is converted to RequireAuth below.
50
+ const doRequest = async (requestUrl, baseOpts) => {
51
+ return (0, core_frontend_1.fetchMapLayerRequest)({
52
+ url: requestUrl,
53
+ formatId: source.formatId,
54
+ layerUrl: source.url,
55
+ headers: new Headers(baseOpts.headers),
56
+ send: async (request, credentialed) =>
57
+ // Sends the handler modified may carry injected secrets: same redirect policy as credentialed ones.
58
+ fetch(request.url, { ...baseOpts, headers: request.headers, redirect: credentialed ? (0, core_frontend_1.credentialedFetchRedirect)() : baseOpts.redirect }),
59
+ });
60
+ };
61
+ let result = await doRequest(url, allowLandingCredentials ? opts : { method: "GET" });
62
+ const landingFailure = await classifyResponseFailure(result, url);
49
63
  if (landingFailure)
50
64
  return landingFailure;
65
+ let response = result.response;
51
66
  let json = await response.json();
52
67
  if (!json) {
53
68
  return { status };
@@ -97,18 +112,17 @@ class OgcApiFeaturesMapLayerFormat extends core_frontend_1.ImageryMapLayerFormat
97
112
  // Landing-page links are allowed to be relative, so resolve them against the URL the landing document
98
113
  // was actually served from (which may differ from the requested one if the request was redirected)
99
114
  // before appending query parameters or evaluating trust.
100
- let collectionsUrl = new URL(collectionsLink.href, response.url || url).toString();
101
- collectionsUrl = (0, core_frontend_1.appendQueryParams)(collectionsUrl, source.savedQueryParams);
102
- collectionsUrl = (0, core_frontend_1.appendQueryParams)(collectionsUrl, source.unsavedQueryParams);
115
+ const collectionsUrl = (0, core_frontend_1.appendQueryParams)(new URL(collectionsLink.href, response.url || url).toString(), source.collectQueryParams());
103
116
  // The collections link is advertised by the server-controlled landing document, so the trust
104
117
  // decision is applied to it independently of the source URL.
105
118
  const allowCreds = core_frontend_1.IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(collectionsUrl, source.url);
106
119
  if (headers && allowCreds)
107
120
  core_frontend_1.IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(collectionsUrl, source.url);
108
- response = await fetch(collectionsUrl, allowCreds ? opts : { method: "GET" });
109
- const collectionsFailure = classifyResponseFailure(response, collectionsUrl);
121
+ result = await doRequest(collectionsUrl, allowCreds ? opts : { method: "GET" });
122
+ const collectionsFailure = await classifyResponseFailure(result, collectionsUrl);
110
123
  if (collectionsFailure)
111
124
  return collectionsFailure;
125
+ response = result.response;
112
126
  json = await response.json();
113
127
  if (Array.isArray(json.collections)) {
114
128
  subLayers = createCollectionsList(json);
@@ -118,6 +132,9 @@ class OgcApiFeaturesMapLayerFormat extends core_frontend_1.ImageryMapLayerFormat
118
132
  return { status, subLayers };
119
133
  }
120
134
  catch (err) {
135
+ // The fetch handler is the authentication authority for the requests it manages.
136
+ if (err instanceof core_frontend_1.MapLayerAuthenticationFailedError)
137
+ return { status: core_frontend_1.MapLayerSourceStatus.RequireAuth };
121
138
  status = core_frontend_1.MapLayerSourceStatus.InvalidUrl;
122
139
  if (err?.status === 401) {
123
140
  status = ((userName && password) ? core_frontend_1.MapLayerSourceStatus.InvalidCredentials : core_frontend_1.MapLayerSourceStatus.RequireAuth);
@@ -1 +1 @@
1
- {"version":3,"file":"OgcApiFeaturesFormat.js","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesFormat.ts"],"names":[],"mappings":";;;AAKA,wDAA+M;AAC/M,2EAAqE;AAErE,gBAAgB;AAChB,MAAa,4BAA6B,SAAQ,qCAAqB;IAC9D,MAAM,CAAU,QAAQ,GAAG,gBAAgB,CAAC;IAC5C,MAAM,CAAU,qBAAqB,CAAC,QAA+B,IAAyC,OAAO,IAAI,kDAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5J,MAAM,CAAU,KAAK,CAAC,QAAQ,CAAC,IAAwB;QAE5D,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC;QACtB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QACtC,IAAI,MAAM,GAAG,oCAAoB,CAAC,UAAU,CAAC;QAC7C,IAAI,CAAC;YAEH,IAAI,OAA4B,CAAC;YACjC,IAAI,QAAQ,IAAI,QAAQ,EAAE,CAAC;gBACzB,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;gBACxB,IAAA,qCAAqB,EAAC,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,IAAI,GAAgB;gBACxB,MAAM,EAAE,KAAK;gBACb,OAAO;aACR,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,CAAC,2BAA2B,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;gBAC5G,IAAI,OAAO,IAAI,UAAU;oBACvB,yBAAS,CAAC,sBAAsB,CAAC,qBAAqB,CAAC,cAAc,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;gBAErF,QAAQ,GAAG,MAAM,KAAK,CAAC,cAAc,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;gBAC9E,MAAM,kBAAkB,GAAG,uBAAuB,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;gBAC7E,IAAI,kBAAkB;oBACpB,OAAO,kBAAkB,CAAC;gBAE5B,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;oBACpC,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;oBACxC,MAAM,GAAG,oCAAoB,CAAC,KAAK,CAAC;gBACtC,CAAC;YAEH,CAAC;YAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAE/B,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,MAAM,GAAG,oCAAoB,CAAC,UAAU,CAAC;YACzC,IAAI,GAAG,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,oCAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC,oCAAoB,CAAC,WAAW,CAAC,CAAC;YACjH,CAAC;YACD,OAAO,EAAE,MAAM,EAAC,CAAC;QACnB,CAAC;IACH,CAAC;;AApIH,oEAqIC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { ImageMapLayerSettings, MapSubLayerProps } from \"@itwin/core-common\";\r\nimport { appendQueryParams, ImageryMapLayerFormat, IModelApp, MapLayerImageryProvider, MapLayerSourceStatus, MapLayerSourceValidation, setBasicAuthorization, ValidateSourceArgs } from \"@itwin/core-frontend\";\r\nimport { OgcApiFeaturesProvider } from \"./OgcApiFeaturesProvider.js\";\r\n\r\n/** @internal */\r\nexport class OgcApiFeaturesMapLayerFormat extends ImageryMapLayerFormat {\r\n public static override formatId = \"OgcApiFeatures\";\r\n public static override createImageryProvider(settings: ImageMapLayerSettings): MapLayerImageryProvider | undefined { return new OgcApiFeaturesProvider(settings); }\r\n\r\n public static override async validate(args: ValidateSourceArgs): Promise<MapLayerSourceValidation> {\r\n\r\n const {source} = args;\r\n const { userName, password } = source;\r\n let status = MapLayerSourceStatus.InvalidUrl;\r\n try {\r\n\r\n let headers: Headers | undefined;\r\n if (userName && password) {\r\n headers = new Headers();\r\n setBasicAuthorization(headers, userName, password);\r\n }\r\n const opts: RequestInit = {\r\n method: \"GET\",\r\n headers,\r\n };\r\n\r\n // Classify HTTP failures before parsing JSON, using the final response URL to enforce origin trust after redirects.\r\n const classifyResponseFailure = (httpResponse: Response, requestedUrl: string): MapLayerSourceValidation | undefined => {\r\n if (httpResponse.ok)\r\n return undefined;\r\n\r\n if (httpResponse.status === 401 || httpResponse.status === 403) {\r\n const challengedUrl = httpResponse.url || requestedUrl;\r\n if (!IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(challengedUrl, source.url)) {\r\n let blockedOrigin: string | undefined;\r\n try { blockedOrigin = new URL(challengedUrl).origin; } catch { /* non-hierarchical URL */ }\r\n return { status: MapLayerSourceStatus.UntrustedOrigin, blockedOrigin };\r\n }\r\n\r\n return { status: (userName && password) ? MapLayerSourceStatus.InvalidCredentials : MapLayerSourceStatus.RequireAuth };\r\n }\r\n\r\n return { status: MapLayerSourceStatus.InvalidUrl };\r\n };\r\n\r\n let url = appendQueryParams(source.url, source.savedQueryParams);\r\n url = appendQueryParams(url, source.unsavedQueryParams);\r\n const allowLandingCredentials = IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(url, source.url);\r\n if (headers && allowLandingCredentials)\r\n IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(url, source.url);\r\n\r\n let response = await fetch(url, allowLandingCredentials ? opts : { method: \"GET\" });\r\n const landingFailure = classifyResponseFailure(response, url);\r\n if (landingFailure)\r\n return landingFailure;\r\n\r\n let json = await response.json();\r\n if (!json) {\r\n return { status };\r\n }\r\n\r\n const createCollectionsList = (data: any) => {\r\n let array: MapSubLayerProps[] | undefined;\r\n for (const collection of data.collections) {\r\n if (collection.itemType === \"feature\") {\r\n const subLayerProps = {\r\n id: collection.id,\r\n name: collection.id,\r\n title: collection.title,\r\n visible: true,\r\n parent: undefined,\r\n children: undefined,\r\n };\r\n if (array)\r\n array.push(subLayerProps);\r\n else\r\n array = [subLayerProps];\r\n }\r\n }\r\n return array;\r\n };\r\n\r\n let subLayers: MapSubLayerProps[] | undefined;\r\n if (Array.isArray(json.collections)) {\r\n subLayers = createCollectionsList(json);\r\n status = MapLayerSourceStatus.Valid;\r\n } else if (json.itemType === \"feature\" || json.type === \"FeatureCollection\") {\r\n // We expect one of the following URL:\r\n // http://server/collections/<collectionName>\r\n // http://server/collections/<collectionName>/items\r\n subLayers = [{\r\n id: json.id,\r\n name: json.id,\r\n title: json.title,\r\n visible: true,\r\n parent: undefined,\r\n children: undefined,\r\n }];\r\n status = MapLayerSourceStatus.Valid;\r\n } else if (Array.isArray(json.links)) {\r\n // This might be the main landing page\r\n const collectionsLink = json.links.find((link: any)=> link.rel.includes(\"data\") && link.type === \"application/json\");\r\n // Landing-page links are allowed to be relative, so resolve them against the URL the landing document\r\n // was actually served from (which may differ from the requested one if the request was redirected)\r\n // before appending query parameters or evaluating trust.\r\n let collectionsUrl = new URL(collectionsLink.href, response.url || url).toString();\r\n collectionsUrl = appendQueryParams(collectionsUrl, source.savedQueryParams);\r\n collectionsUrl = appendQueryParams(collectionsUrl, source.unsavedQueryParams);\r\n\r\n // The collections link is advertised by the server-controlled landing document, so the trust\r\n // decision is applied to it independently of the source URL.\r\n const allowCreds = IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(collectionsUrl, source.url);\r\n if (headers && allowCreds)\r\n IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(collectionsUrl, source.url);\r\n\r\n response = await fetch(collectionsUrl, allowCreds ? opts : { method: \"GET\" });\r\n const collectionsFailure = classifyResponseFailure(response, collectionsUrl);\r\n if (collectionsFailure)\r\n return collectionsFailure;\r\n\r\n json = await response.json();\r\n if (Array.isArray(json.collections)) {\r\n subLayers = createCollectionsList(json);\r\n status = MapLayerSourceStatus.Valid;\r\n }\r\n\r\n }\r\n\r\n return { status, subLayers };\r\n\r\n } catch (err: any) {\r\n status = MapLayerSourceStatus.InvalidUrl;\r\n if (err?.status === 401) {\r\n status = ((userName && password) ? MapLayerSourceStatus.InvalidCredentials : MapLayerSourceStatus.RequireAuth);\r\n }\r\n return { status};\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"OgcApiFeaturesFormat.js","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesFormat.ts"],"names":[],"mappings":";;;AAKA,wDAAwT;AACxT,2EAAqE;AAErE,gBAAgB;AAChB,MAAa,4BAA6B,SAAQ,qCAAqB;IAC9D,MAAM,CAAU,QAAQ,GAAG,gBAAgB,CAAC;IAC5C,MAAM,CAAU,qBAAqB,CAAC,QAA+B,IAAyC,OAAO,IAAI,kDAAsB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAE5J,MAAM,CAAU,KAAK,CAAC,QAAQ,CAAC,IAAwB;QAE5D,MAAM,EAAC,MAAM,EAAC,GAAG,IAAI,CAAC;QACtB,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;QACtC,IAAI,MA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AAE,CAAC,CAAC;gBAChF,MAAM,kBAAkB,GAAG,MAAM,uBAAuB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;gBACjF,IAAI,kBAAkB;oBACpB,OAAO,kBAAkB,CAAC;gBAE5B,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC;gBAC3B,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;gBAC7B,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;oBACpC,SAAS,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;oBACxC,MAAM,GAAG,oCAAoB,CAAC,KAAK,CAAC;gBACtC,CAAC;YAEH,CAAC;YAED,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;QAE/B,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,iFAAiF;YACjF,IAAI,GAAG,YAAY,iDAAiC;gBAClD,OAAO,EAAE,MAAM,EAAE,oCAAoB,CAAC,WAAW,EAAE,CAAC;YACtD,MAAM,GAAG,oCAAoB,CAAC,UAAU,CAAC;YACzC,IAAI,GAAG,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,oCAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC,oCAAoB,CAAC,WAAW,CAAC,CAAC;YACjH,CAAC;YACD,OAAO,EAAE,MAAM,EAAC,CAAC;QACnB,CAAC;IACH,CAAC;;AAtJH,oEAuJC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { ImageMapLayerSettings, MapSubLayerProps } from \"@itwin/core-common\";\r\nimport { appendQueryParams, credentialedFetchRedirect, fetchMapLayerRequest, ImageryMapLayerFormat, IModelApp, MapLayerAuthenticationFailedError, MapLayerFetchResult, MapLayerImageryProvider, MapLayerSourceStatus, MapLayerSourceValidation, setBasicAuthorization, ValidateSourceArgs } from \"@itwin/core-frontend\";\r\nimport { OgcApiFeaturesProvider } from \"./OgcApiFeaturesProvider.js\";\r\n\r\n/** @internal */\r\nexport class OgcApiFeaturesMapLayerFormat extends ImageryMapLayerFormat {\r\n public static override formatId = \"OgcApiFeatures\";\r\n public static override createImageryProvider(settings: ImageMapLayerSettings): MapLayerImageryProvider | undefined { return new OgcApiFeaturesProvider(settings); }\r\n\r\n public static override async validate(args: ValidateSourceArgs): Promise<MapLayerSourceValidation> {\r\n\r\n const {source} = args;\r\n const { userName, password } = source;\r\n let status = MapLayerSourceStatus.InvalidUrl;\r\n try {\r\n\r\n let headers: Headers | undefined;\r\n if (userName && password) {\r\n headers = new Headers();\r\n setBasicAuthorization(headers, userName, password);\r\n }\r\n const opts: RequestInit = {\r\n method: \"GET\",\r\n headers,\r\n };\r\n\r\n // Classify HTTP failures before parsing JSON, using the final response URL to enforce origin trust after redirects.\r\n const classifyResponseFailure = async ({ response: httpResponse, managedByHandler }: MapLayerFetchResult, requestedUrl: string): Promise<MapLayerSourceValidation | undefined> => {\r\n if (httpResponse.ok)\r\n return undefined;\r\n\r\n // A handler-managed response gets none of the legacy origin/authentication classification: an\r\n // authentication failure would have been thrown as MapLayerAuthenticationFailedError.\r\n if (!managedByHandler && (httpResponse.status === 401 || httpResponse.status === 403)) {\r\n const challengedUrl = httpResponse.url || requestedUrl;\r\n if (!IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(challengedUrl, source.url)) {\r\n let blockedOrigin: string | undefined;\r\n try { blockedOrigin = new URL(challengedUrl).origin; } catch { /* non-hierarchical URL */ }\r\n return { status: MapLayerSourceStatus.UntrustedOrigin, blockedOrigin };\r\n }\r\n\r\n return { status: (userName && password) ? MapLayerSourceStatus.InvalidCredentials : MapLayerSourceStatus.RequireAuth };\r\n }\r\n\r\n return { status: MapLayerSourceStatus.InvalidUrl };\r\n };\r\n\r\n const url = appendQueryParams(source.url, source.collectQueryParams());\r\n const allowLandingCredentials = IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(url, source.url);\r\n if (headers && allowLandingCredentials)\r\n IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(url, source.url);\r\n\r\n // Routes each validation request through the registered fetch handler (if any); a\r\n // MapLayerAuthenticationFailedError thrown by the handler is converted to RequireAuth below.\r\n const doRequest = async (requestUrl: string, baseOpts: RequestInit): Promise<MapLayerFetchResult> => {\r\n return fetchMapLayerRequest({\r\n url: requestUrl,\r\n formatId: source.formatId,\r\n layerUrl: source.url,\r\n headers: new Headers(baseOpts.headers),\r\n send: async (request, credentialed) =>\r\n // Sends the handler modified may carry injected secrets: same redirect policy as credentialed ones.\r\n fetch(request.url, { ...baseOpts, headers: request.headers, redirect: credentialed ? credentialedFetchRedirect() : baseOpts.redirect }),\r\n });\r\n };\r\n\r\n let result = await doRequest(url, allowLandingCredentials ? opts : { method: \"GET\" });\r\n const landingFailure = await classifyResponseFailure(result, url);\r\n if (landingFailure)\r\n return landingFailure;\r\n\r\n let response = result.response;\r\n let json = await response.json();\r\n if (!json) {\r\n return { status };\r\n }\r\n\r\n const createCollectionsList = (data: any) => {\r\n let array: MapSubLayerProps[] | undefined;\r\n for (const collection of data.collections) {\r\n if (collection.itemType === \"feature\") {\r\n const subLayerProps = {\r\n id: collection.id,\r\n name: collection.id,\r\n title: collection.title,\r\n visible: true,\r\n parent: undefined,\r\n children: undefined,\r\n };\r\n if (array)\r\n array.push(subLayerProps);\r\n else\r\n array = [subLayerProps];\r\n }\r\n }\r\n return array;\r\n };\r\n\r\n let subLayers: MapSubLayerProps[] | undefined;\r\n if (Array.isArray(json.collections)) {\r\n subLayers = createCollectionsList(json);\r\n status = MapLayerSourceStatus.Valid;\r\n } else if (json.itemType === \"feature\" || json.type === \"FeatureCollection\") {\r\n // We expect one of the following URL:\r\n // http://server/collections/<collectionName>\r\n // http://server/collections/<collectionName>/items\r\n subLayers = [{\r\n id: json.id,\r\n name: json.id,\r\n title: json.title,\r\n visible: true,\r\n parent: undefined,\r\n children: undefined,\r\n }];\r\n status = MapLayerSourceStatus.Valid;\r\n } else if (Array.isArray(json.links)) {\r\n // This might be the main landing page\r\n const collectionsLink = json.links.find((link: any)=> link.rel.includes(\"data\") && link.type === \"application/json\");\r\n // Landing-page links are allowed to be relative, so resolve them against the URL the landing document\r\n // was actually served from (which may differ from the requested one if the request was redirected)\r\n // before appending query parameters or evaluating trust.\r\n const collectionsUrl = appendQueryParams(new URL(collectionsLink.href, response.url || url).toString(), source.collectQueryParams());\r\n\r\n // The collections link is advertised by the server-controlled landing document, so the trust\r\n // decision is applied to it independently of the source URL.\r\n const allowCreds = IModelApp.mapLayerFormatRegistry.isCredentialsSharingAllowed(collectionsUrl, source.url);\r\n if (headers && allowCreds)\r\n IModelApp.mapLayerFormatRegistry.logUntrustedOriginUse(collectionsUrl, source.url);\r\n\r\n result = await doRequest(collectionsUrl, allowCreds ? opts : { method: \"GET\" });\r\n const collectionsFailure = await classifyResponseFailure(result, collectionsUrl);\r\n if (collectionsFailure)\r\n return collectionsFailure;\r\n\r\n response = result.response;\r\n json = await response.json();\r\n if (Array.isArray(json.collections)) {\r\n subLayers = createCollectionsList(json);\r\n status = MapLayerSourceStatus.Valid;\r\n }\r\n\r\n }\r\n\r\n return { status, subLayers };\r\n\r\n } catch (err: any) {\r\n // The fetch handler is the authentication authority for the requests it manages.\r\n if (err instanceof MapLayerAuthenticationFailedError)\r\n return { status: MapLayerSourceStatus.RequireAuth };\r\n status = MapLayerSourceStatus.InvalidUrl;\r\n if (err?.status === 401) {\r\n status = ((userName && password) ? MapLayerSourceStatus.InvalidCredentials : MapLayerSourceStatus.RequireAuth);\r\n }\r\n return { status};\r\n }\r\n }\r\n}\r\n"]}
@@ -39,6 +39,7 @@ export declare class OgcApiFeaturesProvider extends MapLayerImageryProvider {
39
39
  get minimumZoomLevel(): number;
40
40
  get staticMode(): boolean;
41
41
  initialize(): Promise<void>;
42
+ private initializeService;
42
43
  private fetchMetadata;
43
44
  private fetchAllItems;
44
45
  private fetchItems;
@@ -1 +1 @@
1
- {"version":3,"file":"OgcApiFeaturesProvider.d.ts","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesProvider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,YAAY,EAAY,qBAAqB,EAAE,WAAW,EAA8C,MAAM,oBAAoB,CAAC;AAC5I,OAAO,EAA2B,SAAS,EAAE,kBAAkB,EAAqB,qBAAqB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,EAAe,MAAM,sBAAsB,CAAC;AAI3M,OAAO,EAAqF,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAGlJ,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAM9D;;EAEE;AACF,qBAAa,mBAAoB,YAAW,uBAAuB;IAEjE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAQtC;IACF,OAAO,CAAC,WAAW,CAAU;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAKtC;IACF,OAAO,CAAC,WAAW,CAAU;IAE7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAKtC;IACF,OAAO,CAAC,WAAW,CAA0D;gBAE1D,WAAW,CAAC,EAAE,cAAc;IA4BlC,UAAU;IAKhB,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,UAAU;CAUtD;AACD,gBAAgB;AAChB,qBAAa,sBAAuB,SAAQ,uBAAuB;IAGjE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IAGxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAM;IACvC,OAAO,CAAC,QAAQ,CAA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E,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,kBAAkB,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC;CAyC1M"}
@@ -112,6 +112,24 @@ class OgcApiFeaturesProvider extends core_frontend_1.MapLayerImageryProvider {
112
112
  get minimumZoomLevel() { return this.staticMode ? super.minimumZoomLevel : this._tiledModeMinLod; }
113
113
  get staticMode() { return !!(this._spatialIdx && this._staticData && !this._forceTileMode); }
114
114
  async initialize() {
115
+ try {
116
+ await this.initializeService();
117
+ }
118
+ catch (error) {
119
+ // Keep the provider (and its tile tree) alive so the application can offer re-authentication.
120
+ if (error instanceof core_frontend_1.MapLayerAuthenticationFailedError) {
121
+ // The failure may occur after the items URL was recorded: discard partial state so no request or
122
+ // rendering happens before re-initialization.
123
+ this._itemsUrl = "";
124
+ this._staticData = undefined;
125
+ this._spatialIdx = undefined;
126
+ this.setStatus(core_frontend_1.MapLayerImageryProviderStatus.RequireAuth);
127
+ }
128
+ else
129
+ throw error;
130
+ }
131
+ }
132
+ async initializeService() {
115
133
  this._collectionUrl = this._settings.url;
116
134
  let layerId;
117
135
  // OGC Feature service request can only serve data for a single feature
@@ -387,6 +405,8 @@ class OgcApiFeaturesProvider extends core_frontend_1.MapLayerImageryProvider {
387
405
  }
388
406
  else {
389
407
  // Tiled data mode
408
+ if (!this._itemsUrl)
409
+ return undefined; // initialization did not complete (e.g. awaiting re-authentication)
390
410
  const extent4326Str = this.getEPSG4326TileExtentString(row, column, zoomLevel, false);
391
411
  const urlObj = new URL(this._itemsUrl);
392
412
  urlObj.searchParams.append("bbox", `${extent4326Str}`);
@@ -453,6 +473,8 @@ class OgcApiFeaturesProvider extends core_frontend_1.MapLayerImageryProvider {
453
473
  return new core_common_1.ImageSource((0, core_bentley_1.base64StringToUint8Array)(base64Png), format);
454
474
  }
455
475
  async getFeatureInfo(featureInfos, quadId, carto, _tree, hit, options) {
476
+ if (!this._itemsUrl)
477
+ return; // initialization did not complete (e.g. awaiting re-authentication)
456
478
  const tileExtent = this.getEPSG4326Extent(quadId.row, quadId.column, quadId.level);
457
479
  const tilePixelSizeX = (tileExtent.longitudeRight - tileExtent.longitudeLeft) / this.tileSize;
458
480
  const tilePixelSizeY = (tileExtent.latitudeTop - tileExtent.latitudeBottom) / this.tileSize;