ol 6.9.1-dev.1635770722243 → 6.9.1-dev.1635943582793
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/layer/MapboxVector.d.ts +11 -5
- package/layer/MapboxVector.d.ts.map +1 -1
- package/layer/MapboxVector.js +29 -7
- package/layer/MapboxVector.js.map +1 -1
- package/package.json +1 -1
- package/src/layer/MapboxVector.js +41 -7
- package/util.js +1 -1
package/layer/MapboxVector.d.ts
CHANGED
|
@@ -33,10 +33,11 @@ export function normalizeStyleUrl(url: string, token: string): string;
|
|
|
33
33
|
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
34
34
|
* @param {string} url The source URL.
|
|
35
35
|
* @param {string} token The access token.
|
|
36
|
+
* @param {string} tokenParam The access token key.
|
|
36
37
|
* @return {string} A vector tile template.
|
|
37
38
|
* @private
|
|
38
39
|
*/
|
|
39
|
-
export function normalizeSourceUrl(url: string, token: string): string;
|
|
40
|
+
export function normalizeSourceUrl(url: string, token: string, tokenParam: string): string;
|
|
40
41
|
export default MapboxVectorLayer;
|
|
41
42
|
export type StyleObject = {
|
|
42
43
|
/**
|
|
@@ -67,6 +68,10 @@ export type SourceObject = {
|
|
|
67
68
|
* The source type.
|
|
68
69
|
*/
|
|
69
70
|
type: string;
|
|
71
|
+
/**
|
|
72
|
+
* TileJSON tiles.
|
|
73
|
+
*/
|
|
74
|
+
tiles?: string[];
|
|
70
75
|
};
|
|
71
76
|
/**
|
|
72
77
|
* The Mapbox source type.
|
|
@@ -91,8 +96,8 @@ export type Options = {
|
|
|
91
96
|
styleUrl: string;
|
|
92
97
|
/**
|
|
93
98
|
* The access token for your Mapbox style. This has to be provided
|
|
94
|
-
* for `mapbox://` style urls. For `https://` and other urls, access
|
|
95
|
-
* url.
|
|
99
|
+
* for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query
|
|
100
|
+
* parameter of the style url.
|
|
96
101
|
*/
|
|
97
102
|
accessToken?: string;
|
|
98
103
|
/**
|
|
@@ -230,8 +235,8 @@ export type Options = {
|
|
|
230
235
|
* style created with Mapbox Studio and hosted on Mapbox, this will look like
|
|
231
236
|
* 'mapbox://styles/you/your-style'.
|
|
232
237
|
* @property {string} [accessToken] The access token for your Mapbox style. This has to be provided
|
|
233
|
-
* for `mapbox://` style urls. For `https://` and other urls, access
|
|
234
|
-
* url.
|
|
238
|
+
* for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query
|
|
239
|
+
* parameter of the style url.
|
|
235
240
|
* @property {string} [source] If your style uses more than one source, you need to use either the
|
|
236
241
|
* `source` property or the `layers` property to limit rendering to a single vector source. The
|
|
237
242
|
* `source` property corresponds to the id of a vector source in your Mapbox style.
|
|
@@ -331,6 +336,7 @@ declare class MapboxVectorLayer extends VectorTileLayer {
|
|
|
331
336
|
sourceId: string;
|
|
332
337
|
layers: string[];
|
|
333
338
|
accessToken: string;
|
|
339
|
+
accessTokenParam_: string;
|
|
334
340
|
/**
|
|
335
341
|
* Fetch the style object.
|
|
336
342
|
* @param {string} styleUrl The URL of the style to load.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxVector.d.ts","sourceRoot":"","sources":["../src/layer/MapboxVector.js"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,mDAMC;AAED;;;;;;GAMG;AACH,uEAYC;AAED;;;;;;GAMG;AACH,uEAYC;AAED;;;;;;GAMG;AACH,sEAYC;AAED
|
|
1
|
+
{"version":3,"file":"MapboxVector.d.ts","sourceRoot":"","sources":["../src/layer/MapboxVector.js"],"names":[],"mappings":"AAaA;;;;;GAKG;AACH,mDAMC;AAED;;;;;;GAMG;AACH,uEAYC;AAED;;;;;;GAMG;AACH,uEAYC;AAED;;;;;;GAMG;AACH,sEAYC;AAED;;;;;;;GAOG;AACH,2FAWC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CD;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH;IACE;;;OAGG;IACH,8BA0CC;IAbC,iBAA8B;IAC9B,iBAA4B;IAE1B,oBAAsC;IAMpC,0BAA4B;IAMlC;;;;OAIG;IACH,6CAiBC;IAED;;;;OAIG;IACH,gDA0GC;IAED;;;;OAIG;IACH,0CAIC;CACF"}
|
package/layer/MapboxVector.js
CHANGED
|
@@ -98,13 +98,19 @@ export function normalizeStyleUrl(url, token) {
|
|
|
98
98
|
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
99
99
|
* @param {string} url The source URL.
|
|
100
100
|
* @param {string} token The access token.
|
|
101
|
+
* @param {string} tokenParam The access token key.
|
|
101
102
|
* @return {string} A vector tile template.
|
|
102
103
|
* @private
|
|
103
104
|
*/
|
|
104
|
-
export function normalizeSourceUrl(url, token) {
|
|
105
|
+
export function normalizeSourceUrl(url, token, tokenParam) {
|
|
105
106
|
var mapboxPath = getMapboxPath(url);
|
|
106
107
|
if (!mapboxPath) {
|
|
107
|
-
|
|
108
|
+
if (!token) {
|
|
109
|
+
return url;
|
|
110
|
+
}
|
|
111
|
+
var urlObject = new URL(url, location.href);
|
|
112
|
+
urlObject.searchParams.set(tokenParam, token);
|
|
113
|
+
return decodeURI(urlObject.href);
|
|
108
114
|
}
|
|
109
115
|
return "https://{a-d}.tiles.mapbox.com/v4/" + mapboxPath + "/{z}/{x}/{y}.vector.pbf?access_token=" + token;
|
|
110
116
|
}
|
|
@@ -138,6 +144,7 @@ var ErrorEvent = /** @class */ (function (_super) {
|
|
|
138
144
|
* @typedef {Object} SourceObject
|
|
139
145
|
* @property {string} url The source URL.
|
|
140
146
|
* @property {SourceType} type The source type.
|
|
147
|
+
* @property {Array<string>} [tiles] TileJSON tiles.
|
|
141
148
|
*/
|
|
142
149
|
/**
|
|
143
150
|
* The Mapbox source type.
|
|
@@ -157,8 +164,8 @@ var SourceType = {
|
|
|
157
164
|
* style created with Mapbox Studio and hosted on Mapbox, this will look like
|
|
158
165
|
* 'mapbox://styles/you/your-style'.
|
|
159
166
|
* @property {string} [accessToken] The access token for your Mapbox style. This has to be provided
|
|
160
|
-
* for `mapbox://` style urls. For `https://` and other urls, access
|
|
161
|
-
* url.
|
|
167
|
+
* for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query
|
|
168
|
+
* parameter of the style url.
|
|
162
169
|
* @property {string} [source] If your style uses more than one source, you need to use either the
|
|
163
170
|
* `source` property or the `layers` property to limit rendering to a single vector source. The
|
|
164
171
|
* `source` property corresponds to the id of a vector source in your Mapbox style.
|
|
@@ -285,7 +292,17 @@ var MapboxVectorLayer = /** @class */ (function (_super) {
|
|
|
285
292
|
}) || this;
|
|
286
293
|
_this.sourceId = options.source;
|
|
287
294
|
_this.layers = options.layers;
|
|
288
|
-
|
|
295
|
+
if (options.accessToken) {
|
|
296
|
+
_this.accessToken = options.accessToken;
|
|
297
|
+
}
|
|
298
|
+
else {
|
|
299
|
+
var url = new URL(options.styleUrl, location.href);
|
|
300
|
+
// The last search parameter is the access token
|
|
301
|
+
url.searchParams.forEach(function (value, key) {
|
|
302
|
+
_this.accessToken = value;
|
|
303
|
+
_this.accessTokenParam_ = key;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
289
306
|
_this.fetchStyle(options.styleUrl);
|
|
290
307
|
return _this;
|
|
291
308
|
}
|
|
@@ -371,7 +388,7 @@ var MapboxVectorLayer = /** @class */ (function (_super) {
|
|
|
371
388
|
if (styleSource.url.indexOf('mapbox://') === 0 ||
|
|
372
389
|
styleSource.url.indexOf('{z}') !== -1) {
|
|
373
390
|
// Tile source url, handle it directly
|
|
374
|
-
source.setUrl(normalizeSourceUrl(styleSource.url, this.accessToken));
|
|
391
|
+
source.setUrl(normalizeSourceUrl(styleSource.url, this.accessToken, this.accessTokenParam_));
|
|
375
392
|
applyStyle(this, style, sourceIdOrLayersList)
|
|
376
393
|
.then(function () {
|
|
377
394
|
source.setState(SourceState.READY);
|
|
@@ -382,7 +399,12 @@ var MapboxVectorLayer = /** @class */ (function (_super) {
|
|
|
382
399
|
}
|
|
383
400
|
else {
|
|
384
401
|
// TileJSON url, let ol-mapbox-style handle it
|
|
385
|
-
|
|
402
|
+
if (styleSource.tiles) {
|
|
403
|
+
styleSource.tiles = styleSource.tiles.map(function (url) {
|
|
404
|
+
return normalizeSourceUrl(url, _this.accessToken, _this.accessTokenParam_);
|
|
405
|
+
});
|
|
406
|
+
}
|
|
407
|
+
setupVectorSource(styleSource, normalizeSourceUrl(styleSource.url, this.accessToken, this.accessTokenParam_)).then(function (source) {
|
|
386
408
|
applyStyle(_this, style, sourceIdOrLayersList)
|
|
387
409
|
.then(function () {
|
|
388
410
|
_this.setSource(source);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxVector.js","sourceRoot":"","sources":["../src/layer/MapboxVector.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;GAEG;AACH,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAC3C,OAAO,SAAS,MAAM,wBAAwB,CAAC;AAC/C,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,eAAe,MAAM,wBAAwB,CAAC;AACrD,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAE9D,IAAM,aAAa,GAAG,wBAAwB,CAAC;AAE/C;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAG;IAC/B,IAAM,UAAU,GAAG,WAAW,CAAC;IA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;YACD,iBAAiB,CACf,WAAW,EACX,kBAAkB,CAChB,WAAW,CAAC,GAAG,EACf,IAAI,CAAC,WAAW,EAChB,IAAI,CAAC,iBAAiB,CACvB,CACF,CAAC,IAAI,CAAC,UAAC,MAAM;gBACZ,UAAU,CAAC,KAAI,EAAE,KAAK,EAAE,oBAAoB,CAAC;qBAC1C,IAAI,CAAC;oBACJ,KAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;gBACzB,CAAC,CAAC;qBACD,KAAK,CAAC,UAAC,KAAK;oBACX,KAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;oBACvB,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;gBAC1B,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;IAED;;;;OAIG;IACH,uCAAW,GAAX,UAAY,KAAK;QACf,IAAI,CAAC,aAAa,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,IAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACH,wBAAC;AAAD,CAAC,AApMD,CAAgC,eAAe,GAoM9C;AAED,eAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -92,13 +92,19 @@ export function normalizeStyleUrl(url, token) {
|
|
|
92
92
|
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
93
93
|
* @param {string} url The source URL.
|
|
94
94
|
* @param {string} token The access token.
|
|
95
|
+
* @param {string} tokenParam The access token key.
|
|
95
96
|
* @return {string} A vector tile template.
|
|
96
97
|
* @private
|
|
97
98
|
*/
|
|
98
|
-
export function normalizeSourceUrl(url, token) {
|
|
99
|
+
export function normalizeSourceUrl(url, token, tokenParam) {
|
|
99
100
|
const mapboxPath = getMapboxPath(url);
|
|
100
101
|
if (!mapboxPath) {
|
|
101
|
-
|
|
102
|
+
if (!token) {
|
|
103
|
+
return url;
|
|
104
|
+
}
|
|
105
|
+
const urlObject = new URL(url, location.href);
|
|
106
|
+
urlObject.searchParams.set(tokenParam, token);
|
|
107
|
+
return decodeURI(urlObject.href);
|
|
102
108
|
}
|
|
103
109
|
return `https://{a-d}.tiles.mapbox.com/v4/${mapboxPath}/{z}/{x}/{y}.vector.pbf?access_token=${token}`;
|
|
104
110
|
}
|
|
@@ -133,6 +139,7 @@ class ErrorEvent extends BaseEvent {
|
|
|
133
139
|
* @typedef {Object} SourceObject
|
|
134
140
|
* @property {string} url The source URL.
|
|
135
141
|
* @property {SourceType} type The source type.
|
|
142
|
+
* @property {Array<string>} [tiles] TileJSON tiles.
|
|
136
143
|
*/
|
|
137
144
|
|
|
138
145
|
/**
|
|
@@ -155,8 +162,8 @@ const SourceType = {
|
|
|
155
162
|
* style created with Mapbox Studio and hosted on Mapbox, this will look like
|
|
156
163
|
* 'mapbox://styles/you/your-style'.
|
|
157
164
|
* @property {string} [accessToken] The access token for your Mapbox style. This has to be provided
|
|
158
|
-
* for `mapbox://` style urls. For `https://` and other urls, access
|
|
159
|
-
* url.
|
|
165
|
+
* for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query
|
|
166
|
+
* parameter of the style url.
|
|
160
167
|
* @property {string} [source] If your style uses more than one source, you need to use either the
|
|
161
168
|
* `source` property or the `layers` property to limit rendering to a single vector source. The
|
|
162
169
|
* `source` property corresponds to the id of a vector source in your Mapbox style.
|
|
@@ -284,7 +291,16 @@ class MapboxVectorLayer extends VectorTileLayer {
|
|
|
284
291
|
|
|
285
292
|
this.sourceId = options.source;
|
|
286
293
|
this.layers = options.layers;
|
|
287
|
-
|
|
294
|
+
if (options.accessToken) {
|
|
295
|
+
this.accessToken = options.accessToken;
|
|
296
|
+
} else {
|
|
297
|
+
const url = new URL(options.styleUrl, location.href);
|
|
298
|
+
// The last search parameter is the access token
|
|
299
|
+
url.searchParams.forEach((value, key) => {
|
|
300
|
+
this.accessToken = value;
|
|
301
|
+
this.accessTokenParam_ = key;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
288
304
|
this.fetchStyle(options.styleUrl);
|
|
289
305
|
}
|
|
290
306
|
|
|
@@ -384,7 +400,13 @@ class MapboxVectorLayer extends VectorTileLayer {
|
|
|
384
400
|
styleSource.url.indexOf('{z}') !== -1
|
|
385
401
|
) {
|
|
386
402
|
// Tile source url, handle it directly
|
|
387
|
-
source.setUrl(
|
|
403
|
+
source.setUrl(
|
|
404
|
+
normalizeSourceUrl(
|
|
405
|
+
styleSource.url,
|
|
406
|
+
this.accessToken,
|
|
407
|
+
this.accessTokenParam_
|
|
408
|
+
)
|
|
409
|
+
);
|
|
388
410
|
applyStyle(this, style, sourceIdOrLayersList)
|
|
389
411
|
.then(() => {
|
|
390
412
|
source.setState(SourceState.READY);
|
|
@@ -394,7 +416,19 @@ class MapboxVectorLayer extends VectorTileLayer {
|
|
|
394
416
|
});
|
|
395
417
|
} else {
|
|
396
418
|
// TileJSON url, let ol-mapbox-style handle it
|
|
397
|
-
|
|
419
|
+
if (styleSource.tiles) {
|
|
420
|
+
styleSource.tiles = styleSource.tiles.map((url) =>
|
|
421
|
+
normalizeSourceUrl(url, this.accessToken, this.accessTokenParam_)
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
setupVectorSource(
|
|
425
|
+
styleSource,
|
|
426
|
+
normalizeSourceUrl(
|
|
427
|
+
styleSource.url,
|
|
428
|
+
this.accessToken,
|
|
429
|
+
this.accessTokenParam_
|
|
430
|
+
)
|
|
431
|
+
).then((source) => {
|
|
398
432
|
applyStyle(this, style, sourceIdOrLayersList)
|
|
399
433
|
.then(() => {
|
|
400
434
|
this.setSource(source);
|
package/util.js
CHANGED