ol 9.0.1-dev.1709147539193 → 9.0.1-dev.1709292731025

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol",
3
- "version": "9.0.1-dev.1709147539193",
3
+ "version": "9.0.1-dev.1709292731025",
4
4
  "description": "OpenLayers mapping library",
5
5
  "keywords": [
6
6
  "map",
@@ -40,10 +40,6 @@ export type Options = {
40
40
  * [Custom styles](https://developers.google.com/maps/documentation/tile/style-reference) applied to the map.
41
41
  */
42
42
  styles?: any[] | undefined;
43
- /**
44
- * Attributions.
45
- */
46
- attributions?: import("./Source.js").AttributionLike | undefined;
47
43
  /**
48
44
  * Use interpolated values when resampling. By default,
49
45
  * linear interpolation is used when resampling. Set to false to use the nearest neighbor instead.
@@ -154,7 +150,6 @@ export type SessionTokenResponse = {
154
150
  * @property {Array<string>} [layerTypes] The layer types added to the map (e.g. `'layerRoadmap'`, `'layerStreetview'`, or `'layerTraffic'`).
155
151
  * @property {boolean} [overlay=false] Display only the `layerTypes` and not the underlying `mapType` (only works if `layerTypes` is provided).
156
152
  * @property {Array<Object>} [styles] [Custom styles](https://developers.google.com/maps/documentation/tile/style-reference) applied to the map.
157
- * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
158
153
  * @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
159
154
  * linear interpolation is used when resampling. Set to false to use the nearest neighbor instead.
160
155
  * @property {number} [cacheSize] Initial tile cache size. Will auto-grow to hold at least the number of tiles in the viewport.
@@ -220,11 +215,26 @@ declare class Google extends TileImage {
220
215
  * @private
221
216
  */
222
217
  private sessionTokenRequest_;
218
+ /**
219
+ * @type {string}
220
+ * @private
221
+ */
222
+ private sessionTokenValue_;
223
223
  /**
224
224
  * @type {ReturnType<typeof setTimeout>}
225
225
  * @private
226
226
  */
227
227
  private sessionRefreshId_;
228
+ /**
229
+ * @type {string}
230
+ * @private
231
+ */
232
+ private previousViewportAttribution_;
233
+ /**
234
+ * @type {string}
235
+ * @private
236
+ */
237
+ private previousViewportExtent_;
228
238
  /**
229
239
  * @return {Error|null} A source loading error. When the source state is `error`, use this function
230
240
  * to get more information about the error. To debug a faulty configuration, you may want to use
@@ -250,6 +260,7 @@ declare class Google extends TileImage {
250
260
  * @private
251
261
  */
252
262
  private createSession_;
263
+ fetchAttributions(frameState: any): Promise<string>;
253
264
  }
254
265
  import TileImage from './TileImage.js';
255
266
  //# sourceMappingURL=Google.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Google.d.ts","sourceRoot":"","sources":["Google.js"],"names":[],"mappings":";;;;;SAmBc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAgCN,MAAM;;;;cACN,MAAM;;;;YACN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAWN,MAAM;;;;YACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM;;AAnDpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EA0EjB;IAnDC;;;OAGG;IACH,gBAA0B;IAE1B;;OAEG;IACH,QAFU,KAAK,GAAC,IAAI,CAEF;IA6BlB;;;OAGG;IACH,6BAA+C;IAE/C;;;OAGG;IACH,0BAAsB;IAKxB;;;;;;;;;;;OAWG;IACH,YAXY,KAAK,GAAC,IAAI,CAarB;IAED;;;;;OAKG;IACH,uBAJW,MAAM,UACN,WAAW,GACV,QAAQ,QAAQ,CAAC,CAI5B;IAED;;;OAGG;IACH,uBAuDC;CAMF;sBApPqB,gBAAgB"}
1
+ {"version":3,"file":"Google.d.ts","sourceRoot":"","sources":["Google.js"],"names":[],"mappings":";;;;;SAiBc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aA+BN,MAAM;;;;cACN,MAAM;;;;YACN,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAWN,MAAM;;;;YACN,MAAM;;;;eACN,MAAM;;;;gBACN,MAAM;;;;iBACN,MAAM;;AAlDpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AACH;IACE;;OAEG;IACH,qBAFW,OAAO,EA2FjB;IArEC;;;OAGG;IACH,gBAA0B;IAE1B;;OAEG;IACH,QAFU,KAAK,GAAC,IAAI,CAEF;IA6BlB;;;OAGG;IACH,6BAA+C;IAE/C;;;OAGG;IACH,2BAAuB;IAEvB;;;OAGG;IACH,0BAAsB;IAEtB;;;OAGG;IACH,qCAAiC;IAEjC;;;OAGG;IACH,gCAA4B;IAK9B;;;;;;;;;;;OAWG;IACH,YAXY,KAAK,GAAC,IAAI,CAarB;IAED;;;;;OAKG;IACH,uBAJW,MAAM,UACN,WAAW,GACV,QAAQ,QAAQ,CAAC,CAI5B;IAED;;;OAGG;IACH,uBAyDC;IAED,oDAmCC;CAMF;sBAzSqB,gBAAgB"}
package/source/Google.js CHANGED
@@ -3,16 +3,14 @@
3
3
  */
4
4
 
5
5
  import TileImage from './TileImage.js';
6
+ import ViewHint from '../ViewHint.js';
6
7
  import {createXYZ, extentFromProjection} from '../tilegrid.js';
7
-
8
- const defaultAttribution =
9
- 'Google Maps' +
10
- '<a class="ol-attribution-google-tos" href="https://cloud.google.com/maps-platform/terms/" target="_blank">Terms of Use</a>' +
11
- ' and ' +
12
- '<a class="ol-attribution-google-tos" href="https://policies.google.com/privacy" target="_blank">Privacy Policy</a>';
8
+ import {getBottomLeft, getTopRight} from '../extent.js';
9
+ import {toLonLat} from '../proj.js';
13
10
 
14
11
  const createSessionUrl = 'https://tile.googleapis.com/v1/createSession';
15
12
  const tileUrl = 'https://tile.googleapis.com/v1/2dtiles';
13
+ const attributionUrl = 'https://tile.googleapis.com/tile/v1/viewport';
16
14
  const maxZoom = 22;
17
15
 
18
16
  /**
@@ -27,7 +25,6 @@ const maxZoom = 22;
27
25
  * @property {Array<string>} [layerTypes] The layer types added to the map (e.g. `'layerRoadmap'`, `'layerStreetview'`, or `'layerTraffic'`).
28
26
  * @property {boolean} [overlay=false] Display only the `layerTypes` and not the underlying `mapType` (only works if `layerTypes` is provided).
29
27
  * @property {Array<Object>} [styles] [Custom styles](https://developers.google.com/maps/documentation/tile/style-reference) applied to the map.
30
- * @property {import("./Source.js").AttributionLike} [attributions] Attributions.
31
28
  * @property {boolean} [interpolate=true] Use interpolated values when resampling. By default,
32
29
  * linear interpolation is used when resampling. Set to false to use the nearest neighbor instead.
33
30
  * @property {number} [cacheSize] Initial tile cache size. Will auto-grow to hold at least the number of tiles in the viewport.
@@ -84,10 +81,9 @@ class Google extends TileImage {
84
81
  constructor(options) {
85
82
  const highDpi = !!options.highDpi;
86
83
  const opaque = !(options.overlay === true);
87
- const attributions = options.attributions || [defaultAttribution];
88
84
 
89
85
  super({
90
- attributions: attributions,
86
+ attributionsCollapsible: false,
91
87
  cacheSize: options.cacheSize,
92
88
  crossOrigin: 'anonymous',
93
89
  interpolate: options.interpolate,
@@ -146,12 +142,30 @@ class Google extends TileImage {
146
142
  */
147
143
  this.sessionTokenRequest_ = sessionTokenRequest;
148
144
 
145
+ /**
146
+ * @type {string}
147
+ * @private
148
+ */
149
+ this.sessionTokenValue_;
150
+
149
151
  /**
150
152
  * @type {ReturnType<typeof setTimeout>}
151
153
  * @private
152
154
  */
153
155
  this.sessionRefreshId_;
154
156
 
157
+ /**
158
+ * @type {string}
159
+ * @private
160
+ */
161
+ this.previousViewportAttribution_;
162
+
163
+ /**
164
+ * @type {string}
165
+ * @private
166
+ */
167
+ this.previousViewportExtent_;
168
+
155
169
  this.createSession_();
156
170
  }
157
171
 
@@ -225,6 +239,7 @@ class Google extends TileImage {
225
239
  });
226
240
 
227
241
  const session = sessionTokenResponse.session;
242
+ this.sessionTokenValue_ = session;
228
243
  const key = this.apiKey_;
229
244
  this.tileUrlFunction = function (tileCoord, pixelRatio, projection) {
230
245
  const z = tileCoord[0];
@@ -238,10 +253,48 @@ class Google extends TileImage {
238
253
  const timeout = Math.max(expiry - Date.now() - 60 * 1000, 1);
239
254
  this.sessionRefreshId_ = setTimeout(() => this.createSession_(), timeout);
240
255
 
256
+ this.setAttributions(this.fetchAttributions.bind(this));
241
257
  // even if the state is already ready, we want the change event
242
258
  this.setState('ready');
243
259
  }
244
260
 
261
+ async fetchAttributions(frameState) {
262
+ if (
263
+ frameState.viewHints[ViewHint.ANIMATING] ||
264
+ frameState.viewHints[ViewHint.INTERACTING] ||
265
+ frameState.animate
266
+ ) {
267
+ return this.previousViewportAttribution_;
268
+ }
269
+ const [west, south] = toLonLat(
270
+ getBottomLeft(frameState.extent),
271
+ frameState.viewState.projection,
272
+ );
273
+ const [east, north] = toLonLat(
274
+ getTopRight(frameState.extent),
275
+ frameState.viewState.projection,
276
+ );
277
+ const tileGrid = this.getTileGrid();
278
+ const zoom = tileGrid.getZForResolution(
279
+ frameState.viewState.resolution,
280
+ this.zDirection,
281
+ );
282
+ const viewportExtent = `zoom=${zoom}&north=${north}&south=${south}&east=${east}&west=${west}`;
283
+ // check if the extent or zoom has actually changed to avoid unnecessary requests
284
+ if (this.previousViewportExtent_ == viewportExtent) {
285
+ return this.previousViewportAttribution_;
286
+ }
287
+ this.previousViewportExtent_ = viewportExtent;
288
+ const session = this.sessionTokenValue_;
289
+ const key = this.apiKey_;
290
+ const url = `${attributionUrl}?session=${session}&key=${key}&${viewportExtent}`;
291
+ this.previousViewportAttribution_ = await fetch(url)
292
+ .then((response) => response.json())
293
+ .then((json) => json.copyright);
294
+
295
+ return this.previousViewportAttribution_;
296
+ }
297
+
245
298
  disposeInternal() {
246
299
  clearTimeout(this.sessionRefreshId_);
247
300
  super.disposeInternal();
package/util.js CHANGED
@@ -33,4 +33,4 @@ export function getUid(obj) {
33
33
  * OpenLayers version.
34
34
  * @type {string}
35
35
  */
36
- export const VERSION = '9.0.1-dev.1709147539193';
36
+ export const VERSION = '9.0.1-dev.1709292731025';