@itwin/map-layers-formats 5.0.0-dev.67 → 5.0.0-dev.69

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 (59) hide show
  1. package/lib/cjs/GoogleMaps/GoogleMapDecorator.d.ts +36 -0
  2. package/lib/cjs/GoogleMaps/GoogleMapDecorator.d.ts.map +1 -0
  3. package/lib/cjs/GoogleMaps/GoogleMapDecorator.js +83 -0
  4. package/lib/cjs/GoogleMaps/GoogleMapDecorator.js.map +1 -0
  5. package/lib/cjs/GoogleMaps/GoogleMaps.d.ts +166 -0
  6. package/lib/cjs/GoogleMaps/GoogleMaps.d.ts.map +1 -0
  7. package/lib/cjs/GoogleMaps/GoogleMaps.js +56 -0
  8. package/lib/cjs/GoogleMaps/GoogleMaps.js.map +1 -0
  9. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.d.ts +10 -0
  10. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.d.ts.map +1 -0
  11. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.js +20 -0
  12. package/lib/cjs/GoogleMaps/GoogleMapsImageryFormat.js.map +1 -0
  13. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.d.ts +25 -0
  14. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -0
  15. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js +232 -0
  16. package/lib/cjs/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -0
  17. package/lib/cjs/internal/GoogleMapsUtils.d.ts +38 -0
  18. package/lib/cjs/internal/GoogleMapsUtils.d.ts.map +1 -0
  19. package/lib/cjs/internal/GoogleMapsUtils.js +104 -0
  20. package/lib/cjs/internal/GoogleMapsUtils.js.map +1 -0
  21. package/lib/cjs/map-layers-formats.d.ts +1 -0
  22. package/lib/cjs/map-layers-formats.d.ts.map +1 -1
  23. package/lib/cjs/map-layers-formats.js +1 -0
  24. package/lib/cjs/map-layers-formats.js.map +1 -1
  25. package/lib/cjs/mapLayersFormats.d.ts.map +1 -1
  26. package/lib/cjs/mapLayersFormats.js +2 -0
  27. package/lib/cjs/mapLayersFormats.js.map +1 -1
  28. package/lib/esm/GoogleMaps/GoogleMapDecorator.d.ts +36 -0
  29. package/lib/esm/GoogleMaps/GoogleMapDecorator.d.ts.map +1 -0
  30. package/lib/esm/GoogleMaps/GoogleMapDecorator.js +78 -0
  31. package/lib/esm/GoogleMaps/GoogleMapDecorator.js.map +1 -0
  32. package/lib/esm/GoogleMaps/GoogleMaps.d.ts +166 -0
  33. package/lib/esm/GoogleMaps/GoogleMaps.d.ts.map +1 -0
  34. package/lib/esm/GoogleMaps/GoogleMaps.js +53 -0
  35. package/lib/esm/GoogleMaps/GoogleMaps.js.map +1 -0
  36. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.d.ts +10 -0
  37. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.d.ts.map +1 -0
  38. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.js +16 -0
  39. package/lib/esm/GoogleMaps/GoogleMapsImageryFormat.js.map +1 -0
  40. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.d.ts +25 -0
  41. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.d.ts.map +1 -0
  42. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js +228 -0
  43. package/lib/esm/GoogleMaps/GoogleMapsImageryProvider.js.map +1 -0
  44. package/lib/esm/internal/GoogleMapsUtils.d.ts +38 -0
  45. package/lib/esm/internal/GoogleMapsUtils.d.ts.map +1 -0
  46. package/lib/esm/internal/GoogleMapsUtils.js +101 -0
  47. package/lib/esm/internal/GoogleMapsUtils.js.map +1 -0
  48. package/lib/esm/map-layers-formats.d.ts +1 -0
  49. package/lib/esm/map-layers-formats.d.ts.map +1 -1
  50. package/lib/esm/map-layers-formats.js +1 -0
  51. package/lib/esm/map-layers-formats.js.map +1 -1
  52. package/lib/esm/mapLayersFormats.d.ts.map +1 -1
  53. package/lib/esm/mapLayersFormats.js +2 -0
  54. package/lib/esm/mapLayersFormats.js.map +1 -1
  55. package/lib/public/images/google_on_non_white.png +0 -0
  56. package/lib/public/images/google_on_non_white_hdpi.png +0 -0
  57. package/lib/public/images/google_on_white.png +0 -0
  58. package/lib/public/images/google_on_white_hdpi.png +0 -0
  59. package/package.json +12 -12
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapDecorator.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgD,WAAW,EAAE,SAAS,EAAU,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAI/C;;GAEG;AACH,MAAM,OAAO,cAAc;IACjB,OAAO,CAAU;IAEzB,4DAA4D;IAC5C,QAAQ,GAAG,IAAI,OAAO,EAAE,CAAC;IAEjC,OAAO,CAAoB;IAEnC,IAAW,MAAM,CAAC,MAAyB;QACvC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAEH,0CAA0C;IAC1C,IAAW,MAAM;QACf,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAED,4DAA4D;IACrD,qBAAqB,CAAC,OAAwB;QACnD,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ;YACzC,OAAO,KAAK,CAAC;QAEf,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACjF,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACjB,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,IAAI,CAA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C;QAEvC,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAAC,UAAU,UAAU,SAAS,MAAM,CAAC,CAAC,CAAC;IAC5G,CAAC;IAAA,CAAC;IAEF,8BAA8B;IACvB,QAAQ,GAAG,CAAC,OAAwB,EAAE,EAAE;QAC7C,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ;YACrB,OAAO;QACT,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;IAC9B,CAAC,CAAC;CACH","sourcesContent":["import { CanvasDecoration, DecorateContext, Decorator, IconSprites, IModelApp, Sprite } from \"@itwin/core-frontend\";\nimport { Point3d } from \"@itwin/core-geometry\";\nimport { GoogleMapsMapTypes } from \"./GoogleMaps\";\n\n\n/** A simple decorator that show logo at the a given screen position.\n * @internal\n */\nexport class LogoDecoration implements CanvasDecoration {\n private _sprite?: Sprite;\n\n /** The current position of the logo in view coordinates. */\n public readonly position = new Point3d();\n\n private _offset: Point3d|undefined;\n\n public set offset(offset: Point3d|undefined) {\n this._offset = offset;\n }\n\n /** The logo offset in view coordinates.*/\n public get offset() {\n return this._offset;\n }\n\n /** Move the logo to the lower left corner of the screen. */\n public moveToLowerLeftCorner(context: DecorateContext) : boolean{\n if (!this._sprite || !this._sprite.isLoaded)\n return false;\n\n this.position.x = this._offset?.x ?? 0;\n this.position.y = context.viewport.parentDiv.clientHeight - this._sprite.size.y;\n if (this._offset?.y)\n this.position.y -= this._offset.y;\n return true;\n }\n\n /* TODO: Add other move methods as needed */\n\n /** Indicate if the logo is loaded and ready to be drawn. */\n public get isLoaded() { return this._sprite?.isLoaded ?? false; }\n\n public async activate(sprite: Sprite): Promise<boolean> {\n this._sprite = sprite;\n return new Promise<boolean>((resolve, _reject) => {\n sprite.loadPromise.then(() => {\n resolve(true);\n }).catch(() => {\n resolve (false);\n });\n });\n }\n\n /** Draw this sprite onto the supplied canvas.\n * @see [[CanvasDecoration.drawDecoration]]\n */\n public drawDecoration(ctx: CanvasRenderingContext2D): void {\n if (this.isLoaded) {\n // Draw image with an origin at the top left corner\n ctx.drawImage(this._sprite!.image!, 0, 0);\n }\n }\n\n public decorate(context: DecorateContext) {\n context.addCanvasDecoration(this);\n }\n}\n\n/** A decorator that adds the Google Maps logo to the lower left corner of the screen.\n * @internal\n*/\nexport class GoogleMapsDecorator implements Decorator {\n public readonly logo = new LogoDecoration();\n\n /** Activate the logo based on the given map type. */\n public async activate(mapType: GoogleMapsMapTypes): Promise<boolean> {\n // Pick the logo that is the most visible on the background map\n const imageName = mapType === \"roadmap\" ?\n \"google_on_white\" :\n \"google_on_non_white\";\n\n // We need to move the logo right after the 'i.js' button\n this.logo.offset = new Point3d(45, 10);\n\n return this.logo.activate(IconSprites.getSpriteFromUrl(`${IModelApp.publicPath}images/${imageName}.png`));\n };\n\n /** Decorate implementation */\n public decorate = (context: DecorateContext) => {\n if (!this.logo.isLoaded)\n return;\n this.logo.moveToLowerLeftCorner(context);\n this.logo.decorate(context);\n };\n}\n"]}
@@ -0,0 +1,166 @@
1
+ /** @packageDocumentation
2
+ * @module MapLayersFormats
3
+ */
4
+ import { BaseMapLayerSettings, ImageMapLayerSettings } from "@itwin/core-common";
5
+ import { MapCartoRectangle } from "@itwin/core-frontend";
6
+ /**
7
+ * The type of base map.
8
+ * @beta*/
9
+ export type GoogleMapsLayerTypes = "layerRoadmap" | "layerStreetview";
10
+ /**
11
+ * Layer types that can be added to the map.
12
+ * @beta
13
+ * */
14
+ export type GoogleMapsMapTypes = "roadmap" | "satellite" | "terrain";
15
+ /**
16
+ * Scale factors that can be applied to labels and objects in the map.
17
+ * @beta
18
+ * */
19
+ export type GoogleMapsScaleFactors = "scaleFactor1x" | "scaleFactor2x" | "scaleFactor4x";
20
+ /**
21
+ * Represents the options to create a Google Maps session.
22
+ * @beta
23
+ */
24
+ export interface GoogleMapsCreateSessionOptions {
25
+ /**
26
+ * The type of base map.
27
+ *
28
+ * `roadmap`: The standard Google Maps painted map tiles.
29
+ *
30
+ * `satellite`: Satellite imagery.
31
+ *
32
+ * `terrain`: Terrain imagery. When selecting `terrain` as the map type, you must also include the `layerRoadmap` layer type.
33
+ * @beta
34
+ * */
35
+ mapType: GoogleMapsMapTypes;
36
+ /**
37
+ * 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.
38
+ */
39
+ language: string;
40
+ /**
41
+ * 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`.
42
+ */
43
+ region: string;
44
+ /**
45
+ * An array of values that specifies the layer types added to the map.
46
+ *
47
+ * `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.
48
+ *
49
+ * `layerStreetview`: Shows Street View-enabled streets and locations using blue outlines on the map.
50
+ *
51
+ * @beta
52
+ * */
53
+ layerTypes?: GoogleMapsLayerTypes[];
54
+ /**
55
+ * Scales-up the size of map elements (such as road labels), while retaining the tile size and coverage area of the default tile.
56
+ * Increasing the scale also reduces the number of labels on the map, which reduces clutter.
57
+ *
58
+ * `scaleFactor1x`: The default.
59
+ *
60
+ * `scaleFactor2x`: Doubles label size and removes minor feature labels.
61
+ *
62
+ * `scaleFactor4x`: Quadruples label size and removes minor feature labels.
63
+ * @beta
64
+ * */
65
+ scale?: GoogleMapsScaleFactors;
66
+ /**
67
+ * A boolean value that specifies whether layerTypes should be rendered as a separate overlay, or combined with the base imagery.
68
+ * When true, the base map isn't displayed. If you haven't defined any layerTypes, then this value is ignored.
69
+ * Default is false.
70
+ * @beta
71
+ * */
72
+ overlay?: boolean;
73
+ /**
74
+ * An array of values specifying additional options to apply.
75
+ * @beta
76
+ * */
77
+ apiOptions?: string[];
78
+ }
79
+ /**
80
+ * Structure representing a Google Maps session.
81
+ * @beta
82
+ */
83
+ export interface GoogleMapsSession {
84
+ /** A session token value that you must include in all of your Map Tiles API requests. */
85
+ session: string;
86
+ /** 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. */
87
+ expiry: number;
88
+ /** The width of the tiles measured in pixels. */
89
+ tileWidth: number;
90
+ /** he height of the tiles measured in pixels. */
91
+ tileHeight: number;
92
+ /** The image format, which can be either `png` or `jpeg`. */
93
+ imageFormat: string;
94
+ }
95
+ /**
96
+ * Represents the maximum zoom level available within a bounding rectangle.
97
+ * @beta
98
+ */
99
+ export interface MaxZoomRectangle {
100
+ maxZoom: number;
101
+ north: number;
102
+ south: number;
103
+ east: number;
104
+ west: number;
105
+ }
106
+ /**
107
+ * Indicate which areas of given viewport have imagery, and at which zoom levels.
108
+ * @beta
109
+ */
110
+ export interface ViewportInfo {
111
+ /** Attribution string that you must display on your map when you display roadmap and satellite tiles. */
112
+ copyright: string;
113
+ /** Array of bounding rectangles that overlap with the current viewport. Also contains the maximum zoom level available within each rectangle.. */
114
+ maxZoomRects: MaxZoomRectangle[];
115
+ }
116
+ /**
117
+ * Request parameters for the getViewportInfo method.
118
+ * @beta
119
+ */
120
+ export interface ViewportInfoRequestParams {
121
+ /** Bounding rectangle */
122
+ rectangle: MapCartoRectangle;
123
+ /** Session token */
124
+ session: string;
125
+ /** The Google Cloud API key */
126
+ key: string;
127
+ /** Zoom level of the viewport */
128
+ zoom: number;
129
+ }
130
+ /**
131
+ * Google Maps API
132
+ * @beta
133
+ */
134
+ export declare const GoogleMaps: {
135
+ /**
136
+ * Creates Google Maps map-layer settings.
137
+ * @param name Name of the layer (Defaults to "GoogleMaps")
138
+ * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)
139
+ *
140
+ * The following examples illustrates how a Googles Map layer can be attached to a viewport:
141
+ * ```ts
142
+ * [[include:GoogleMaps_AttachMapLayerSimple]]
143
+ * ```
144
+ * ```ts
145
+ * [[include:GoogleMaps_AttachMapLayerOpts]]
146
+ * ```
147
+ * @beta
148
+ */
149
+ createMapLayerSettings: (name?: string, opts?: GoogleMapsCreateSessionOptions) => ImageMapLayerSettings;
150
+ /**
151
+ * Creates Google Maps base layer settings.
152
+ * @param name Name of the layer (Defaults to "GoogleMaps")
153
+ * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)
154
+ *
155
+ * The following examples illustrates how a Google Maps base layer can be set on a viewport:
156
+ * ```ts
157
+ * [[include:GoogleMaps_BaseMapSimple]]
158
+ * ```
159
+ * ```ts
160
+ * [[include:GoogleMaps_BaseMapOpts]]
161
+ * ```
162
+ * @beta
163
+ */
164
+ createBaseLayerSettings: (opts?: GoogleMapsCreateSessionOptions) => BaseMapLayerSettings;
165
+ };
166
+ //# sourceMappingURL=GoogleMaps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMaps.d.ts","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMaps.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAIzD;;UAEU;AACV,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG,iBAAiB,CAAC;AAEtE;;;KAGK;AACL,MAAM,MAAM,kBAAkB,GAAI,SAAS,GAAC,WAAW,GAAC,SAAS,CAAC;AAElE;;;KAGK;AACL,MAAM,MAAM,sBAAsB,GAAI,eAAe,GAAG,eAAe,GAAG,eAAe,CAAC;AAE1F;;;EAGE;AACF,MAAM,WAAW,8BAA8B;IAC3C;;;;;;;;;OASG;IACL,OAAO,EAAE,kBAAkB,CAAC;IAC5B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACf;;MAEE;IACJ,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;;;SAQK;IACL,UAAU,CAAC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------------------------
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
+ import { BaseMapLayerSettings, ImageMapLayerSettings } from "@itwin/core-common";
9
+ import { GoogleMapsUtils } from "../internal/GoogleMapsUtils";
10
+ ;
11
+ ;
12
+ /**
13
+ * Google Maps API
14
+ * @beta
15
+ */
16
+ // eslint-disable-next-line @typescript-eslint/naming-convention
17
+ export const GoogleMaps = {
18
+ /**
19
+ * Creates Google Maps map-layer settings.
20
+ * @param name Name of the layer (Defaults to "GoogleMaps")
21
+ * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)
22
+ *
23
+ * The following examples illustrates how a Googles Map layer can be attached to a viewport:
24
+ * ```ts
25
+ * [[include:GoogleMaps_AttachMapLayerSimple]]
26
+ * ```
27
+ * ```ts
28
+ * [[include:GoogleMaps_AttachMapLayerOpts]]
29
+ * ```
30
+ * @beta
31
+ */
32
+ createMapLayerSettings: (name, opts) => {
33
+ return ImageMapLayerSettings.fromJSON(GoogleMapsUtils.createMapLayerProps(name, opts));
34
+ },
35
+ /**
36
+ * Creates Google Maps base layer settings.
37
+ * @param name Name of the layer (Defaults to "GoogleMaps")
38
+ * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)
39
+ *
40
+ * The following examples illustrates how a Google Maps base layer can be set on a viewport:
41
+ * ```ts
42
+ * [[include:GoogleMaps_BaseMapSimple]]
43
+ * ```
44
+ * ```ts
45
+ * [[include:GoogleMaps_BaseMapOpts]]
46
+ * ```
47
+ * @beta
48
+ */
49
+ createBaseLayerSettings: (opts) => {
50
+ return BaseMapLayerSettings.fromJSON(GoogleMapsUtils.createMapLayerProps("GoogleMaps", opts));
51
+ }
52
+ };
53
+ //# sourceMappingURL=GoogleMaps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMaps.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMaps.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAEH,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEjF,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAkF7D,CAAC;AAqBD,CAAC;AA4CF;;;EAGE;AACF,gEAAgE;AAChE,MAAM,CAAC,MAAM,UAAU,GAAG;IAC1B;;;;;;;;;;;;;MAaE;IACA,sBAAsB,EAAE,CAAC,IAAa,EAAE,IAAqC,EAAE,EAAE;QAC/E,OAAO,qBAAqB,CAAC,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACzF,CAAC;IAEH;;;;;;;;;;;;;MAaE;IACA,uBAAuB,EAAE,CAAC,IAAqC,EAAE,EAAE;QACjE,OAAO,oBAAoB,CAAC,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,CAAC;IAChG,CAAC;CACF,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/** @packageDocumentation\n * @module MapLayersFormats\n */\n\nimport { BaseMapLayerSettings, ImageMapLayerSettings } from \"@itwin/core-common\";\nimport { MapCartoRectangle } from \"@itwin/core-frontend\";\nimport { GoogleMapsUtils } from \"../internal/GoogleMapsUtils\";\n\n\n/**\n * The type of base map.\n * @beta*/\nexport type GoogleMapsLayerTypes = \"layerRoadmap\" | \"layerStreetview\";\n\n/**\n * Layer types that can be added to the map.\n * @beta\n * */\nexport type GoogleMapsMapTypes = \"roadmap\"|\"satellite\"|\"terrain\";\n\n/**\n * Scale factors that can be applied to labels and objects in the map.\n * @beta\n * */\nexport type GoogleMapsScaleFactors = \"scaleFactor1x\" | \"scaleFactor2x\" | \"scaleFactor4x\";\n\n/**\n* Represents the options to create a Google Maps session.\n* @beta\n*/\nexport interface GoogleMapsCreateSessionOptions {\n /**\n * The type of base map.\n *\n * `roadmap`: The standard Google Maps painted map tiles.\n *\n * `satellite`: Satellite imagery.\n *\n * `terrain`: Terrain imagery. When selecting `terrain` as the map type, you must also include the `layerRoadmap` layer type.\n * @beta\n * */\n mapType: GoogleMapsMapTypes,\n /**\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.\n */\n language: string;\n /**\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`.\n */\n region: string;\n\n /**\n * An array of values that specifies the layer types added to the map.\n *\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.\n *\n * `layerStreetview`: Shows Street View-enabled streets and locations using blue outlines on the map.\n *\n * @beta\n * */\n layerTypes?: GoogleMapsLayerTypes[];\n\n /**\n * Scales-up the size of map elements (such as road labels), while retaining the tile size and coverage area of the default tile.\n * Increasing the scale also reduces the number of labels on the map, which reduces clutter.\n *\n * `scaleFactor1x`: The default.\n *\n * `scaleFactor2x`: Doubles label size and removes minor feature labels.\n *\n * `scaleFactor4x`: Quadruples label size and removes minor feature labels.\n * @beta\n * */\n scale?: GoogleMapsScaleFactors\n\n /**\n * A boolean value that specifies whether layerTypes should be rendered as a separate overlay, or combined with the base imagery.\n * When true, the base map isn't displayed. If you haven't defined any layerTypes, then this value is ignored.\n * Default is false.\n * @beta\n * */\n overlay? : boolean;\n\n /**\n * An array of values specifying additional options to apply.\n * @beta\n * */\n apiOptions?: string[];\n};\n\n/**\n* Structure representing a Google Maps session.\n* @beta\n*/\nexport interface GoogleMapsSession {\n /** A session token value that you must include in all of your Map Tiles API requests. */\n session: string;\n\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. */\n expiry: number;\n\n /** The width of the tiles measured in pixels. */\n tileWidth: number;\n\n /** he height of the tiles measured in pixels. */\n tileHeight: number;\n\n /** The image format, which can be either `png` or `jpeg`. */\n imageFormat: string;\n};\n\n/**\n * Represents the maximum zoom level available within a bounding rectangle.\n* @beta\n*/\nexport interface MaxZoomRectangle {\n maxZoom: number;\n north: number;\n south: number;\n east: number;\n west: number;\n}\n\n/**\n * Indicate which areas of given viewport have imagery, and at which zoom levels.\n * @beta\n*/\nexport interface ViewportInfo {\n /** Attribution string that you must display on your map when you display roadmap and satellite tiles. */\n copyright: string;\n\n /** Array of bounding rectangles that overlap with the current viewport. Also contains the maximum zoom level available within each rectangle.. */\n maxZoomRects: MaxZoomRectangle[];\n}\n\n/**\n * Request parameters for the getViewportInfo method.\n * @beta\n*/\nexport interface ViewportInfoRequestParams {\n /** Bounding rectangle */\n rectangle: MapCartoRectangle;\n\n /** Session token */\n session: string;\n\n /** The Google Cloud API key */\n key: string;\n\n /** Zoom level of the viewport */\n zoom: number;\n}\n\n/**\n * Google Maps API\n * @beta\n*/\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const GoogleMaps = {\n/**\n * Creates Google Maps map-layer settings.\n * @param name Name of the layer (Defaults to \"GoogleMaps\")\n * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)\n *\n * The following examples illustrates how a Googles Map layer can be attached to a viewport:\n * ```ts\n * [[include:GoogleMaps_AttachMapLayerSimple]]\n * ```\n * ```ts\n * [[include:GoogleMaps_AttachMapLayerOpts]]\n * ```\n * @beta\n*/\n createMapLayerSettings: (name?: string, opts?: GoogleMapsCreateSessionOptions) => {\n return ImageMapLayerSettings.fromJSON(GoogleMapsUtils.createMapLayerProps(name, opts));\n },\n\n/**\n * Creates Google Maps base layer settings.\n * @param name Name of the layer (Defaults to \"GoogleMaps\")\n * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)\n *\n * The following examples illustrates how a Google Maps base layer can be set on a viewport:\n * ```ts\n * [[include:GoogleMaps_BaseMapSimple]]\n * ```\n * ```ts\n * [[include:GoogleMaps_BaseMapOpts]]\n * ```\n * @beta\n*/\n createBaseLayerSettings: (opts?: GoogleMapsCreateSessionOptions) => {\n return BaseMapLayerSettings.fromJSON(GoogleMapsUtils.createMapLayerProps(\"GoogleMaps\", opts));\n }\n};"]}
@@ -0,0 +1,10 @@
1
+ /** @packageDocumentation
2
+ * @module MapLayersFormats
3
+ */
4
+ import { ImageMapLayerSettings } from "@itwin/core-common";
5
+ import { ImageryMapLayerFormat, MapLayerImageryProvider } from "@itwin/core-frontend";
6
+ export declare class GoogleMapsMapLayerFormat extends ImageryMapLayerFormat {
7
+ static formatId: string;
8
+ static createImageryProvider(settings: ImageMapLayerSettings): MapLayerImageryProvider | undefined;
9
+ }
10
+ //# sourceMappingURL=GoogleMapsImageryFormat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsImageryFormat.d.ts","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryFormat.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGtF,qBAAa,wBAAyB,SAAQ,qBAAqB;IACjE,OAAuB,QAAQ,SAAgB;WACxB,qBAAqB,CAAC,QAAQ,EAAE,qBAAqB,GAAG,uBAAuB,GAAG,SAAS;CAGnH"}
@@ -0,0 +1,16 @@
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
+ import { ImageryMapLayerFormat } from "@itwin/core-frontend";
9
+ import { GoogleMapsImageryProvider } from "./GoogleMapsImageryProvider";
10
+ export class GoogleMapsMapLayerFormat extends ImageryMapLayerFormat {
11
+ static formatId = "GoogleMaps";
12
+ static createImageryProvider(settings) {
13
+ return new GoogleMapsImageryProvider(settings);
14
+ }
15
+ }
16
+ //# sourceMappingURL=GoogleMapsImageryFormat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsImageryFormat.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryFormat.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAE,qBAAqB,EAA2B,MAAM,sBAAsB,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AAExE,MAAM,OAAO,wBAAyB,SAAQ,qBAAqB;IAC1D,MAAM,CAAU,QAAQ,GAAG,YAAY,CAAC;IACxC,MAAM,CAAU,qBAAqB,CAAC,QAA+B;QAC1E,OAAO,IAAI,yBAAyB,CAAC,QAAQ,CAAC,CAAC;IACjD,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/** @packageDocumentation\n * @module MapLayersFormats\n */\n\nimport { ImageMapLayerSettings } from \"@itwin/core-common\";\nimport { ImageryMapLayerFormat, MapLayerImageryProvider } from \"@itwin/core-frontend\";\nimport { GoogleMapsImageryProvider } from \"./GoogleMapsImageryProvider\";\n\nexport class GoogleMapsMapLayerFormat extends ImageryMapLayerFormat {\n public static override formatId = \"GoogleMaps\";\n public static override createImageryProvider(settings: ImageMapLayerSettings): MapLayerImageryProvider | undefined {\n return new GoogleMapsImageryProvider(settings);\n }\n}\n"]}
@@ -0,0 +1,25 @@
1
+ /** @packageDocumentation
2
+ * @module MapLayersFormats
3
+ */
4
+ import { ImageMapLayerSettings, ImageSource } from "@itwin/core-common";
5
+ import { DecorateContext, MapLayerImageryProvider, MapLayerSourceValidation, ScreenViewport } from "@itwin/core-frontend";
6
+ import { GoogleMapsSession } from "./GoogleMaps";
7
+ export declare class GoogleMapsImageryProvider extends MapLayerImageryProvider {
8
+ private _decorator;
9
+ private _hadUnrecoverableError;
10
+ private _tileSize;
11
+ constructor(settings: ImageMapLayerSettings);
12
+ static validateUrlTemplate(template: string): MapLayerSourceValidation;
13
+ protected createSession(): Promise<GoogleMapsSession | undefined>;
14
+ get tileSize(): number;
15
+ initialize(): Promise<void>;
16
+ private createCreateSessionOptions;
17
+ constructUrl(row: number, column: number, level: number): Promise<string>;
18
+ private fetchAttributions;
19
+ private logJsonError;
20
+ loadTile(row: number, column: number, zoomLevel: number): Promise<ImageSource | undefined>;
21
+ decorate(context: DecorateContext): void;
22
+ private getSelectedTiles;
23
+ addAttributions(cards: HTMLTableElement, vp: ScreenViewport): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=GoogleMapsImageryProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsImageryProvider.d.ts","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,qBAAqB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAgC,uBAAuB,EAAwB,wBAAwB,EAAW,cAAc,EAAQ,MAAM,sBAAsB,CAAC;AAC7L,OAAO,EAAoG,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAenJ,qBAAa,yBAA0B,SAAQ,uBAAuB;IAEpE,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,sBAAsB,CAAS;IACvC,OAAO,CAAC,SAAS,CAAM;gBACX,QAAQ,EAAE,qBAAqB;WAI7B,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,wBAAwB;cAI7D,aAAa,IAAK,OAAO,CAAC,iBAAiB,GAAC,SAAS,CAAC;IAYtE,IAAoB,QAAQ,IAAI,MAAM,CAA2B;IAE3C,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA4BjD,OAAO,CAAC,0BAA0B;IAoCrB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;YAWxE,iBAAiB;YAqCjB,YAAY;IASJ,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC;IA0ChG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI;IAIxD,OAAO,CAAC,gBAAgB;IAIF,eAAe,CAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAuBnG"}
@@ -0,0 +1,228 @@
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
+ import { IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapLayerSourceStatus, MapTile } from "@itwin/core-frontend";
9
+ import { BentleyError, BentleyStatus, Logger } from "@itwin/core-bentley";
10
+ import { GoogleMapsDecorator } from "./GoogleMapDecorator";
11
+ import { GoogleMapsUtils } from "../internal/GoogleMapsUtils";
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
+ /*
18
+ * Google Maps imagery provider
19
+ * @internal
20
+ */
21
+ export class GoogleMapsImageryProvider extends MapLayerImageryProvider {
22
+ _decorator;
23
+ _hadUnrecoverableError = false;
24
+ _tileSize = 256;
25
+ constructor(settings) {
26
+ super(settings, true);
27
+ 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
+ }
44
+ }
45
+ get tileSize() { return this._tileSize; }
46
+ 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";
53
+ Logger.logError(loggerCategory, msg);
54
+ throw new BentleyError(BentleyStatus.ERROR, msg);
55
+ }
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);
61
+ }
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`;
66
+ Logger.logError(loggerCategory, msg);
67
+ throw new BentleyError(BentleyStatus.ERROR, msg);
68
+ }
69
+ }
70
+ createCreateSessionOptions() {
71
+ const layerPropertyKeys = this._settings.properties ? Object.keys(this._settings.properties) : undefined;
72
+ if (layerPropertyKeys === undefined ||
73
+ !layerPropertyKeys.includes("mapType") ||
74
+ !layerPropertyKeys.includes("language") ||
75
+ !layerPropertyKeys.includes("region")) {
76
+ const msg = "Missing session options";
77
+ Logger.logError(loggerCategory, msg);
78
+ throw new BentleyError(BentleyStatus.ERROR, msg);
79
+ }
80
+ const createSessionOptions = {
81
+ mapType: this._settings.properties.mapType,
82
+ region: this._settings.properties.region,
83
+ language: this._settings.properties.language,
84
+ };
85
+ if (this._settings.properties?.layerTypes !== undefined) {
86
+ createSessionOptions.layerTypes = this._settings.properties.layerTypes;
87
+ }
88
+ if (this._settings.properties?.scale !== undefined) {
89
+ createSessionOptions.scale = this._settings.properties.scale;
90
+ }
91
+ if (this._settings.properties?.overlay !== undefined) {
92
+ createSessionOptions.overlay = this._settings.properties.overlay;
93
+ }
94
+ if (this._settings.properties?.apiOptions !== undefined) {
95
+ createSessionOptions.apiOptions = this._settings.properties.apiOptions;
96
+ }
97
+ return createSessionOptions;
98
+ }
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());
108
+ }
109
+ async fetchAttributions(tiles) {
110
+ const zooms = new Set();
111
+ const matchingAttributions = [];
112
+ // Viewport info requests must be made for a specific zoom level
113
+ tiles.forEach((tile) => zooms.add(tile.depth));
114
+ for (const zoom of zooms) {
115
+ let cartoRect;
116
+ for (const tile of tiles) {
117
+ if (tile.depth === zoom && tile instanceof MapTile) {
118
+ const extent = this.getEPSG4326Extent(tile.quadId.row, tile.quadId.column, tile.depth);
119
+ const rect = MapCartoRectangle.fromDegrees(extent.longitudeLeft, extent.latitudeBottom, extent.longitudeRight, extent.latitudeTop);
120
+ if (cartoRect)
121
+ cartoRect.union(rect);
122
+ else
123
+ cartoRect = rect;
124
+ }
125
+ }
126
+ if (cartoRect) {
127
+ 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
+ });
134
+ if (viewportInfo?.copyright) {
135
+ matchingAttributions.push(viewportInfo.copyright);
136
+ }
137
+ }
138
+ catch (error) {
139
+ Logger.logError(loggerCategory, `Error while loading viewport info: ${error?.message ?? "Unknown error"}`);
140
+ }
141
+ }
142
+ }
143
+ return matchingAttributions;
144
+ }
145
+ async logJsonError(tileResponse) {
146
+ try {
147
+ const error = await tileResponse.json();
148
+ Logger.logError(loggerCategory, `Error while loading tile: ${error?.message}`);
149
+ }
150
+ catch {
151
+ Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);
152
+ }
153
+ }
154
+ async loadTile(row, column, zoomLevel) {
155
+ if (this._hadUnrecoverableError)
156
+ return undefined;
157
+ try {
158
+ let tileUrl = await this.constructUrl(row, column, zoomLevel);
159
+ let tileResponse = await this.makeTileRequest(tileUrl);
160
+ 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);
167
+ if (!tileResponse.ok) {
168
+ if (tileResponse.headers.get("content-type")?.includes("application/json")) {
169
+ await this.logJsonError(tileResponse);
170
+ }
171
+ else {
172
+ Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);
173
+ }
174
+ this._hadUnrecoverableError = true; // Prevent from doing more invalid requests
175
+ return undefined;
176
+ }
177
+ }
178
+ else {
179
+ await this.logJsonError(tileResponse);
180
+ }
181
+ }
182
+ else {
183
+ Logger.logError(loggerCategory, `Error while loading tile: ${tileResponse.statusText}`);
184
+ return undefined;
185
+ }
186
+ }
187
+ return await this.getImageFromTileResponse(tileResponse, zoomLevel);
188
+ }
189
+ catch (error) {
190
+ if (error?.code === 401) {
191
+ Logger.logError(loggerCategory, `Authorize to load tile: ${error.message}`);
192
+ }
193
+ else {
194
+ Logger.logError(loggerCategory, `Error while loading tile: ${error.message}`);
195
+ }
196
+ return undefined;
197
+ }
198
+ }
199
+ decorate(context) {
200
+ this._decorator.decorate(context);
201
+ }
202
+ getSelectedTiles(vp) {
203
+ return IModelApp.tileAdmin.getTilesForUser(vp)?.selected;
204
+ }
205
+ async addAttributions(cards, vp) {
206
+ let copyrightMsg = "";
207
+ const tiles = this.getSelectedTiles(vp);
208
+ if (tiles) {
209
+ try {
210
+ const attrList = await this.fetchAttributions(tiles);
211
+ for (const attr of attrList) {
212
+ attr.split(",").forEach((line) => {
213
+ copyrightMsg += `${copyrightMsg.length === 0 ? "" : "<br"}${line}`;
214
+ });
215
+ }
216
+ }
217
+ catch (error) {
218
+ Logger.logError(loggerCategory, `Error while loading attributions: ${error?.message ?? "Unknown error"}`);
219
+ }
220
+ }
221
+ cards.appendChild(IModelApp.makeLogoCard({
222
+ iconSrc: `${IModelApp.publicPath}images/google_on_white_hdpi.png`,
223
+ heading: "Google Maps",
224
+ notice: copyrightMsg
225
+ }));
226
+ }
227
+ }
228
+ //# sourceMappingURL=GoogleMapsImageryProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsImageryProvider.js","sourceRoot":"","sources":["../../../src/GoogleMaps/GoogleMapsImageryProvider.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F;;GAEG;AAGH,OAAO,EAAmB,SAAS,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAoB,EAA4B,OAAO,EAAwB,MAAM,sBAAsB,CAAC;AAE7L,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,M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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 { ImageMapLayerSettings, ImageSource } from \"@itwin/core-common\";\nimport { DecorateContext, IModelApp, MapCartoRectangle, MapLayerImageryProvider, MapLayerSourceStatus, MapLayerSourceValidation, MapTile, ScreenViewport, Tile } from \"@itwin/core-frontend\";\nimport { GoogleMapsCreateSessionOptions, GoogleMapsLayerTypes, GoogleMapsMapTypes, GoogleMapsScaleFactors, GoogleMapsSession } from \"./GoogleMaps\";\nimport { BentleyError, BentleyStatus, Logger } from \"@itwin/core-bentley\";\nimport { GoogleMapsDecorator } from \"./GoogleMapDecorator\";\nimport { GoogleMapsUtils } from \"../internal/GoogleMapsUtils\";\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"]}
@@ -0,0 +1,38 @@
1
+ import { ImageMapLayerProps, MapLayerProviderProperties } from "@itwin/core-common";
2
+ import { GoogleMapsCreateSessionOptions, GoogleMapsSession, ViewportInfo, ViewportInfoRequestParams } from "../GoogleMaps/GoogleMaps";
3
+ /** @internal */
4
+ export declare const GoogleMapsUtils: {
5
+ /**
6
+ * Creates a Google Maps session.
7
+ * @param apiKey Google Cloud API key
8
+ * @param opts Options to create the session
9
+ * @internal
10
+ */
11
+ createSession: (apiKey: string, opts: GoogleMapsCreateSessionOptions) => Promise<GoogleMapsSession>;
12
+ /**
13
+ * Register the google maps format if it is not already registered.
14
+ * @internal
15
+ */
16
+ checkFormatRegistered: () => void;
17
+ /**
18
+ * Creates a Google Maps layer props.
19
+ * @param name Name of the layer (Defaults to "GoogleMaps")
20
+ * @param opts Options to create the session (Defaults to satellite map type, English language, US region, and roadmap layer type)
21
+ * @internal
22
+ */
23
+ createMapLayerProps: (name?: string, opts?: GoogleMapsCreateSessionOptions) => ImageMapLayerProps;
24
+ /**
25
+ * Retrieves the maximum zoom level available within a bounding rectangle.
26
+ * @param rectangle The bounding rectangle
27
+ * @returns The maximum zoom level available within the bounding rectangle.
28
+ * @internal
29
+ */
30
+ getViewportInfo: (params: ViewportInfoRequestParams) => Promise<ViewportInfo | undefined>;
31
+ /**
32
+ * Converts the session options to provider properties
33
+ * @param opts Options to create the session
34
+ * @internal
35
+ */
36
+ createPropertiesFromSessionOptions: (opts: GoogleMapsCreateSessionOptions) => MapLayerProviderProperties;
37
+ };
38
+ //# sourceMappingURL=GoogleMapsUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GoogleMapsUtils.d.ts","sourceRoot":"","sources":["../../../src/internal/GoogleMapsUtils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAEpF,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,0BAA0B,CAAC;AAItI,gBAAgB;AAEhB,eAAO,MAAM,eAAe;IAC1B;;;;;MAKE;4BAC4B,MAAM,QAAQ,8BAA8B,KAAG,OAAO,CAAC,iBAAiB,CAAC;IAWvG;;;MAGE;;IAOF;;;;;IAKA;iCAC4B,MAAM,SAAwB,8BAA8B,KAAG,kBAAkB;IAW7G;;;;;MAKE;8BAC8B,yBAAyB,KAAG,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC;IAgB3F;;;;IAIA;+CACyC,8BAA8B,KAAG,0BAA0B;CAyBvG,CAAA"}