@itwin/map-layers-formats 5.1.0-dev.9 → 5.1.1

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 (125) hide show
  1. package/CHANGELOG.md +80 -1
  2. package/lib/cjs/ArcGisFeature/ArcGisFeatureFormat.js.map +1 -1
  3. package/lib/cjs/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  4. package/lib/cjs/ArcGisFeature/ArcGisFeatureQuery.js.map +1 -1
  5. package/lib/cjs/ArcGisFeature/ArcGisFeatureReader.js.map +1 -1
  6. package/lib/cjs/ArcGisFeature/ArcGisFeatureResponse.js.map +1 -1
  7. package/lib/cjs/ArcGisFeature/ArcGisJsonFeatureReader.js.map +1 -1
  8. package/lib/cjs/ArcGisFeature/ArcGisPbfFeatureReader.js.map +1 -1
  9. package/lib/cjs/ArcGisFeature/ArcGisSymbologyRenderer.js.map +1 -1
  10. package/lib/cjs/ArcGisFeature/EsriSymbology.js.map +1 -1
  11. package/lib/cjs/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  12. package/lib/cjs/Feature/DefaultMarkerIcon.js +9 -9
  13. package/lib/cjs/Feature/DefaultMarkerIcon.js.map +1 -1
  14. package/lib/cjs/Feature/FeatureCanvasRenderer.js.map +1 -1
  15. package/lib/cjs/Feature/FeatureInfoReader.js.map +1 -1
  16. package/lib/cjs/Feature/FeatureSymbology.js.map +1 -1
  17. package/lib/cjs/Feature/RandomMapColor.js.map +1 -1
  18. package/lib/cjs/GeoJSON/GeoJSONGeometry.js.map +1 -1
  19. package/lib/cjs/GeoJSON/GeoJSONGeometryReader.js.map +1 -1
  20. package/lib/cjs/GoogleMaps/GoogleMaps.d.ts +8 -125
  21. package/lib/cjs/GoogleMaps/GoogleMaps.d.ts.map +1 -1
  22. package/lib/cjs/GoogleMaps/GoogleMaps.js +10 -3
  23. package/lib/cjs/GoogleMaps/GoogleMaps.js.map +1 -1
  24. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.d.ts +8 -0
  25. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.d.ts.map +1 -1
  26. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.js +10 -1
  27. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.js.map +1 -1
  28. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.d.ts +10 -7
  29. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -1
  30. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js +65 -68
  31. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -1
  32. package/lib/cjs/GoogleMaps/GoogleMapsSession.d.ts +152 -0
  33. package/lib/cjs/GoogleMaps/GoogleMapsSession.d.ts.map +1 -0
  34. package/lib/cjs/GoogleMaps/GoogleMapsSession.js +33 -0
  35. package/lib/cjs/GoogleMaps/GoogleMapsSession.js.map +1 -0
  36. package/lib/cjs/Icons/MapInfoIcon.js.map +1 -1
  37. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesFormat.js.map +1 -1
  38. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesProvider.js.map +1 -1
  39. package/lib/cjs/OgcApiFeatures/OgcApiFeaturesReader.js.map +1 -1
  40. package/lib/cjs/Tools/GeometryTerrainDraper.js.map +1 -1
  41. package/lib/cjs/Tools/MapFeatureInfoDecorator.js.map +1 -1
  42. package/lib/cjs/Tools/MapFeatureInfoTool.js.map +1 -1
  43. package/lib/cjs/internal/GoogleMapsUtils.d.ts +9 -16
  44. package/lib/cjs/internal/GoogleMapsUtils.d.ts.map +1 -1
  45. package/lib/cjs/internal/GoogleMapsUtils.js +36 -40
  46. package/lib/cjs/internal/GoogleMapsUtils.js.map +1 -1
  47. package/lib/cjs/internal/NativeGoogleMapsSession.d.ts +29 -0
  48. package/lib/cjs/internal/NativeGoogleMapsSession.d.ts.map +1 -0
  49. package/lib/cjs/internal/NativeGoogleMapsSession.js +83 -0
  50. package/lib/cjs/internal/NativeGoogleMapsSession.js.map +1 -0
  51. package/lib/cjs/map-layers-formats.d.ts +2 -0
  52. package/lib/cjs/map-layers-formats.d.ts.map +1 -1
  53. package/lib/cjs/map-layers-formats.js +2 -0
  54. package/lib/cjs/map-layers-formats.js.map +1 -1
  55. package/lib/cjs/mapLayersFormats.d.ts +10 -0
  56. package/lib/cjs/mapLayersFormats.d.ts.map +1 -1
  57. package/lib/cjs/mapLayersFormats.js +5 -0
  58. package/lib/cjs/mapLayersFormats.js.map +1 -1
  59. package/lib/esm/ArcGisFeature/ArcGisFeatureFormat.js.map +1 -1
  60. package/lib/esm/ArcGisFeature/ArcGisFeatureProvider.js.map +1 -1
  61. package/lib/esm/ArcGisFeature/ArcGisFeatureQuery.js.map +1 -1
  62. package/lib/esm/ArcGisFeature/ArcGisFeatureReader.js.map +1 -1
  63. package/lib/esm/ArcGisFeature/ArcGisFeatureResponse.js.map +1 -1
  64. package/lib/esm/ArcGisFeature/ArcGisJsonFeatureReader.js.map +1 -1
  65. package/lib/esm/ArcGisFeature/ArcGisPbfFeatureReader.js.map +1 -1
  66. package/lib/esm/ArcGisFeature/ArcGisSymbologyRenderer.js.map +1 -1
  67. package/lib/esm/ArcGisFeature/EsriSymbology.js.map +1 -1
  68. package/lib/esm/ArcGisFeature/esriPBuffer.gen.js.map +1 -1
  69. package/lib/esm/Feature/DefaultMarkerIcon.js +9 -9
  70. package/lib/esm/Feature/DefaultMarkerIcon.js.map +1 -1
  71. package/lib/esm/Feature/FeatureCanvasRenderer.js.map +1 -1
  72. package/lib/esm/Feature/FeatureInfoReader.js.map +1 -1
  73. package/lib/esm/Feature/FeatureSymbology.js.map +1 -1
  74. package/lib/esm/Feature/RandomMapColor.js.map +1 -1
  75. package/lib/esm/GeoJSON/GeoJSONGeometry.js.map +1 -1
  76. package/lib/esm/GeoJSON/GeoJSONGeometryReader.js.map +1 -1
  77. package/lib/esm/GoogleMaps/GoogleMaps.d.ts +8 -125
  78. package/lib/esm/GoogleMaps/GoogleMaps.d.ts.map +1 -1
  79. package/lib/esm/GoogleMaps/GoogleMaps.js +10 -3
  80. package/lib/esm/GoogleMaps/GoogleMaps.js.map +1 -1
  81. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.d.ts +8 -0
  82. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.d.ts.map +1 -1
  83. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.js +10 -1
  84. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.js.map +1 -1
  85. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.d.ts +10 -7
  86. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -1
  87. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js +65 -68
  88. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -1
  89. package/lib/esm/GoogleMaps/GoogleMapsSession.d.ts +152 -0
  90. package/lib/esm/GoogleMaps/GoogleMapsSession.d.ts.map +1 -0
  91. package/lib/esm/GoogleMaps/GoogleMapsSession.js +28 -0
  92. package/lib/esm/GoogleMaps/GoogleMapsSession.js.map +1 -0
  93. package/lib/esm/Icons/MapInfoIcon.js.map +1 -1
  94. package/lib/esm/OgcApiFeatures/OgcApiFeaturesFormat.js.map +1 -1
  95. package/lib/esm/OgcApiFeatures/OgcApiFeaturesProvider.js.map +1 -1
  96. package/lib/esm/OgcApiFeatures/OgcApiFeaturesReader.js.map +1 -1
  97. package/lib/esm/Tools/GeometryTerrainDraper.js.map +1 -1
  98. package/lib/esm/Tools/MapFeatureInfoDecorator.js.map +1 -1
  99. package/lib/esm/Tools/MapFeatureInfoTool.js.map +1 -1
  100. package/lib/esm/internal/GoogleMapsUtils.d.ts +9 -16
  101. package/lib/esm/internal/GoogleMapsUtils.d.ts.map +1 -1
  102. package/lib/esm/internal/GoogleMapsUtils.js +36 -40
  103. package/lib/esm/internal/GoogleMapsUtils.js.map +1 -1
  104. package/lib/esm/internal/NativeGoogleMapsSession.d.ts +29 -0
  105. package/lib/esm/internal/NativeGoogleMapsSession.d.ts.map +1 -0
  106. package/lib/esm/internal/NativeGoogleMapsSession.js +78 -0
  107. package/lib/esm/internal/NativeGoogleMapsSession.js.map +1 -0
  108. package/lib/esm/map-layers-formats.d.ts +2 -0
  109. package/lib/esm/map-layers-formats.d.ts.map +1 -1
  110. package/lib/esm/map-layers-formats.js +2 -0
  111. package/lib/esm/map-layers-formats.js.map +1 -1
  112. package/lib/esm/mapLayersFormats.d.ts +10 -0
  113. package/lib/esm/mapLayersFormats.d.ts.map +1 -1
  114. package/lib/esm/mapLayersFormats.js +5 -0
  115. package/lib/esm/mapLayersFormats.js.map +1 -1
  116. package/lib/public/locales/en/mapLayersFormats.json +18 -18
  117. package/package.json +17 -15
  118. package/lib/cjs/GoogleMaps/GoogleMapDecorator.d.ts +0 -36
  119. package/lib/cjs/GoogleMaps/GoogleMapDecorator.d.ts.map +0 -1
  120. package/lib/cjs/GoogleMaps/GoogleMapDecorator.js +0 -87
  121. package/lib/cjs/GoogleMaps/GoogleMapDecorator.js.map +0 -1
  122. package/lib/esm/GoogleMaps/GoogleMapDecorator.d.ts +0 -36
  123. package/lib/esm/GoogleMaps/GoogleMapDecorator.d.ts.map +0 -1
  124. package/lib/esm/GoogleMaps/GoogleMapDecorator.js +0 -82
  125. package/lib/esm/GoogleMaps/GoogleMapDecorator.js.map +0 -1
@@ -6,69 +6,54 @@
6
6
  * @module MapLayersFormats
7
7
  */
8
8
  import { BentleyError, BentleyStatus, Logger } from "@itwin/core-bentley";
9
- import { IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapLayerSourceStatus, MapTile } from "@itwin/core-frontend";
9
+ import { GoogleMapsDecorator, IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapTile } from "@itwin/core-frontend";
10
+ import { NativeGoogleMapsSessionManager } from "../internal/NativeGoogleMapsSession.js";
10
11
  import { GoogleMapsUtils } from "../internal/GoogleMapsUtils.js";
11
- import { GoogleMapsDecorator } from "./GoogleMapDecorator.js";
12
12
  const loggerCategory = "MapLayersFormats.GoogleMaps";
13
- const levelToken = "{level}";
14
- const rowToken = "{row}";
15
- const columnToken = "{column}";
16
- const urlTemplate = `https://tile.googleapis.com/v1/2dtiles/${levelToken}/${columnToken}/${rowToken}`;
17
13
  /*
18
14
  * Google Maps imagery provider
19
- * @internal
15
+ * @beta
20
16
  */
21
17
  export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
22
18
  _decorator;
23
19
  _hadUnrecoverableError = false;
24
20
  _tileSize = 256;
25
- constructor(settings) {
21
+ _sessionManager;
22
+ _sessionOptions;
23
+ _activeSession;
24
+ constructor(settings, sessionManager) {
26
25
  super(settings, true);
27
26
  this._decorator = new GoogleMapsDecorator();
28
- }
29
- static validateUrlTemplate(template) {
30
- return { status: (template.indexOf(levelToken) > 0 && template.indexOf(columnToken) > 0 && template.indexOf(rowToken) > 0) ? MapLayerSourceStatus.Valid : MapLayerSourceStatus.InvalidUrl };
31
- }
32
- async createSession() {
33
- const sessionOptions = this.createCreateSessionOptions();
34
- if (this._settings.accessKey) {
35
- // Create session and store in query parameters
36
- const sessionObj = await GoogleMapsUtils.createSession(this._settings.accessKey.value, sessionOptions);
37
- this._settings.unsavedQueryParams = { session: sessionObj.session };
38
- return sessionObj;
39
- }
40
- else {
41
- Logger.logError(loggerCategory, `Missing GoogleMaps api key`);
42
- return undefined;
43
- }
27
+ this._sessionManager = sessionManager;
44
28
  }
45
29
  get tileSize() { return this._tileSize; }
46
30
  async initialize() {
47
- const layerPropertyKeys = this._settings.properties ? Object.keys(this._settings.properties) : undefined;
48
- if (layerPropertyKeys === undefined ||
49
- !layerPropertyKeys.includes("mapType") ||
50
- !layerPropertyKeys.includes("language") ||
51
- !layerPropertyKeys.includes("region")) {
52
- const msg = "Missing session options";
31
+ this._sessionOptions = GoogleMapsUtils.getSessionOptionsFromMapLayer(this._settings);
32
+ this._sessionManager = await this.getSessionManager();
33
+ this._activeSession = await this._sessionManager.createSession(this._sessionOptions);
34
+ ;
35
+ this._tileSize = this._activeSession.getTileSize();
36
+ const isActivated = await this._decorator.activate(this._settings.properties.mapType);
37
+ if (!isActivated) {
38
+ const msg = `Failed to activate decorator`;
53
39
  Logger.logError(loggerCategory, msg);
54
40
  throw new BentleyError(BentleyStatus.ERROR, msg);
55
41
  }
56
- const session = await this.createSession();
57
- if (!session) {
58
- const msg = `Failed to create session`;
59
- Logger.logError(loggerCategory, msg);
60
- throw new BentleyError(BentleyStatus.ERROR, msg);
42
+ }
43
+ async getSessionManager() {
44
+ if (this._sessionManager)
45
+ return this._sessionManager;
46
+ if (this._settings.accessKey?.value) {
47
+ return new NativeGoogleMapsSessionManager(this._settings.accessKey.value);
61
48
  }
62
- this._tileSize = session.tileWidth; // assuming here tiles are square
63
- const isActivated = await this._decorator.activate(this._settings.properties.mapType);
64
- if (!isActivated) {
65
- const msg = `Failed to activate decorator`;
49
+ else {
50
+ const msg = `Missing GoogleMaps api key`;
66
51
  Logger.logError(loggerCategory, msg);
67
52
  throw new BentleyError(BentleyStatus.ERROR, msg);
68
53
  }
69
54
  }
70
- createCreateSessionOptions() {
71
- const layerPropertyKeys = this._settings.properties ? Object.keys(this._settings.properties) : undefined;
55
+ createCreateSessionOptions(settings) {
56
+ const layerPropertyKeys = settings.properties ? Object.keys(settings.properties) : undefined;
72
57
  if (layerPropertyKeys === undefined ||
73
58
  !layerPropertyKeys.includes("mapType") ||
74
59
  !layerPropertyKeys.includes("language") ||
@@ -78,11 +63,11 @@ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
78
63
  throw new BentleyError(BentleyStatus.ERROR, msg);
79
64
  }
80
65
  const createSessionOptions = {
81
- mapType: this._settings.properties.mapType,
66
+ mapType: settings.properties.mapType,
82
67
  region: this._settings.properties.region,
83
68
  language: this._settings.properties.language,
84
69
  };
85
- if (this._settings.properties?.layerTypes !== undefined) {
70
+ if (Array.isArray(this._settings.properties?.layerTypes) && this._settings.properties.layerTypes.length > 0) {
86
71
  createSessionOptions.layerTypes = this._settings.properties.layerTypes;
87
72
  }
88
73
  if (this._settings.properties?.scale !== undefined) {
@@ -96,15 +81,27 @@ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
96
81
  }
97
82
  return createSessionOptions;
98
83
  }
99
- // construct the Url from the desired Tile
100
- async constructUrl(row, column, level) {
101
- const tmpUrl = urlTemplate.replace(levelToken, level.toString()).replace(columnToken, column.toString()).replace(rowToken, row.toString());
102
- const obj = new URL(tmpUrl);
103
- if (this._settings.accessKey) {
104
- obj.searchParams.append("key", this._settings.accessKey.value);
105
- }
106
- // We assume the 'session' param to be already part of the query parameters (checked in initialize)
107
- return this.appendCustomParams(obj.toString());
84
+ // not used, see loadTile
85
+ async constructUrl(_row, _column, _level) {
86
+ return "";
87
+ }
88
+ async fetchViewportInfo(rectangle, zoomLevel) {
89
+ if (!this._activeSession) {
90
+ Logger.logError(loggerCategory, `Session is not initialized`);
91
+ throw new BentleyError(BentleyStatus.ERROR, "Session is not initialized");
92
+ }
93
+ const req = this._activeSession.getViewportInfoRequest(rectangle, zoomLevel);
94
+ const request = new Request(req.url, { method: "GET" });
95
+ if (req.authorization) {
96
+ request.headers.set("Authorization", req.authorization);
97
+ }
98
+ // Add the session token to the request
99
+ const response = await fetch(request);
100
+ if (!response.ok) {
101
+ Logger.logError(loggerCategory, `Error while loading viewport info: ${response.statusText}`);
102
+ throw new BentleyError(BentleyStatus.ERROR, `Error while loading viewport info: ${response.statusText}`);
103
+ }
104
+ return response.json();
108
105
  }
109
106
  async fetchAttributions(tiles) {
110
107
  const zooms = new Set();
@@ -123,14 +120,9 @@ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
123
120
  cartoRect = rect;
124
121
  }
125
122
  }
126
- if (cartoRect) {
123
+ if (cartoRect && this._activeSession) {
127
124
  try {
128
- const viewportInfo = await GoogleMapsUtils.getViewportInfo({
129
- rectangle: cartoRect,
130
- session: this._settings.collectQueryParams().session,
131
- key: this._settings.accessKey.value,
132
- zoom
133
- });
125
+ const viewportInfo = await this.fetchViewportInfo(cartoRect, zoom);
134
126
  if (viewportInfo?.copyright) {
135
127
  matchingAttributions.push(viewportInfo.copyright);
136
128
  }
@@ -152,18 +144,23 @@ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
152
144
  }
153
145
  }
154
146
  async loadTile(row, column, zoomLevel) {
147
+ const tilePos = { row, column, level: zoomLevel };
155
148
  if (this._hadUnrecoverableError)
156
149
  return undefined;
150
+ if (this._activeSession === undefined || this._sessionOptions === undefined) {
151
+ Logger.logError(loggerCategory, `Session manager is not initialized`);
152
+ return undefined;
153
+ }
157
154
  try {
158
- let tileUrl = await this.constructUrl(row, column, zoomLevel);
159
- let tileResponse = await this.makeTileRequest(tileUrl);
155
+ let tileRequest = this._activeSession.getTileRequest(tilePos);
156
+ let tileResponse = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);
160
157
  if (!tileResponse.ok) {
161
- if (tileResponse.headers.get("content-type")?.includes("application/json")) {
162
- // Session might have expired, lets try to re-new it.
163
- const isSessionCreated = await this.createSession();
164
- if (isSessionCreated) {
165
- tileUrl = await this.constructUrl(row, column, zoomLevel);
166
- tileResponse = await this.makeTileRequest(tileUrl);
158
+ if (tileResponse.headers.get("content-type")?.includes("application/json") && this._sessionManager) {
159
+ try {
160
+ // Session might have expired, lets try to refresh it
161
+ this._activeSession = await this._sessionManager.createSession(this._sessionOptions);
162
+ tileRequest = this._activeSession.getTileRequest(tilePos);
163
+ tileResponse = await this.makeTileRequest(tileRequest.url.toString(), undefined, tileRequest.authorization);
167
164
  if (!tileResponse.ok) {
168
165
  if (tileResponse.headers.get("content-type")?.includes("application/json")) {
169
166
  await this.logJsonError(tileResponse);
@@ -175,7 +172,7 @@ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
175
172
  return undefined;
176
173
  }
177
174
  }
178
- else {
175
+ catch {
179
176
  await this.logJsonError(tileResponse);
180
177
  }
181
178
  }
@@ -1 +1 @@
1
- {"version":3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AAC;gBAClB,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,qCAAqC,KAAK,EAAE,OAAO,IAAE,eAAe,EAAE,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;QAED,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,YAAY,CAAC;YACvC,OAAO,EAAE,GAAG,SAAS,CAAC,UAAU,iCAAiC;YACjE,OAAO,EAAE,aAAa;YACtB,MAAM,EAAE,YAAY;SAAE,CAAC,CAAC,CAAC;IAC7B,CAAC;CAEF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n/** @packageDocumentation\n * @module MapLayersFormats\n */\n\nimport { BentleyError, BentleyStatus, Logger } from \"@itwin/core-bentley\";\nimport { ImageMapLayerSettings, ImageSource } from \"@itwin/core-common\";\nimport { DecorateContext, IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapLayerSourceStatus, MapLayerSourceValidation, MapTile, ScreenViewport, Tile } from \"@itwin/core-frontend\";\nimport { GoogleMapsUtils } from \"../internal/GoogleMapsUtils.js\";\nimport { GoogleMapsDecorator } from \"./GoogleMapDecorator.js\";\nimport { GoogleMapsCreateSessionOptions, GoogleMapsLayerTypes, GoogleMapsMapTypes, GoogleMapsScaleFactors, GoogleMapsSession } from \"./GoogleMaps.js\";\n\nconst loggerCategory = \"MapLayersFormats.GoogleMaps\";\nconst levelToken = \"{level}\";\nconst rowToken = \"{row}\";\nconst columnToken = \"{column}\";\n\nconst urlTemplate = `https://tile.googleapis.com/v1/2dtiles/${levelToken}/${columnToken}/${rowToken}`;\n\n/*\n* Google Maps imagery provider\n* @internal\n*/\nexport class GoogleMapsImageryProvider extends MapLayerImageryProvider {\n\n private _decorator: GoogleMapsDecorator;\n private _hadUnrecoverableError = false;\n private _tileSize = 256\n constructor(settings: ImageMapLayerSettings) {\n super(settings, true);\n this._decorator = new GoogleMapsDecorator();\n }\n public static validateUrlTemplate(template: string): MapLayerSourceValidation {\n return { status: (template.indexOf(levelToken) > 0 && template.indexOf(columnToken) > 0 && template.indexOf(rowToken) > 0) ? MapLayerSourceStatus.Valid : MapLayerSourceStatus.InvalidUrl };\n }\n\n protected async createSession() : Promise<GoogleMapsSession|undefined> {\n const sessionOptions = this.createCreateSessionOptions();\n if (this._settings.accessKey ) {\n // Create session and store in query parameters\n const sessionObj = await GoogleMapsUtils.createSession(this._settings.accessKey.value, sessionOptions);\n this._settings.unsavedQueryParams = {session: sessionObj.session};\n return sessionObj;\n } else {\n Logger.logError(loggerCategory, `Missing GoogleMaps api key`);\n return undefined;\n }\n }\n public override get tileSize(): number { return this._tileSize; }\n\n public override async initialize(): Promise<void> {\n\n const layerPropertyKeys = this._settings.properties ? Object.keys(this._settings.properties) : undefined;\n if (layerPropertyKeys === undefined ||\n !layerPropertyKeys.includes(\"mapType\") ||\n !layerPropertyKeys.includes(\"language\") ||\n !layerPropertyKeys.includes(\"region\")) {\n const msg = \"Missing session options\";\n Logger.logError(loggerCategory, msg);\n throw new BentleyError(BentleyStatus.ERROR, msg);\n }\n\n const session = await this.createSession();\n if (!session) {\n const msg = `Failed to create session`;\n Logger.logError(loggerCategory, msg);\n throw new BentleyError(BentleyStatus.ERROR, msg);\n }\n this._tileSize = session.tileWidth; // assuming here tiles are square\n\n const isActivated = await this._decorator.activate(this._settings.properties!.mapType as GoogleMapsMapTypes);\n if (!isActivated) {\n const msg = `Failed to activate decorator`;\n Logger.logError(loggerCategory, msg);\n throw new BentleyError(BentleyStatus.ERROR, msg);\n }\n }\n\n private createCreateSessionOptions(): GoogleMapsCreateSessionOptions {\n const layerPropertyKeys = this._settings.properties ? Object.keys(this._settings.properties) : undefined;\n if (layerPropertyKeys === undefined ||\n !layerPropertyKeys.includes(\"mapType\") ||\n !layerPropertyKeys.includes(\"language\") ||\n !layerPropertyKeys.includes(\"region\")) {\n const msg = \"Missing session options\";\n Logger.logError(loggerCategory, msg);\n throw new BentleyError(BentleyStatus.ERROR, msg);\n }\n\n const createSessionOptions: GoogleMapsCreateSessionOptions = {\n mapType: this._settings.properties!.mapType as GoogleMapsMapTypes,\n region: this._settings.properties!.region as string,\n language: this._settings.properties!.language as string,\n }\n\n if (this._settings.properties?.layerTypes !== undefined) {\n createSessionOptions.layerTypes = this._settings.properties.layerTypes as GoogleMapsLayerTypes[];\n }\n\n if (this._settings.properties?.scale !== undefined) {\n createSessionOptions.scale = this._settings.properties.scale as GoogleMapsScaleFactors;\n }\n\n if (this._settings.properties?.overlay !== undefined) {\n createSessionOptions.overlay = this._settings.properties.overlay as boolean;\n }\n\n if (this._settings.properties?.apiOptions !== undefined) {\n createSessionOptions.apiOptions = this._settings.properties.apiOptions as string[];\n }\n return createSessionOptions;\n }\n\n // construct the Url from the desired Tile\n public async constructUrl(row: number, column: number, level: number): Promise<string> {\n const tmpUrl = urlTemplate.replace(levelToken, level.toString()).replace(columnToken, column.toString()).replace(rowToken, row.toString());\n const obj = new URL(tmpUrl);\n if (this._settings.accessKey ) {\n obj.searchParams.append(\"key\", this._settings.accessKey.value);\n }\n\n // We assume the 'session' param to be already part of the query parameters (checked in initialize)\n return this.appendCustomParams(obj.toString());\n }\n\n private async fetchAttributions(tiles: Set<Tile>): Promise<string[]> {\n const zooms = new Set<number>();\n const matchingAttributions: string[] = [];\n\n // Viewport info requests must be made for a specific zoom level\n tiles.forEach((tile) => zooms.add(tile.depth));\n\n for (const zoom of zooms) {\n let cartoRect: MapCartoRectangle|undefined;\n for (const tile of tiles) {\n if (tile.depth === zoom && tile instanceof MapTile) {\n const extent = this.getEPSG4326Extent(tile.quadId.row, tile.quadId.column, tile.depth);\n const rect = MapCartoRectangle.fromDegrees(extent.longitudeLeft, extent.latitudeBottom, extent.longitudeRight, extent.latitudeTop)\n if (cartoRect)\n cartoRect.union(rect);\n else\n cartoRect = rect;\n }\n }\n if (cartoRect) {\n try {\n const viewportInfo = await GoogleMapsUtils.getViewportInfo({\n rectangle: cartoRect,\n session: this._settings.collectQueryParams().session,\n key: this._settings.accessKey!.value,\n zoom});\n if (viewportInfo?.copyright) {\n matchingAttributions.push(viewportInfo.copyright);\n }\n } catch (error:any) {\n Logger.logError(loggerCategory, `Error while loading viewport info: ${error?.message??\"Unknown error\"}`);\n }\n }\n }\n\n return matchingAttributions;\n }\n private async logJsonError(tileResponse: Response) {\n try {\n const error = await tileResponse.json();\n Logger.logError(loggerCategory, `Error while loading tile: ${error?.message}`);\n } catch {\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\n }\n }\n\n public override async loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined> {\n if (this._hadUnrecoverableError)\n return undefined;\n\n try {\n let tileUrl: string = await this.constructUrl(row, column, zoomLevel);\n let tileResponse: Response = await this.makeTileRequest(tileUrl);\n if (!tileResponse.ok) {\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\")) {\n // Session might have expired, lets try to re-new it.\n const isSessionCreated = await this.createSession();\n if (isSessionCreated) {\n tileUrl = await this.constructUrl(row, column, zoomLevel);\n tileResponse = await this.makeTileRequest(tileUrl);\n if (!tileResponse.ok) {\n if (tileResponse.headers.get(\"content-type\")?.includes(\"application/json\")) {\n await this.logJsonError(tileResponse);\n } else {\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\n }\n this._hadUnrecoverableError = true; // Prevent from doing more invalid requests\n return undefined;\n }\n } else {\n await this.logJsonError(tileResponse);\n }\n } else {\n Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);\n return undefined;\n }\n }\n return await this.getImageFromTileResponse(tileResponse, zoomLevel);\n } catch (error: any) {\n if (error?.code === 401) {\n Logger.logError(loggerCategory, `Authorize to load tile: ${error.message}`);\n } else {\n Logger.logError(loggerCategory, `Error while loading tile: ${error.message}`);\n }\n return undefined;\n }\n }\n\n public override decorate(context: DecorateContext): void {\n this._decorator.decorate(context);\n }\n\n private getSelectedTiles(vp: ScreenViewport) {\n return IModelApp.tileAdmin.getTilesForUser(vp)?.selected\n }\n\n public override async addAttributions (cards: HTMLTableElement, vp: ScreenViewport): Promise<void> {\n let copyrightMsg = \"\";\n const tiles = this.getSelectedTiles(vp);\n if (tiles) {\n try {\n const attrList = await this.fetchAttributions(tiles);\n for (const attr of attrList) {\n attr.split(\",\").forEach((line) => {\n copyrightMsg += `${copyrightMsg.length===0 ? \"\": \"<br\"}${line}`;\n });\n }\n }\n catch (error: any) {\n Logger.logError(loggerCategory, `Error while loading attributions: ${error?.message??\"Unknown error\"}`);\n }\n }\n\n cards.appendChild(IModelApp.makeLogoCard({\n iconSrc: `${IModelApp.publicPath}images/google_on_white_hdpi.png`,\n heading: \"Google Maps\",\n notice: copyrightMsg }));\n }\n\n}\n"]}
1
+ {"version":3,"file":"GoogleMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAmB,mBAAmB,EAAE,SAAS,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,OAAO,EAAqC,MAAM,sBAAsB,CAAC;AAE/K,OAAO,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,cAAc,GAAG,6BAA6B,CAAC;AAErD;;;EAGE;AACF,MAAM,OAAO,yBAA0B,SAAQ,uBAAuB;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,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EAAE,CAAC;oBAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;wBAC/B,YAAY,IAAI,GAAG,YAAY,CAAC,MAAM,KAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA,CAAC,CAAC,KAAK,GAAG,IAAI,EAAE,CAAC;oBACpE,CAAC,CAAC,CAAC;gBACH,CAAC;YACH,CAAC;YACD,OAAO,KAAU,EAAE,CAAC;gBAClB,MAAM,CAAC,QAAQ,CAAC,cAAc,EAAE,qCAAqC,KAAK,EAAE,OAAO,IAAE,eAAe,EAAE,CAAC,CAAC;YAC1G,CAAC;QACH,CAAC;QAED,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,YAAY,CAAC;YACvC,OAAO,EAAE,GAAG,SAAS,CAAC,UAAU,iCAAiC;YACjE,OAAO,EAAE,aAAa;YACtB,MAAM,EAAE,YAAY;SAAE,CAAC,CAAC,CAAC;IAC7B,CAAC;CACF","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, GoogleMapsLayerTypes, GoogleMapsMapTypes, GoogleMapsScaleFactors, 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 }\r\n public override get tileSize(): number { return this._tileSize; }\r\n\r\n public override async initialize(): Promise<void> {\r\n this._sessionOptions = GoogleMapsUtils.getSessionOptionsFromMapLayer(this._settings);\r\n this._sessionManager = await this.getSessionManager();\r\n this._activeSession = await this._sessionManager.createSession(this._sessionOptions);;\r\n this._tileSize = this._activeSession.getTileSize();\r\n const isActivated = await this._decorator.activate(this._settings.properties!.mapType as GoogleMapsMapTypes);\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 layerPropertyKeys = settings.properties ? Object.keys(settings.properties) : undefined;\r\n if (layerPropertyKeys === undefined ||\r\n !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 createSessionOptions: GoogleMapsCreateSessionOptions = {\r\n mapType: settings.properties!.mapType as GoogleMapsMapTypes,\r\n region: this._settings.properties!.region as string,\r\n language: this._settings.properties!.language as string,\r\n }\r\n\r\n if (Array.isArray(this._settings.properties?.layerTypes) && this._settings.properties.layerTypes.length > 0) {\r\n createSessionOptions.layerTypes = this._settings.properties.layerTypes as GoogleMapsLayerTypes[];\r\n }\r\n\r\n if (this._settings.properties?.scale !== undefined) {\r\n createSessionOptions.scale = this._settings.properties.scale as GoogleMapsScaleFactors;\r\n }\r\n\r\n if (this._settings.properties?.overlay !== undefined) {\r\n createSessionOptions.overlay = this._settings.properties.overlay as boolean;\r\n }\r\n\r\n if (this._settings.properties?.apiOptions !== undefined) {\r\n createSessionOptions.apiOptions = this._settings.properties.apiOptions as string[];\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 let copyrightMsg = \"\";\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 copyrightMsg += `${copyrightMsg.length===0 ? \"\": \"<br\"}${line}`;\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 cards.appendChild(IModelApp.makeLogoCard({\r\n iconSrc: `${IModelApp.publicPath}images/google_on_white_hdpi.png`,\r\n heading: \"Google Maps\",\r\n notice: copyrightMsg }));\r\n }\r\n}\r\n"]}
@@ -0,0 +1,152 @@
1
+ /** @packageDocumentation
2
+ * @module MapLayersFormats
3
+ */
4
+ import { MapCartoRectangle, QuadIdProps } from "@itwin/core-frontend";
5
+ /**
6
+ * The type of base map .
7
+ * @beta*/
8
+ export type GoogleMapsLayerTypes = "layerRoadmap" | "layerStreetview";
9
+ /**
10
+ * Layer types that can be added to the map.
11
+ * @beta
12
+ * */
13
+ export type GoogleMapsMapTypes = "roadmap" | "satellite" | "terrain";
14
+ /**
15
+ * Scale factors that can be applied to labels and objects in the map.
16
+ * @beta
17
+ * */
18
+ export type GoogleMapsScaleFactors = "scaleFactor1x" | "scaleFactor2x" | "scaleFactor4x";
19
+ /**
20
+ * Represents the options to create a Google Maps session.
21
+ * @beta
22
+ */
23
+ export interface GoogleMapsCreateSessionOptions {
24
+ /**
25
+ * The type of base map.
26
+ *
27
+ * `roadmap`: The standard Google Maps painted map tiles.
28
+ *
29
+ * `satellite`: Satellite imagery.
30
+ *
31
+ * `terrain`: Terrain imagery. When selecting `terrain` as the map type, you must also include the `layerRoadmap` layer type.
32
+ * @beta
33
+ * */
34
+ mapType: GoogleMapsMapTypes;
35
+ /**
36
+ * An {@link https://en.wikipedia.org/wiki/IETF_language_tag | IETF language tag} that specifies the language used to display information on the tiles. For example, `en-US` specifies the English language as spoken in the United States.
37
+ */
38
+ language: string;
39
+ /**
40
+ * A {@link https://cldr.unicode.org/ | Common Locale Data Repository} region identifier (two uppercase letters) that represents the physical location of the user. For example, `US`.
41
+ */
42
+ region: string;
43
+ /**
44
+ * An array of values that specifies the layer types added to the map.
45
+ *
46
+ * `layerRoadmap`: Required if you specify terrain as the map type. Can also be optionally overlaid on the satellite map type. Has no effect on roadmap tiles.
47
+ *
48
+ * `layerStreetview`: Shows Street View-enabled streets and locations using blue outlines on the map.
49
+ *
50
+ * @beta
51
+ * */
52
+ layerTypes?: GoogleMapsLayerTypes[];
53
+ /**
54
+ * Scales-up the size of map elements (such as road labels), while retaining the tile size and coverage area of the default tile.
55
+ * Increasing the scale also reduces the number of labels on the map, which reduces clutter.
56
+ *
57
+ * `scaleFactor1x`: The default.
58
+ *
59
+ * `scaleFactor2x`: Doubles label size and removes minor feature labels.
60
+ *
61
+ * `scaleFactor4x`: Quadruples label size and removes minor feature labels.
62
+ * @beta
63
+ * */
64
+ scale?: GoogleMapsScaleFactors;
65
+ /**
66
+ * A boolean value that specifies whether layerTypes should be rendered as a separate overlay, or combined with the base imagery.
67
+ * When true, the base map isn't displayed. If you haven't defined any layerTypes, then this value is ignored.
68
+ * Default is false.
69
+ * @beta
70
+ * */
71
+ overlay?: boolean;
72
+ /**
73
+ * An array of values specifying additional options to apply.
74
+ * @beta
75
+ * */
76
+ apiOptions?: string[];
77
+ }
78
+ /**
79
+ * Session data returned by the Google Maps API.
80
+ * @beta
81
+ */
82
+ export interface GoogleMapsSessionData {
83
+ /** A session token value that you must include in all of your Map Tiles API requests. */
84
+ session: string;
85
+ /** string that contains the time (in seconds since the epoch) at which the token expires. A session token is valid for two weeks from its creation time, but this policy might change without notice. */
86
+ expiry: number;
87
+ /** The width of the tiles measured in pixels. */
88
+ tileWidth: number;
89
+ /** he height of the tiles measured in pixels. */
90
+ tileHeight: number;
91
+ /** The image format, which can be either `png` or `jpeg`. */
92
+ imageFormat: string;
93
+ }
94
+ /**
95
+ * Maximum zoom level available within a bounding rectangle.
96
+ * @beta
97
+ */
98
+ export interface MaxZoomRectangle {
99
+ maxZoom: number;
100
+ north: number;
101
+ south: number;
102
+ east: number;
103
+ west: number;
104
+ }
105
+ /**
106
+ * Indicate which areas of given viewport have imagery, and at which zoom levels.
107
+ * @beta
108
+ */
109
+ export interface ViewportInfo {
110
+ /** Attribution string that you must display on your map when you display roadmap and satellite tiles. */
111
+ copyright: string;
112
+ /** Array of bounding rectangles that overlap with the current viewport. Also contains the maximum zoom level available within each rectangle.. */
113
+ maxZoomRects: MaxZoomRectangle[];
114
+ }
115
+ /**
116
+ * Google Maps Request
117
+ * @beta
118
+ */
119
+ export interface GoogleMapsRequest {
120
+ /** The URL of the request */
121
+ url: URL;
122
+ authorization?: string;
123
+ }
124
+ /**
125
+ * Google Maps session.
126
+ * @beta
127
+ */
128
+ export interface GoogleMapsSession {
129
+ getTileSize: () => number;
130
+ getTileRequest: (position: QuadIdProps) => GoogleMapsRequest;
131
+ getViewportInfoRequest(rectangle: MapCartoRectangle, zoomLevel: number): GoogleMapsRequest;
132
+ }
133
+ /**
134
+ * Base implementation of Google Maps session.
135
+ * @beta
136
+ */
137
+ export declare abstract class BaseGoogleMapsSession implements GoogleMapsSession {
138
+ protected abstract getTileApiBaseUrl(): string;
139
+ protected getTilePositionUrl(position: QuadIdProps): URL;
140
+ abstract getTileSize(): number;
141
+ abstract getTileRequest(position: QuadIdProps): GoogleMapsRequest;
142
+ abstract getViewportInfoRequest(rectangle: MapCartoRectangle, zoomLevel: number): GoogleMapsRequest;
143
+ }
144
+ /**
145
+ * Google Maps session manager interface.
146
+ * @beta
147
+ */
148
+ export declare abstract class GoogleMapsSessionManager {
149
+ readonly type = "GoogleMapsSessionManager";
150
+ abstract createSession(sessionOptions: GoogleMapsCreateSessionOptions): Promise<GoogleMapsSession>;
151
+ }
152
+ //# sourceMappingURL=GoogleMapsSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsSession.d.ts","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsSession.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAC,MAAM,sBAAsB,CAAC;AAGrE;;UAEU;AACV,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAEtE;;;KAGK;AACL,MAAM,MAAM,k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E,GAAG,CAAC;IAGT,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;EAGE;AACF,MAAM,WAAW,iBAAiB;IAEhC,WAAW,EAAE,MAAM,MAAM,CAAC;IAG1B,cAAc,EAAE,CAAC,QAAQ,EAAE,WAAW,KAAK,iBAAiB,CAAC;IAG7D,sBAAsB,CAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB,CAAA;CAC5F;AAED;;;EAGE;AACF,8BAAsB,qBAAsB,YAAW,iBAAiB;IACtE,SAAS,CAAC,QAAQ,CAAC,iBAAiB,IAAI,MAAM;IAE9C,SAAS,CAAC,kBAAkB,CAAC,QAAQ,EAAE,WAAW;aAMlC,WAAW,IAAI,MAAM;aACrB,cAAc,CAAC,QAAQ,EAAE,WAAW,GAAG,iBAAiB;aACxD,sBAAsB,CAAE,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,GAAG,iBAAiB;CAC5G;AAED;;;EAGE;AACF,8BAAsB,wBAAwB;IAC5C,SAAgB,IAAI,8BAA8B;aAClC,aAAa,CAAE,cAAc,EAAE,8BAA8B,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAC3G"}
@@ -0,0 +1,28 @@
1
+ /*---------------------------------------------------------------------------------------------
2
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
3
+ * See LICENSE.md in the project root for license terms and full copyright notice.
4
+ *--------------------------------------------------------------------------------------------*/
5
+ /** @packageDocumentation
6
+ * @module MapLayersFormats
7
+ */
8
+ ;
9
+ ;
10
+ /**
11
+ * Base implementation of Google Maps session.
12
+ * @beta
13
+ */
14
+ export class BaseGoogleMapsSession {
15
+ getTilePositionUrl(position) {
16
+ const baseUrl = this.getTileApiBaseUrl();
17
+ const tmpUrl = `${baseUrl}/${position.level}/${position.column}/${position.row}`;
18
+ return new URL(tmpUrl);
19
+ }
20
+ }
21
+ /**
22
+ * Google Maps session manager interface.
23
+ * @beta
24
+ */
25
+ export class GoogleMapsSessionManager {
26
+ type = "GoogleMapsSessionManager";
27
+ }
28
+ //# sourceMappingURL=GoogleMapsSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsSession.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsSession.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAoFF,CAAC;AAsBD,CAAC;AAsDF;;;EAGE;AACF,MAAM,OAAgB,qBAAqB;IAG/B,kBAAkB,CAAC,QAAqB;QAChD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzC,MAAM,MAAM,GAAG,GAAG,OAAO,IAAI,QAAQ,CAAC,KAAK,IAAI,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,GAAG,EAAE,CAAC;QACjF,OAAO,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC;IACzB,CAAC;CAKF;AAED;;;EAGE;AACF,MAAM,OAAgB,wBAAwB;IAC5B,IAAI,GAAG,0BAA0B,CAAC;CAEnD","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 { MapCartoRectangle, QuadIdProps} from \"@itwin/core-frontend\";\r\n\r\n\r\n/**\r\n * The type of base map .\r\n * @beta*/\r\nexport type GoogleMapsLayerTypes = \"layerRoadmap\" | \"layerStreetview\";\r\n\r\n/**\r\n * Layer types that can be added to the map.\r\n * @beta\r\n * */\r\nexport type GoogleMapsMapTypes = \"roadmap\"|\"satellite\"|\"terrain\";\r\n\r\n/**\r\n * Scale factors that can be applied to labels and objects in the map.\r\n * @beta\r\n * */\r\nexport type GoogleMapsScaleFactors = \"scaleFactor1x\" | \"scaleFactor2x\" | \"scaleFactor4x\";\r\n\r\n/**\r\n* Represents the options to create a Google Maps session.\r\n* @beta\r\n*/\r\nexport interface GoogleMapsCreateSessionOptions {\r\n /**\r\n * The type of base map.\r\n *\r\n * `roadmap`: The standard Google Maps painted map tiles.\r\n *\r\n * `satellite`: Satellite imagery.\r\n *\r\n * `terrain`: Terrain imagery. When selecting `terrain` as the map type, you must also include the `layerRoadmap` layer type.\r\n * @beta\r\n * */\r\n mapType: GoogleMapsMapTypes,\r\n /**\r\n * An {@link https://en.wikipedia.org/wiki/IETF_language_tag | IETF language tag} that specifies the language used to display information on the tiles. For example, `en-US` specifies the English language as spoken in the United States.\r\n */\r\n language: string;\r\n /**\r\n * A {@link https://cldr.unicode.org/ | Common Locale Data Repository} region identifier (two uppercase letters) that represents the physical location of the user. For example, `US`.\r\n */\r\n region: string;\r\n\r\n /**\r\n * An array of values that specifies the layer types added to the map.\r\n *\r\n * `layerRoadmap`: Required if you specify terrain as the map type. Can also be optionally overlaid on the satellite map type. Has no effect on roadmap tiles.\r\n *\r\n * `layerStreetview`: Shows Street View-enabled streets and locations using blue outlines on the map.\r\n *\r\n * @beta\r\n * */\r\n layerTypes?: GoogleMapsLayerTypes[];\r\n\r\n /**\r\n * Scales-up the size of map elements (such as road labels), while retaining the tile size and coverage area of the default tile.\r\n * Increasing the scale also reduces the number of labels on the map, which reduces clutter.\r\n *\r\n * `scaleFactor1x`: The default.\r\n *\r\n * `scaleFactor2x`: Doubles label size and removes minor feature labels.\r\n *\r\n * `scaleFactor4x`: Quadruples label size and removes minor feature labels.\r\n * @beta\r\n * */\r\n scale?: GoogleMapsScaleFactors\r\n\r\n /**\r\n * A boolean value that specifies whether layerTypes should be rendered as a separate overlay, or combined with the base imagery.\r\n * When true, the base map isn't displayed. If you haven't defined any layerTypes, then this value is ignored.\r\n * Default is false.\r\n * @beta\r\n * */\r\n overlay? : boolean;\r\n\r\n /**\r\n * An array of values specifying additional options to apply.\r\n * @beta\r\n * */\r\n apiOptions?: string[];\r\n};\r\n\r\n\r\n/**\r\n* Session data returned by the Google Maps API.\r\n* @beta\r\n*/\r\nexport interface GoogleMapsSessionData {\r\n /** A session token value that you must include in all of your Map Tiles API requests. */\r\n session: string;\r\n\r\n /** string that contains the time (in seconds since the epoch) at which the token expires. A session token is valid for two weeks from its creation time, but this policy might change without notice. */\r\n expiry: number;\r\n\r\n /** The width of the tiles measured in pixels. */\r\n tileWidth: number;\r\n\r\n /** he height of the tiles measured in pixels. */\r\n tileHeight: number;\r\n\r\n /** The image format, which can be either `png` or `jpeg`. */\r\n imageFormat: string;\r\n};\r\n\r\n/**\r\n * Maximum zoom level available within a bounding rectangle.\r\n* @beta\r\n*/\r\nexport interface MaxZoomRectangle {\r\n maxZoom: number;\r\n north: number;\r\n south: number;\r\n east: number;\r\n west: number;\r\n}\r\n\r\n/**\r\n * Indicate which areas of given viewport have imagery, and at which zoom levels.\r\n * @beta\r\n*/\r\nexport interface ViewportInfo {\r\n /** Attribution string that you must display on your map when you display roadmap and satellite tiles. */\r\n copyright: string;\r\n\r\n /** Array of bounding rectangles that overlap with the current viewport. Also contains the maximum zoom level available within each rectangle.. */\r\n maxZoomRects: MaxZoomRectangle[];\r\n}\r\n\r\n\r\n/**\r\n* Google Maps Request\r\n* @beta\r\n*/\r\nexport interface GoogleMapsRequest {\r\n /** The URL of the request */\r\n url: URL;\r\n\r\n /* Authorization header for the request */\r\n authorization?: string;\r\n}\r\n\r\n/**\r\n* Google Maps session.\r\n* @beta\r\n*/\r\nexport interface GoogleMapsSession {\r\n /* Tile size in pixels */\r\n getTileSize: () => number;\r\n\r\n /* Tile URL for the given tile position */\r\n getTileRequest: (position: QuadIdProps) => GoogleMapsRequest;\r\n\r\n /* Viewport information request */\r\n getViewportInfoRequest (rectangle: MapCartoRectangle, zoomLevel: number): GoogleMapsRequest\r\n}\r\n\r\n/**\r\n* Base implementation of Google Maps session.\r\n* @beta\r\n*/\r\nexport abstract class BaseGoogleMapsSession implements GoogleMapsSession {\r\n protected abstract getTileApiBaseUrl(): string;\r\n\r\n protected getTilePositionUrl(position: QuadIdProps) {\r\n const baseUrl = this.getTileApiBaseUrl();\r\n const tmpUrl = `${baseUrl}/${position.level}/${position.column}/${position.row}`;\r\n return new URL(tmpUrl);\r\n }\r\n\r\n public abstract getTileSize(): number;\r\n public abstract getTileRequest(position: QuadIdProps): GoogleMapsRequest;\r\n public abstract getViewportInfoRequest (rectangle: MapCartoRectangle, zoomLevel: number): GoogleMapsRequest\r\n}\r\n\r\n/**\r\n* Google Maps session manager interface.\r\n* @beta\r\n*/\r\nexport abstract class GoogleMapsSessionManager {\r\n public readonly type = \"GoogleMapsSessionManager\";\r\n public abstract createSession (sessionOptions: GoogleMapsCreateSessionOptions): Promise<GoogleMapsSession>;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MapInfoIcon.js","sourceRoot":"","sources":["../../../src/Icons/MapInfoIcon.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,goCAAgoC;CACjoC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\n/** @internal */\nexport const mapInfoIcon = {\n dataUri: \"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTUuODYyIDUuMTYyYTEuNDg4IDEuNDg4IDAgMSAxLTIuOTc1IDAgMS40ODggMS40ODggMCAwIDEgMi45NzUgMFpNMTIgN2MuNzEyIDAgMS4zODcuMTU0IDIgLjQyMlYwaC0xLjA1bC0yLjI3OCA3LjIwMUE0Ljk1IDQuOTUgMCAwIDEgMTIgN1ptLTQuNzkyIDYuMzQ5TDcgMTRIMFYwaDExLjQ2M0w4Ljg3MiA4LjEyOUM3LjczOSA5LjA0NSA3IDEwLjQyOSA3IDEyYzAgLjQ3LjA4Ni45MTcuMjA4IDEuMzQ5Wm0tLjAzMy04LjE4N1Y1LjA5YTIuNzY0IDIuNzY0IDAgMCAwLTIuODcyLTIuNzI4IDIuNzY0IDIuNzY0IDAgMCAwLTIuNzI4IDIuOEE2LjkwMyA2LjkwMyAwIDAgMCAyLjggOC4zMTJjLjQ3NC44NzcgMSAxLjcyNCAxLjU3NSAyLjUzOCAwIDAgLjk2My0xLjQ4OCAxLjU3NS0yLjUzN2E2LjkwMyA2LjkwMyAwIDAgMCAxLjIyNS0zLjE1Wk0xNiAxMmE0IDQgMCAxIDEtOCAwIDQgNCAwIDAgMSA4IDBabS00LjA1LTEuODVhLjQ2OS40NjkgMCAwIDAgLjUuNS42NTUuNjU1IDAgMCAwIC42NS0uNmwtLjAwMi0uMDMyQS40Ni40NiAwIDAgMCAxMi42IDkuNmEuNjE1LjYxNSAwIDAgMC0uNjUuNTVabTEuMTUgMy40NS0uMTUtLjJhMSAxIDAgMCAxLS41NS4zYy0uMSAwLS4xLS4wNS0uMDUtLjNsLjM1LTEuM2MuMTUtLjUuMS0uOC0uMTUtLjhhMy4yNSAzLjI1IDAgMCAwLTEuNjUuOGwuMS4yNWMuMTk4LS4xMjUuNDItLjIxLjY1LS4yNS4wNSAwIC4wNS4wNSAwIC4yNWwtLjMgMS4yYy0uMi43IDAgLjg1LjI1Ljg1YTIuODg1IDIuODg1IDAgMCAwIDEuNS0uOFoiLz48L3N2Zz4=\",\n} as const;\n"]}
1
+ {"version":3,"file":"MapInfoIcon.js","sourceRoot":"","sources":["../../../src/Icons/MapInfoIcon.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,gBAAgB;AAChB,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,goCAAgoC;CACjoC,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\n/** @internal */\r\nexport const mapInfoIcon = {\r\n dataUri: \"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNiAxNiI+PHBhdGggZD0iTTUuODYyIDUuMTYyYTEuNDg4IDEuNDg4IDAgMSAxLTIuOTc1IDAgMS40ODggMS40ODggMCAwIDEgMi45NzUgMFpNMTIgN2MuNzEyIDAgMS4zODcuMTU0IDIgLjQyMlYwaC0xLjA1bC0yLjI3OCA3LjIwMUE0Ljk1IDQuOTUgMCAwIDEgMTIgN1ptLTQuNzkyIDYuMzQ5TDcgMTRIMFYwaDExLjQ2M0w4Ljg3MiA4LjEyOUM3LjczOSA5LjA0NSA3IDEwLjQyOSA3IDEyYzAgLjQ3LjA4Ni45MTcuMjA4IDEuMzQ5Wm0tLjAzMy04LjE4N1Y1LjA5YTIuNzY0IDIuNzY0IDAgMCAwLTIuODcyLTIuNzI4IDIuNzY0IDIuNzY0IDAgMCAwLTIuNzI4IDIuOEE2LjkwMyA2LjkwMyAwIDAgMCAyLjggOC4zMTJjLjQ3NC44NzcgMSAxLjcyNCAxLjU3NSAyLjUzOCAwIDAgLjk2My0xLjQ4OCAxLjU3NS0yLjUzN2E2LjkwMyA2LjkwMyAwIDAgMCAxLjIyNS0zLjE1Wk0xNiAxMmE0IDQgMCAxIDEtOCAwIDQgNCAwIDAgMSA4IDBabS00LjA1LTEuODVhLjQ2OS40NjkgMCAwIDAgLjUuNS42NTUuNjU1IDAgMCAwIC42NS0uNmwtLjAwMi0uMDMyQS40Ni40NiAwIDAgMCAxMi42IDkuNmEuNjE1LjYxNSAwIDAgMC0uNjUuNTVabTEuMTUgMy40NS0uMTUtLjJhMSAxIDAgMCAxLS41NS4zYy0uMSAwLS4xLS4wNS0uMDUtLjNsLjM1LTEuM2MuMTUtLjUuMS0uOC0uMTUtLjhhMy4yNSA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AAC;YAClB,MAAM,GAAG,oBAAoB,CAAC,UAAU,CAAC;YACzC,IAAI,GAAG,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;YACjH,CAAC;YACD,OAAO,EAAE,MAAM,EAAC,CAAC;QACnB,CAAC;IACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { ImageMapLayerSettings, MapSubLayerProps } from \"@itwin/core-common\";\nimport { appendQueryParams, ImageryMapLayerFormat, MapLayerImageryProvider, MapLayerSourceStatus, MapLayerSourceValidation, setBasicAuthorization, ValidateSourceArgs } from \"@itwin/core-frontend\";\nimport { OgcApiFeaturesProvider } from \"./OgcApiFeaturesProvider.js\";\n\n/** @internal */\nexport class OgcApiFeaturesMapLayerFormat extends ImageryMapLayerFormat {\n public static override formatId = \"OgcApiFeatures\";\n public static override createImageryProvider(settings: ImageMapLayerSettings): MapLayerImageryProvider | undefined { return new OgcApiFeaturesProvider(settings); }\n\n public static override async validate(args: ValidateSourceArgs): Promise<MapLayerSourceValidation> {\n\n const {source} = args;\n const { userName, password } = source;\n let status = MapLayerSourceStatus.InvalidUrl;\n try {\n\n let headers: Headers | undefined;\n if (userName && password) {\n headers = new Headers();\n setBasicAuthorization(headers, userName, password);\n }\n const opts: RequestInit = {\n method: \"GET\",\n headers,\n };\n\n let url = appendQueryParams(source.url, source.savedQueryParams);\n url = appendQueryParams(url, source.unsavedQueryParams);\n let response = await fetch(url, opts);\n let json = await response.json();\n if (!json) {\n return { status };\n }\n\n const createCollectionsList = (data: any) => {\n let array: MapSubLayerProps[] | undefined;\n for (const collection of data.collections) {\n if (collection.itemType === \"feature\") {\n const subLayerProps = {\n id: collection.id,\n name: collection.id,\n title: collection.title,\n visible: true,\n parent: undefined,\n children: undefined,\n };\n if (array)\n array.push(subLayerProps);\n else\n array = [subLayerProps];\n }\n }\n return array;\n };\n\n let subLayers: MapSubLayerProps[] | undefined;\n if (Array.isArray(json.collections)) {\n subLayers = createCollectionsList(json);\n status = MapLayerSourceStatus.Valid;\n } else if (json.itemType === \"feature\" || json.type === \"FeatureCollection\") {\n // We expect one of the following URL:\n // http://server/collections/<collectionName>\n // http://server/collections/<collectionName>/items\n subLayers = [{\n id: json.id,\n name: json.id,\n title: json.title,\n visible: true,\n parent: undefined,\n children: undefined,\n }];\n status = MapLayerSourceStatus.Valid;\n } else if (Array.isArray(json.links)) {\n // This might be the main landing page\n const collectionsLink = json.links.find((link: any)=> link.rel.includes(\"data\") && link.type === \"application/json\");\n let collectionsUrl = appendQueryParams(collectionsLink.href, source.savedQueryParams);\n collectionsUrl = appendQueryParams(collectionsUrl, source.unsavedQueryParams);\n response = await fetch(collectionsUrl, opts);\n json = await response.json();\n if (Array.isArray(json.collections)) {\n subLayers = createCollectionsList(json);\n status = MapLayerSourceStatus.Valid;\n }\n\n }\n\n return { status, subLayers };\n\n } catch (err: any) {\n status = MapLayerSourceStatus.InvalidUrl;\n if (err?.status === 401) {\n status = ((userName && password) ? MapLayerSourceStatus.InvalidCredentials : MapLayerSourceStatus.RequireAuth);\n }\n return { status};\n }\n }\n}\n"]}
1
+ {"version":3,"file":"OgcApiFeaturesFormat.js","sourceRoot":"","sources":["../../../src/OgcApiFeatures/OgcApiFeaturesFormat.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAA2B,oBAAoB,EAA4B,qBAAqB,EAAsB,MAAM,sBAAsB,CAAC;AACpM,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,gBAAgB;AAChB,MAAM,OAAO,4BAA6B,SAAQ,qBAAqB;IAC9D,M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,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC;gBACrH,IAAI,cAAc,GAAG,iBAAiB,CAAC,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;gBACtF,cAAc,GAAG,iBAAiB,CAAC,cAAc,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC;gBAC9E,QAAQ,GAAG,MAAM,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;gBAC7C,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,oBAAoB,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,oBAAoB,CAAC,UAAU,CAAC;YACzC,IAAI,GAAG,EAAE,MAAM,KAAK,GAAG,EAAE,CAAC;gBACxB,MAAM,GAAG,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,kBAAkB,CAAC,CAAC,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;YACjH,CAAC;YACD,OAAO,EAAE,MAAM,EAAC,CAAC;QACnB,CAAC;IACH,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\nimport { ImageMapLayerSettings, MapSubLayerProps } from \"@itwin/core-common\";\r\nimport { appendQueryParams, ImageryMapLayerFormat, 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 let url = appendQueryParams(source.url, source.savedQueryParams);\r\n url = appendQueryParams(url, source.unsavedQueryParams);\r\n let response = await fetch(url, opts);\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 let collectionsUrl = appendQueryParams(collectionsLink.href, source.savedQueryParams);\r\n collectionsUrl = appendQueryParams(collectionsUrl, source.unsavedQueryParams);\r\n response = await fetch(collectionsUrl, opts);\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"]}