ol 6.14.2-dev.1649543381601 → 6.14.2-dev.1649704885317
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/control/ScaleLine.js +1 -1
- package/layer/MapboxVector.d.ts +0 -145
- package/layer/MapboxVector.d.ts.map +1 -1
- package/layer/MapboxVector.js +14 -278
- package/layer/MapboxVector.js.map +1 -1
- package/package.json +2 -2
- package/renderer/canvas/Layer.d.ts.map +1 -1
- package/renderer/canvas/Layer.js +7 -4
- package/renderer/canvas/Layer.js.map +1 -1
- package/src/control/ScaleLine.js +1 -1
- package/src/layer/MapboxVector.js +13 -333
- package/src/renderer/canvas/Layer.js +9 -4
- package/util.js +1 -1
package/control/ScaleLine.js
CHANGED
package/layer/MapboxVector.d.ts
CHANGED
|
@@ -1,103 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the path from a mapbox:// URL.
|
|
3
|
-
* @param {string} url The Mapbox URL.
|
|
4
|
-
* @return {string} The path.
|
|
5
|
-
* @private
|
|
6
|
-
*/
|
|
7
|
-
export function getMapboxPath(url: string): string;
|
|
8
|
-
/**
|
|
9
|
-
* Turns mapbox:// sprite URLs into resolvable URLs.
|
|
10
|
-
* @param {string} url The sprite URL.
|
|
11
|
-
* @param {string} token The access token.
|
|
12
|
-
* @param {string} styleUrl The style URL.
|
|
13
|
-
* @return {string} A resolvable URL.
|
|
14
|
-
* @private
|
|
15
|
-
*/
|
|
16
|
-
export function normalizeSpriteUrl(url: string, token: string, styleUrl: string): string;
|
|
17
|
-
/**
|
|
18
|
-
* Turns mapbox:// glyphs URLs into resolvable URLs.
|
|
19
|
-
* @param {string} url The glyphs URL.
|
|
20
|
-
* @param {string} token The access token.
|
|
21
|
-
* @param {string} styleUrl The style URL.
|
|
22
|
-
* @return {string} A resolvable URL.
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
export function normalizeGlyphsUrl(url: string, token: string, styleUrl: string): string;
|
|
26
|
-
/**
|
|
27
|
-
* Turns mapbox:// style URLs into resolvable URLs.
|
|
28
|
-
* @param {string} url The style URL.
|
|
29
|
-
* @param {string} token The access token.
|
|
30
|
-
* @return {string} A resolvable URL.
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
export function normalizeStyleUrl(url: string, token: string): string;
|
|
34
|
-
/**
|
|
35
|
-
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
36
|
-
* @param {string} url The source URL.
|
|
37
|
-
* @param {string} token The access token.
|
|
38
|
-
* @param {string} tokenParam The access token key.
|
|
39
|
-
* @param {string} styleUrl The style URL.
|
|
40
|
-
* @return {string} A vector tile template.
|
|
41
|
-
* @private
|
|
42
|
-
*/
|
|
43
|
-
export function normalizeSourceUrl(url: string, token: string, tokenParam: string, styleUrl: string): string;
|
|
44
1
|
export default MapboxVectorLayer;
|
|
45
|
-
export type StyleObject = {
|
|
46
|
-
/**
|
|
47
|
-
* The style sources.
|
|
48
|
-
*/
|
|
49
|
-
sources: {
|
|
50
|
-
[x: string]: SourceObject;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* The sprite URL.
|
|
54
|
-
*/
|
|
55
|
-
sprite: string;
|
|
56
|
-
/**
|
|
57
|
-
* The glyphs URL.
|
|
58
|
-
*/
|
|
59
|
-
glyphs: string;
|
|
60
|
-
/**
|
|
61
|
-
* The style layers.
|
|
62
|
-
*/
|
|
63
|
-
layers: Array<LayerObject>;
|
|
64
|
-
};
|
|
65
|
-
export type SourceObject = {
|
|
66
|
-
/**
|
|
67
|
-
* The source URL.
|
|
68
|
-
*/
|
|
69
|
-
url: string;
|
|
70
|
-
/**
|
|
71
|
-
* The source type.
|
|
72
|
-
*/
|
|
73
|
-
type: SourceType;
|
|
74
|
-
/**
|
|
75
|
-
* TileJSON tiles.
|
|
76
|
-
*/
|
|
77
|
-
tiles?: string[] | undefined;
|
|
78
|
-
};
|
|
79
|
-
export type LayerObject = {
|
|
80
|
-
/**
|
|
81
|
-
* The layer id.
|
|
82
|
-
*/
|
|
83
|
-
id: string;
|
|
84
|
-
/**
|
|
85
|
-
* The layer type.
|
|
86
|
-
*/
|
|
87
|
-
type: string;
|
|
88
|
-
/**
|
|
89
|
-
* The source id.
|
|
90
|
-
*/
|
|
91
|
-
source: string;
|
|
92
|
-
/**
|
|
93
|
-
* The layout.
|
|
94
|
-
*/
|
|
95
|
-
layout: any;
|
|
96
|
-
/**
|
|
97
|
-
* The paint.
|
|
98
|
-
*/
|
|
99
|
-
paint: any;
|
|
100
|
-
};
|
|
101
2
|
export type Options = {
|
|
102
3
|
/**
|
|
103
4
|
* The URL of the Mapbox style object to use for this layer. For a
|
|
@@ -248,14 +149,6 @@ export type Options = {
|
|
|
248
149
|
[x: string]: any;
|
|
249
150
|
} | undefined;
|
|
250
151
|
};
|
|
251
|
-
/**
|
|
252
|
-
* @typedef {Object} LayerObject
|
|
253
|
-
* @property {string} id The layer id.
|
|
254
|
-
* @property {string} type The layer type.
|
|
255
|
-
* @property {string} source The source id.
|
|
256
|
-
* @property {Object} layout The layout.
|
|
257
|
-
* @property {Object} paint The paint.
|
|
258
|
-
*/
|
|
259
152
|
/**
|
|
260
153
|
* @typedef {Object} Options
|
|
261
154
|
* @property {string} styleUrl The URL of the Mapbox style object to use for this layer. For a
|
|
@@ -370,45 +263,7 @@ declare class MapboxVectorLayer extends VectorTileLayer {
|
|
|
370
263
|
* must be provided.
|
|
371
264
|
*/
|
|
372
265
|
constructor(options: Options);
|
|
373
|
-
setMaxResolutionFromTileGrid_: boolean;
|
|
374
|
-
sourceId: string | undefined;
|
|
375
|
-
layers: string[] | undefined;
|
|
376
266
|
accessToken: string | undefined;
|
|
377
|
-
accessTokenParam_: string;
|
|
378
|
-
/**
|
|
379
|
-
* Fetch the style object.
|
|
380
|
-
* @param {string} styleUrl The URL of the style to load.
|
|
381
|
-
* @protected
|
|
382
|
-
*/
|
|
383
|
-
protected fetchStyle(styleUrl: string): void;
|
|
384
|
-
/**
|
|
385
|
-
* Handle the loaded style object.
|
|
386
|
-
* @param {StyleObject} style The loaded style.
|
|
387
|
-
* @param {string} styleUrl The URL of the style.
|
|
388
|
-
* @protected
|
|
389
|
-
*/
|
|
390
|
-
protected onStyleLoad(style: StyleObject, styleUrl: string): void;
|
|
391
|
-
/**
|
|
392
|
-
* Applies configuration from the provided source to this layer's source,
|
|
393
|
-
* and reconfigures the loader to add a feature that renders the background,
|
|
394
|
-
* if the style is configured with a background.
|
|
395
|
-
* @param {import("../source/VectorTile.js").default} source The source to configure from.
|
|
396
|
-
* @param {StyleObject} style The style to configure the background from.
|
|
397
|
-
*/
|
|
398
|
-
configureSource(source: import("../source/VectorTile.js").default, style: StyleObject): void;
|
|
399
|
-
/**
|
|
400
|
-
* Handle configuration or loading error.
|
|
401
|
-
* @param {Error} error The error.
|
|
402
|
-
* @protected
|
|
403
|
-
*/
|
|
404
|
-
protected handleError(error: Error): void;
|
|
405
|
-
}
|
|
406
|
-
/**
|
|
407
|
-
* The Mapbox source type.
|
|
408
|
-
*/
|
|
409
|
-
type SourceType = string;
|
|
410
|
-
declare namespace SourceType {
|
|
411
|
-
const VECTOR: string;
|
|
412
267
|
}
|
|
413
268
|
import VectorTileLayer from "../layer/VectorTile.js";
|
|
414
269
|
//# sourceMappingURL=MapboxVector.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapboxVector.d.ts","sourceRoot":"","sources":["../src/layer/MapboxVector.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapboxVector.d.ts","sourceRoot":"","sources":["../src/layer/MapboxVector.js"],"names":[],"mappings":";;;;;;;cA+Bc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAqDN,MAA4C,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAvDhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH;IACE;;;OAGG;IACH,qBAHW,OAAO,EAqDjB;IAnBG,gCAAsC;CAoB3C"}
|
package/layer/MapboxVector.js
CHANGED
|
@@ -22,101 +22,7 @@ import MVT from '../format/MVT.js';
|
|
|
22
22
|
import SourceState from '../source/State.js';
|
|
23
23
|
import VectorTileLayer from '../layer/VectorTile.js';
|
|
24
24
|
import VectorTileSource from '../source/VectorTile.js';
|
|
25
|
-
import { applyBackground, applyStyle
|
|
26
|
-
var mapboxBaseUrl = 'https://api.mapbox.com';
|
|
27
|
-
/**
|
|
28
|
-
* Gets the path from a mapbox:// URL.
|
|
29
|
-
* @param {string} url The Mapbox URL.
|
|
30
|
-
* @return {string} The path.
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
export function getMapboxPath(url) {
|
|
34
|
-
var startsWith = 'mapbox://';
|
|
35
|
-
if (url.indexOf(startsWith) !== 0) {
|
|
36
|
-
return '';
|
|
37
|
-
}
|
|
38
|
-
return url.slice(startsWith.length);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Turns mapbox:// sprite URLs into resolvable URLs.
|
|
42
|
-
* @param {string} url The sprite URL.
|
|
43
|
-
* @param {string} token The access token.
|
|
44
|
-
* @param {string} styleUrl The style URL.
|
|
45
|
-
* @return {string} A resolvable URL.
|
|
46
|
-
* @private
|
|
47
|
-
*/
|
|
48
|
-
export function normalizeSpriteUrl(url, token, styleUrl) {
|
|
49
|
-
var mapboxPath = getMapboxPath(url);
|
|
50
|
-
if (!mapboxPath) {
|
|
51
|
-
return decodeURI(new URL(url, styleUrl).href);
|
|
52
|
-
}
|
|
53
|
-
var startsWith = 'sprites/';
|
|
54
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
55
|
-
throw new Error("unexpected sprites url: ".concat(url));
|
|
56
|
-
}
|
|
57
|
-
var sprite = mapboxPath.slice(startsWith.length);
|
|
58
|
-
return "".concat(mapboxBaseUrl, "/styles/v1/").concat(sprite, "/sprite?access_token=").concat(token);
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Turns mapbox:// glyphs URLs into resolvable URLs.
|
|
62
|
-
* @param {string} url The glyphs URL.
|
|
63
|
-
* @param {string} token The access token.
|
|
64
|
-
* @param {string} styleUrl The style URL.
|
|
65
|
-
* @return {string} A resolvable URL.
|
|
66
|
-
* @private
|
|
67
|
-
*/
|
|
68
|
-
export function normalizeGlyphsUrl(url, token, styleUrl) {
|
|
69
|
-
var mapboxPath = getMapboxPath(url);
|
|
70
|
-
if (!mapboxPath) {
|
|
71
|
-
return decodeURI(new URL(url, styleUrl).href);
|
|
72
|
-
}
|
|
73
|
-
var startsWith = 'fonts/';
|
|
74
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
75
|
-
throw new Error("unexpected fonts url: ".concat(url));
|
|
76
|
-
}
|
|
77
|
-
var font = mapboxPath.slice(startsWith.length);
|
|
78
|
-
return "".concat(mapboxBaseUrl, "/fonts/v1/").concat(font, "/0-255.pbf?access_token=").concat(token);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Turns mapbox:// style URLs into resolvable URLs.
|
|
82
|
-
* @param {string} url The style URL.
|
|
83
|
-
* @param {string} token The access token.
|
|
84
|
-
* @return {string} A resolvable URL.
|
|
85
|
-
* @private
|
|
86
|
-
*/
|
|
87
|
-
export function normalizeStyleUrl(url, token) {
|
|
88
|
-
var mapboxPath = getMapboxPath(url);
|
|
89
|
-
if (!mapboxPath) {
|
|
90
|
-
return decodeURI(new URL(url, location.href).href);
|
|
91
|
-
}
|
|
92
|
-
var startsWith = 'styles/';
|
|
93
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
94
|
-
throw new Error("unexpected style url: ".concat(url));
|
|
95
|
-
}
|
|
96
|
-
var style = mapboxPath.slice(startsWith.length);
|
|
97
|
-
return "".concat(mapboxBaseUrl, "/styles/v1/").concat(style, "?&access_token=").concat(token);
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
101
|
-
* @param {string} url The source URL.
|
|
102
|
-
* @param {string} token The access token.
|
|
103
|
-
* @param {string} tokenParam The access token key.
|
|
104
|
-
* @param {string} styleUrl The style URL.
|
|
105
|
-
* @return {string} A vector tile template.
|
|
106
|
-
* @private
|
|
107
|
-
*/
|
|
108
|
-
export function normalizeSourceUrl(url, token, tokenParam, styleUrl) {
|
|
109
|
-
var urlObject = new URL(url, styleUrl);
|
|
110
|
-
var mapboxPath = getMapboxPath(url);
|
|
111
|
-
if (!mapboxPath) {
|
|
112
|
-
if (!token) {
|
|
113
|
-
return decodeURI(urlObject.href);
|
|
114
|
-
}
|
|
115
|
-
urlObject.searchParams.set(tokenParam, token);
|
|
116
|
-
return decodeURI(urlObject.href);
|
|
117
|
-
}
|
|
118
|
-
return "https://{a-d}.tiles.mapbox.com/v4/".concat(mapboxPath, "/{z}/{x}/{y}.vector.pbf?access_token=").concat(token);
|
|
119
|
-
}
|
|
25
|
+
import { applyBackground, applyStyle } from 'ol-mapbox-style';
|
|
120
26
|
/**
|
|
121
27
|
* @classdesc
|
|
122
28
|
* Event emitted on configuration or loading error.
|
|
@@ -136,34 +42,6 @@ var ErrorEvent = /** @class */ (function (_super) {
|
|
|
136
42
|
}
|
|
137
43
|
return ErrorEvent;
|
|
138
44
|
}(BaseEvent));
|
|
139
|
-
/**
|
|
140
|
-
* @typedef {Object} StyleObject
|
|
141
|
-
* @property {Object<string, SourceObject>} sources The style sources.
|
|
142
|
-
* @property {string} sprite The sprite URL.
|
|
143
|
-
* @property {string} glyphs The glyphs URL.
|
|
144
|
-
* @property {Array<LayerObject>} layers The style layers.
|
|
145
|
-
*/
|
|
146
|
-
/**
|
|
147
|
-
* @typedef {Object} SourceObject
|
|
148
|
-
* @property {string} url The source URL.
|
|
149
|
-
* @property {SourceType} type The source type.
|
|
150
|
-
* @property {Array<string>} [tiles] TileJSON tiles.
|
|
151
|
-
*/
|
|
152
|
-
/**
|
|
153
|
-
* The Mapbox source type.
|
|
154
|
-
* @enum {string}
|
|
155
|
-
*/
|
|
156
|
-
var SourceType = {
|
|
157
|
-
VECTOR: 'vector',
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* @typedef {Object} LayerObject
|
|
161
|
-
* @property {string} id The layer id.
|
|
162
|
-
* @property {string} type The layer type.
|
|
163
|
-
* @property {string} source The source id.
|
|
164
|
-
* @property {Object} layout The layout.
|
|
165
|
-
* @property {Object} paint The paint.
|
|
166
|
-
*/
|
|
167
45
|
/**
|
|
168
46
|
* @typedef {Object} Options
|
|
169
47
|
* @property {string} styleUrl The URL of the Mapbox style object to use for this layer. For a
|
|
@@ -307,170 +185,28 @@ var MapboxVectorLayer = /** @class */ (function (_super) {
|
|
|
307
185
|
useInterimTilesOnError: options.useInterimTilesOnError,
|
|
308
186
|
properties: options.properties,
|
|
309
187
|
}) || this;
|
|
310
|
-
_this.setMaxResolutionFromTileGrid_ =
|
|
311
|
-
options.maxResolution === undefined && options.minZoom === undefined;
|
|
312
|
-
_this.sourceId = options.source;
|
|
313
|
-
_this.layers = options.layers;
|
|
314
188
|
if (options.accessToken) {
|
|
315
189
|
_this.accessToken = options.accessToken;
|
|
316
190
|
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
url.searchParams.forEach(function (value, key) {
|
|
321
|
-
_this.accessToken = value;
|
|
322
|
-
_this.accessTokenParam_ = key;
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
_this.fetchStyle(options.styleUrl);
|
|
326
|
-
return _this;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Fetch the style object.
|
|
330
|
-
* @param {string} styleUrl The URL of the style to load.
|
|
331
|
-
* @protected
|
|
332
|
-
*/
|
|
333
|
-
MapboxVectorLayer.prototype.fetchStyle = function (styleUrl) {
|
|
334
|
-
var _this = this;
|
|
335
|
-
var url = normalizeStyleUrl(styleUrl, this.accessToken);
|
|
336
|
-
fetch(url)
|
|
337
|
-
.then(function (response) {
|
|
338
|
-
if (!response.ok) {
|
|
339
|
-
throw new Error("unexpected response when fetching style: ".concat(response.status));
|
|
340
|
-
}
|
|
341
|
-
return response.json();
|
|
191
|
+
var url = options.styleUrl;
|
|
192
|
+
applyStyle(_this, url, options.layers || options.source, {
|
|
193
|
+
accessToken: _this.accessToken,
|
|
342
194
|
})
|
|
343
|
-
.then(function (
|
|
344
|
-
|
|
195
|
+
.then(function () {
|
|
196
|
+
source.setState(SourceState.READY);
|
|
345
197
|
})
|
|
346
198
|
.catch(function (error) {
|
|
347
|
-
_this.
|
|
199
|
+
_this.dispatchEvent(new ErrorEvent(error));
|
|
200
|
+
var source = _this.getSource();
|
|
201
|
+
source.setState(SourceState.ERROR);
|
|
348
202
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
* @param {StyleObject} style The loaded style.
|
|
353
|
-
* @param {string} styleUrl The URL of the style.
|
|
354
|
-
* @protected
|
|
355
|
-
*/
|
|
356
|
-
MapboxVectorLayer.prototype.onStyleLoad = function (style, styleUrl) {
|
|
357
|
-
var _this = this;
|
|
358
|
-
var sourceId;
|
|
359
|
-
var sourceIdOrLayersList;
|
|
360
|
-
if (this.layers) {
|
|
361
|
-
// confirm all layers share the same source
|
|
362
|
-
var lookup = {};
|
|
363
|
-
for (var i = 0; i < style.layers.length; ++i) {
|
|
364
|
-
var layer = style.layers[i];
|
|
365
|
-
if (layer.source) {
|
|
366
|
-
lookup[layer.id] = layer.source;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
var firstSource = void 0;
|
|
370
|
-
for (var i = 0; i < this.layers.length; ++i) {
|
|
371
|
-
var candidate = lookup[this.layers[i]];
|
|
372
|
-
if (!candidate) {
|
|
373
|
-
this.handleError(new Error("could not find source for ".concat(this.layers[i])));
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
if (!firstSource) {
|
|
377
|
-
firstSource = candidate;
|
|
378
|
-
}
|
|
379
|
-
else if (firstSource !== candidate) {
|
|
380
|
-
this.handleError(new Error("layers can only use a single source, found ".concat(firstSource, " and ").concat(candidate)));
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
sourceId = firstSource;
|
|
385
|
-
sourceIdOrLayersList = this.layers;
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
sourceId = this.sourceId;
|
|
389
|
-
sourceIdOrLayersList = sourceId;
|
|
390
|
-
}
|
|
391
|
-
if (!sourceIdOrLayersList) {
|
|
392
|
-
// default to the first source in the style
|
|
393
|
-
sourceId = Object.keys(style.sources)[0];
|
|
394
|
-
sourceIdOrLayersList = sourceId;
|
|
395
|
-
}
|
|
396
|
-
if (style.sprite) {
|
|
397
|
-
style.sprite = normalizeSpriteUrl(style.sprite, this.accessToken, styleUrl);
|
|
398
|
-
}
|
|
399
|
-
if (style.glyphs) {
|
|
400
|
-
style.glyphs = normalizeGlyphsUrl(style.glyphs, this.accessToken, styleUrl);
|
|
401
|
-
}
|
|
402
|
-
var styleSource = style.sources[sourceId];
|
|
403
|
-
if (styleSource.type !== SourceType.VECTOR) {
|
|
404
|
-
this.handleError(new Error("only works for vector sources, found ".concat(styleSource.type)));
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
var source = this.getSource();
|
|
408
|
-
if (styleSource.url && styleSource.url.indexOf('mapbox://') === 0) {
|
|
409
|
-
// Tile source url, handle it directly
|
|
410
|
-
source.setUrl(normalizeSourceUrl(styleSource.url, this.accessToken, this.accessTokenParam_, styleUrl));
|
|
411
|
-
applyStyle(this, style, sourceIdOrLayersList)
|
|
412
|
-
.then(function () {
|
|
413
|
-
_this.configureSource(source, style);
|
|
414
|
-
})
|
|
415
|
-
.catch(function (error) {
|
|
416
|
-
_this.handleError(error);
|
|
203
|
+
if (_this.getBackground() === undefined) {
|
|
204
|
+
applyBackground(_this, options.styleUrl, {
|
|
205
|
+
accessToken: _this.accessToken,
|
|
417
206
|
});
|
|
418
207
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
if (styleSource.tiles) {
|
|
422
|
-
styleSource.tiles = styleSource.tiles.map(function (url) {
|
|
423
|
-
return normalizeSourceUrl(url, _this.accessToken, _this.accessTokenParam_, styleUrl);
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
setupVectorSource(styleSource, styleSource.url
|
|
427
|
-
? normalizeSourceUrl(styleSource.url, this.accessToken, this.accessTokenParam_, styleUrl)
|
|
428
|
-
: undefined).then(function (source) {
|
|
429
|
-
applyStyle(_this, style, sourceIdOrLayersList)
|
|
430
|
-
.then(function () {
|
|
431
|
-
_this.configureSource(source, style);
|
|
432
|
-
})
|
|
433
|
-
.catch(function (error) {
|
|
434
|
-
_this.configureSource(source, style);
|
|
435
|
-
_this.handleError(error);
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
/**
|
|
441
|
-
* Applies configuration from the provided source to this layer's source,
|
|
442
|
-
* and reconfigures the loader to add a feature that renders the background,
|
|
443
|
-
* if the style is configured with a background.
|
|
444
|
-
* @param {import("../source/VectorTile.js").default} source The source to configure from.
|
|
445
|
-
* @param {StyleObject} style The style to configure the background from.
|
|
446
|
-
*/
|
|
447
|
-
MapboxVectorLayer.prototype.configureSource = function (source, style) {
|
|
448
|
-
var targetSource = this.getSource();
|
|
449
|
-
if (source !== targetSource) {
|
|
450
|
-
targetSource.setAttributions(source.getAttributions());
|
|
451
|
-
targetSource.setTileUrlFunction(source.getTileUrlFunction());
|
|
452
|
-
targetSource.setTileLoadFunction(source.getTileLoadFunction());
|
|
453
|
-
targetSource.tileGrid = source.tileGrid;
|
|
454
|
-
}
|
|
455
|
-
if (this.getBackground() === undefined) {
|
|
456
|
-
applyBackground(this, style);
|
|
457
|
-
}
|
|
458
|
-
if (this.setMaxResolutionFromTileGrid_) {
|
|
459
|
-
var tileGrid = targetSource.getTileGrid();
|
|
460
|
-
this.setMaxResolution(tileGrid.getResolution(tileGrid.getMinZoom()));
|
|
461
|
-
}
|
|
462
|
-
targetSource.setState(SourceState.READY);
|
|
463
|
-
};
|
|
464
|
-
/**
|
|
465
|
-
* Handle configuration or loading error.
|
|
466
|
-
* @param {Error} error The error.
|
|
467
|
-
* @protected
|
|
468
|
-
*/
|
|
469
|
-
MapboxVectorLayer.prototype.handleError = function (error) {
|
|
470
|
-
this.dispatchEvent(new ErrorEvent(error));
|
|
471
|
-
var source = this.getSource();
|
|
472
|
-
source.setState(SourceState.ERROR);
|
|
473
|
-
};
|
|
208
|
+
return _this;
|
|
209
|
+
}
|
|
474
210
|
return MapboxVectorLayer;
|
|
475
211
|
}(VectorTileLayer));
|
|
476
212
|
export default MapboxVectorLayer;
|
|
@@ -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,eAAe,EAAE,UAAU,
|
|
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;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C,eAAe,GAwD9C;AAED,eAAe,iBAAiB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ol",
|
|
3
|
-
"version": "6.14.2-dev.
|
|
3
|
+
"version": "6.14.2-dev.1649704885317",
|
|
4
4
|
"description": "OpenLayers mapping library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"map",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"geotiff": "^2.0.2",
|
|
26
|
-
"ol-mapbox-style": "^
|
|
26
|
+
"ol-mapbox-style": "^8.0.5",
|
|
27
27
|
"pbf": "3.2.1",
|
|
28
28
|
"rbush": "^3.0.1"
|
|
29
29
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../src/renderer/canvas/Layer.js"],"names":[],"mappings":";AAkCA;;;;GAIG;AACH;IAOI;;;OAGG;IACH,qBAFU,WAAW,CAEA;IAErB;;;OAGG;IACH,8BAFU,MAAM,CAEO;IAEvB;;;;;OAKG;IACH,yBAFU,OAAO,oBAAoB,EAAE,SAAS,CAEV;IAEtC;;;;;OAKG;IACH,0BAFU,OAAO,oBAAoB,EAAE,SAAS,CAET;IAEvC;;;;;OAKG;IACH,iCAFU,OAAO,oBAAoB,EAAE,SAAS,CAEF;IAE9C;;OAEG;IACH,SAFU,wBAAwB,CAEf;IAEnB;;OAEG;IACH,iBAFU,OAAO,CAEW;IAE5B;;;OAGG;IACH,sBAAyB;IAEzB;;;OAGG;IACH,sBAFU,OAAO,uBAAuB,EAAE,UAAU,GAAC,IAAI,CAEnC;IAGxB;;;;;OAKG;IACH,oBALW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,OACnD,MAAM,OACN,MAAM,GACL,iBAAiB,GAAC,IAAI,CAiBjC;IAED;;;OAGG;IACH,0BAHW,OAAO,uBAAuB,EAAE,UAAU,GACzC,MAAM,CASjB;IAED;;;;;;OAMG;IACH,qBALW,WAAW,aACX,MAAM,WACN,MAAM,
|
|
1
|
+
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../src/renderer/canvas/Layer.js"],"names":[],"mappings":";AAkCA;;;;GAIG;AACH;IAOI;;;OAGG;IACH,qBAFU,WAAW,CAEA;IAErB;;;OAGG;IACH,8BAFU,MAAM,CAEO;IAEvB;;;;;OAKG;IACH,yBAFU,OAAO,oBAAoB,EAAE,SAAS,CAEV;IAEtC;;;;;OAKG;IACH,0BAFU,OAAO,oBAAoB,EAAE,SAAS,CAET;IAEvC;;;;;OAKG;IACH,iCAFU,OAAO,oBAAoB,EAAE,SAAS,CAEF;IAE9C;;OAEG;IACH,SAFU,wBAAwB,CAEf;IAEnB;;OAEG;IACH,iBAFU,OAAO,CAEW;IAE5B;;;OAGG;IACH,sBAAyB;IAEzB;;;OAGG;IACH,sBAFU,OAAO,uBAAuB,EAAE,UAAU,GAAC,IAAI,CAEnC;IAGxB;;;;;OAKG;IACH,oBALW,iBAAiB,GAAC,gBAAgB,GAAC,gBAAgB,OACnD,MAAM,OACN,MAAM,GACL,iBAAiB,GAAC,IAAI,CAiBjC;IAED;;;OAGG;IACH,0BAHW,OAAO,uBAAuB,EAAE,UAAU,GACzC,MAAM,CASjB;IAED;;;;;;OAMG;IACH,qBALW,WAAW,aACX,MAAM,WACN,MAAM,kDA2DhB;IAED;;;;;OAKG;IACH,iCALW,wBAAwB,cACxB,OAAO,uBAAuB,EAAE,UAAU,UAC1C,OAAO,iBAAiB,EAAE,MAAM,QA2B1C;IAED;;;;;OAKG;IACH,6BAWC;IAED;;;;OAIG;IACH,6BAJW,wBAAwB,cACxB,OAAO,uBAAuB,EAAE,UAAU,QAMpD;IAED;;;;OAIG;IACH,8BAJW,wBAAwB,cACxB,OAAO,uBAAuB,EAAE,UAAU,QAKpD;IAED;;;;;;;;;;;OAWG;IACH,qCAVW,OAAO,qBAAqB,EAAE,UAAU,cACxC,MAAM,YACN,MAAM,cACN,MAAM,SACN,MAAM,UACN,MAAM,WACN,MAAM,GAEJ,OAAO,oBAAoB,EAAE,SAAS,CA2BlD;CAoEF"}
|
package/renderer/canvas/Layer.js
CHANGED
|
@@ -146,7 +146,8 @@ var CanvasLayerRenderer = /** @class */ (function (_super) {
|
|
|
146
146
|
target.style.opacity === '' &&
|
|
147
147
|
opacity === 1 &&
|
|
148
148
|
(!opt_backgroundColor ||
|
|
149
|
-
(target
|
|
149
|
+
(target &&
|
|
150
|
+
target.style.backgroundColor &&
|
|
150
151
|
equals(asArray(target.style.backgroundColor), asArray(opt_backgroundColor))))) {
|
|
151
152
|
var canvas = target.firstElementChild;
|
|
152
153
|
if (canvas instanceof HTMLCanvasElement) {
|
|
@@ -172,9 +173,6 @@ var CanvasLayerRenderer = /** @class */ (function (_super) {
|
|
|
172
173
|
style.position = 'absolute';
|
|
173
174
|
style.width = '100%';
|
|
174
175
|
style.height = '100%';
|
|
175
|
-
if (opt_backgroundColor) {
|
|
176
|
-
style.backgroundColor = opt_backgroundColor;
|
|
177
|
-
}
|
|
178
176
|
context = createCanvasContext2D();
|
|
179
177
|
var canvas = context.canvas;
|
|
180
178
|
container.appendChild(canvas);
|
|
@@ -185,6 +183,11 @@ var CanvasLayerRenderer = /** @class */ (function (_super) {
|
|
|
185
183
|
this.container = container;
|
|
186
184
|
this.context = context;
|
|
187
185
|
}
|
|
186
|
+
if (!this.containerReused &&
|
|
187
|
+
opt_backgroundColor &&
|
|
188
|
+
!this.container.style.backgroundColor) {
|
|
189
|
+
this.container.style.backgroundColor = opt_backgroundColor;
|
|
190
|
+
}
|
|
188
191
|
};
|
|
189
192
|
/**
|
|
190
193
|
* @param {CanvasRenderingContext2D} context Context.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.js","sourceRoot":"","sources":["../../src/renderer/canvas/Layer.js"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA;;GAEG;AACH,OAAO,aAAa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AU,CAAC,IAAI,CAAC,CAAC;YAC5C,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;SACnC;QACD,YAAY,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACnC,IAAI,IAAI,CAAC;QACT,IAAI;YACF,YAAY,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC/D,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACnD;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,CAAC,IAAI,KAAK,eAAe,EAAE;gBAChC,2FAA2F;gBAC3F,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;gBAC1B,OAAO,IAAI,UAAU,EAAE,CAAC;aACzB;YACD,OAAO,IAAI,CAAC;SACb;QAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE;YACjB,OAAO,IAAI,CAAC;SACb;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,6CAAe,GAAf;QACE,OAAO,IAAI,CAAC,UAAU,CAAC;QACvB,iBAAM,eAAe,WAAE,CAAC;IAC1B,CAAC;IACH,0BAAC;AAAD,CAAC,AAtVD,CAAkC,aAAa,GAsV9C;AAED,eAAe,mBAAmB,CAAC"}
|
package/src/control/ScaleLine.js
CHANGED
|
@@ -7,110 +7,7 @@ import MVT from '../format/MVT.js';
|
|
|
7
7
|
import SourceState from '../source/State.js';
|
|
8
8
|
import VectorTileLayer from '../layer/VectorTile.js';
|
|
9
9
|
import VectorTileSource from '../source/VectorTile.js';
|
|
10
|
-
import {applyBackground, applyStyle
|
|
11
|
-
|
|
12
|
-
const mapboxBaseUrl = 'https://api.mapbox.com';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Gets the path from a mapbox:// URL.
|
|
16
|
-
* @param {string} url The Mapbox URL.
|
|
17
|
-
* @return {string} The path.
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
export function getMapboxPath(url) {
|
|
21
|
-
const startsWith = 'mapbox://';
|
|
22
|
-
if (url.indexOf(startsWith) !== 0) {
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
return url.slice(startsWith.length);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Turns mapbox:// sprite URLs into resolvable URLs.
|
|
30
|
-
* @param {string} url The sprite URL.
|
|
31
|
-
* @param {string} token The access token.
|
|
32
|
-
* @param {string} styleUrl The style URL.
|
|
33
|
-
* @return {string} A resolvable URL.
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
export function normalizeSpriteUrl(url, token, styleUrl) {
|
|
37
|
-
const mapboxPath = getMapboxPath(url);
|
|
38
|
-
if (!mapboxPath) {
|
|
39
|
-
return decodeURI(new URL(url, styleUrl).href);
|
|
40
|
-
}
|
|
41
|
-
const startsWith = 'sprites/';
|
|
42
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
43
|
-
throw new Error(`unexpected sprites url: ${url}`);
|
|
44
|
-
}
|
|
45
|
-
const sprite = mapboxPath.slice(startsWith.length);
|
|
46
|
-
|
|
47
|
-
return `${mapboxBaseUrl}/styles/v1/${sprite}/sprite?access_token=${token}`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Turns mapbox:// glyphs URLs into resolvable URLs.
|
|
52
|
-
* @param {string} url The glyphs URL.
|
|
53
|
-
* @param {string} token The access token.
|
|
54
|
-
* @param {string} styleUrl The style URL.
|
|
55
|
-
* @return {string} A resolvable URL.
|
|
56
|
-
* @private
|
|
57
|
-
*/
|
|
58
|
-
export function normalizeGlyphsUrl(url, token, styleUrl) {
|
|
59
|
-
const mapboxPath = getMapboxPath(url);
|
|
60
|
-
if (!mapboxPath) {
|
|
61
|
-
return decodeURI(new URL(url, styleUrl).href);
|
|
62
|
-
}
|
|
63
|
-
const startsWith = 'fonts/';
|
|
64
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
65
|
-
throw new Error(`unexpected fonts url: ${url}`);
|
|
66
|
-
}
|
|
67
|
-
const font = mapboxPath.slice(startsWith.length);
|
|
68
|
-
|
|
69
|
-
return `${mapboxBaseUrl}/fonts/v1/${font}/0-255.pbf?access_token=${token}`;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Turns mapbox:// style URLs into resolvable URLs.
|
|
74
|
-
* @param {string} url The style URL.
|
|
75
|
-
* @param {string} token The access token.
|
|
76
|
-
* @return {string} A resolvable URL.
|
|
77
|
-
* @private
|
|
78
|
-
*/
|
|
79
|
-
export function normalizeStyleUrl(url, token) {
|
|
80
|
-
const mapboxPath = getMapboxPath(url);
|
|
81
|
-
if (!mapboxPath) {
|
|
82
|
-
return decodeURI(new URL(url, location.href).href);
|
|
83
|
-
}
|
|
84
|
-
const startsWith = 'styles/';
|
|
85
|
-
if (mapboxPath.indexOf(startsWith) !== 0) {
|
|
86
|
-
throw new Error(`unexpected style url: ${url}`);
|
|
87
|
-
}
|
|
88
|
-
const style = mapboxPath.slice(startsWith.length);
|
|
89
|
-
|
|
90
|
-
return `${mapboxBaseUrl}/styles/v1/${style}?&access_token=${token}`;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Turns mapbox:// source URLs into vector tile URL templates.
|
|
95
|
-
* @param {string} url The source URL.
|
|
96
|
-
* @param {string} token The access token.
|
|
97
|
-
* @param {string} tokenParam The access token key.
|
|
98
|
-
* @param {string} styleUrl The style URL.
|
|
99
|
-
* @return {string} A vector tile template.
|
|
100
|
-
* @private
|
|
101
|
-
*/
|
|
102
|
-
export function normalizeSourceUrl(url, token, tokenParam, styleUrl) {
|
|
103
|
-
const urlObject = new URL(url, styleUrl);
|
|
104
|
-
const mapboxPath = getMapboxPath(url);
|
|
105
|
-
if (!mapboxPath) {
|
|
106
|
-
if (!token) {
|
|
107
|
-
return decodeURI(urlObject.href);
|
|
108
|
-
}
|
|
109
|
-
urlObject.searchParams.set(tokenParam, token);
|
|
110
|
-
return decodeURI(urlObject.href);
|
|
111
|
-
}
|
|
112
|
-
return `https://{a-d}.tiles.mapbox.com/v4/${mapboxPath}/{z}/{x}/{y}.vector.pbf?access_token=${token}`;
|
|
113
|
-
}
|
|
10
|
+
import {applyBackground, applyStyle} from 'ol-mapbox-style';
|
|
114
11
|
|
|
115
12
|
/**
|
|
116
13
|
* @classdesc
|
|
@@ -130,38 +27,6 @@ class ErrorEvent extends BaseEvent {
|
|
|
130
27
|
}
|
|
131
28
|
}
|
|
132
29
|
|
|
133
|
-
/**
|
|
134
|
-
* @typedef {Object} StyleObject
|
|
135
|
-
* @property {Object<string, SourceObject>} sources The style sources.
|
|
136
|
-
* @property {string} sprite The sprite URL.
|
|
137
|
-
* @property {string} glyphs The glyphs URL.
|
|
138
|
-
* @property {Array<LayerObject>} layers The style layers.
|
|
139
|
-
*/
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* @typedef {Object} SourceObject
|
|
143
|
-
* @property {string} url The source URL.
|
|
144
|
-
* @property {SourceType} type The source type.
|
|
145
|
-
* @property {Array<string>} [tiles] TileJSON tiles.
|
|
146
|
-
*/
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* The Mapbox source type.
|
|
150
|
-
* @enum {string}
|
|
151
|
-
*/
|
|
152
|
-
const SourceType = {
|
|
153
|
-
VECTOR: 'vector',
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @typedef {Object} LayerObject
|
|
158
|
-
* @property {string} id The layer id.
|
|
159
|
-
* @property {string} type The layer type.
|
|
160
|
-
* @property {string} source The source id.
|
|
161
|
-
* @property {Object} layout The layout.
|
|
162
|
-
* @property {Object} paint The paint.
|
|
163
|
-
*/
|
|
164
|
-
|
|
165
30
|
/**
|
|
166
31
|
* @typedef {Object} Options
|
|
167
32
|
* @property {string} styleUrl The URL of the Mapbox style object to use for this layer. For a
|
|
@@ -306,211 +171,26 @@ class MapboxVectorLayer extends VectorTileLayer {
|
|
|
306
171
|
properties: options.properties,
|
|
307
172
|
});
|
|
308
173
|
|
|
309
|
-
this.setMaxResolutionFromTileGrid_ =
|
|
310
|
-
options.maxResolution === undefined && options.minZoom === undefined;
|
|
311
|
-
|
|
312
|
-
this.sourceId = options.source;
|
|
313
|
-
this.layers = options.layers;
|
|
314
|
-
|
|
315
174
|
if (options.accessToken) {
|
|
316
175
|
this.accessToken = options.accessToken;
|
|
317
|
-
} else {
|
|
318
|
-
const url = new URL(options.styleUrl, location.href);
|
|
319
|
-
// The last search parameter is the access token
|
|
320
|
-
url.searchParams.forEach((value, key) => {
|
|
321
|
-
this.accessToken = value;
|
|
322
|
-
this.accessTokenParam_ = key;
|
|
323
|
-
});
|
|
324
176
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
* @protected
|
|
332
|
-
*/
|
|
333
|
-
fetchStyle(styleUrl) {
|
|
334
|
-
const url = normalizeStyleUrl(styleUrl, this.accessToken);
|
|
335
|
-
fetch(url)
|
|
336
|
-
.then((response) => {
|
|
337
|
-
if (!response.ok) {
|
|
338
|
-
throw new Error(
|
|
339
|
-
`unexpected response when fetching style: ${response.status}`
|
|
340
|
-
);
|
|
341
|
-
}
|
|
342
|
-
return response.json();
|
|
343
|
-
})
|
|
344
|
-
.then((style) => {
|
|
345
|
-
this.onStyleLoad(style, url.startsWith('data:') ? location.href : url);
|
|
177
|
+
const url = options.styleUrl;
|
|
178
|
+
applyStyle(this, url, options.layers || options.source, {
|
|
179
|
+
accessToken: this.accessToken,
|
|
180
|
+
})
|
|
181
|
+
.then(() => {
|
|
182
|
+
source.setState(SourceState.READY);
|
|
346
183
|
})
|
|
347
184
|
.catch((error) => {
|
|
348
|
-
this.
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Handle the loaded style object.
|
|
354
|
-
* @param {StyleObject} style The loaded style.
|
|
355
|
-
* @param {string} styleUrl The URL of the style.
|
|
356
|
-
* @protected
|
|
357
|
-
*/
|
|
358
|
-
onStyleLoad(style, styleUrl) {
|
|
359
|
-
let sourceId;
|
|
360
|
-
let sourceIdOrLayersList;
|
|
361
|
-
if (this.layers) {
|
|
362
|
-
// confirm all layers share the same source
|
|
363
|
-
const lookup = {};
|
|
364
|
-
for (let i = 0; i < style.layers.length; ++i) {
|
|
365
|
-
const layer = style.layers[i];
|
|
366
|
-
if (layer.source) {
|
|
367
|
-
lookup[layer.id] = layer.source;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
let firstSource;
|
|
371
|
-
for (let i = 0; i < this.layers.length; ++i) {
|
|
372
|
-
const candidate = lookup[this.layers[i]];
|
|
373
|
-
if (!candidate) {
|
|
374
|
-
this.handleError(
|
|
375
|
-
new Error(`could not find source for ${this.layers[i]}`)
|
|
376
|
-
);
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (!firstSource) {
|
|
380
|
-
firstSource = candidate;
|
|
381
|
-
} else if (firstSource !== candidate) {
|
|
382
|
-
this.handleError(
|
|
383
|
-
new Error(
|
|
384
|
-
`layers can only use a single source, found ${firstSource} and ${candidate}`
|
|
385
|
-
)
|
|
386
|
-
);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
sourceId = firstSource;
|
|
391
|
-
sourceIdOrLayersList = this.layers;
|
|
392
|
-
} else {
|
|
393
|
-
sourceId = this.sourceId;
|
|
394
|
-
sourceIdOrLayersList = sourceId;
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
if (!sourceIdOrLayersList) {
|
|
398
|
-
// default to the first source in the style
|
|
399
|
-
sourceId = Object.keys(style.sources)[0];
|
|
400
|
-
sourceIdOrLayersList = sourceId;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
if (style.sprite) {
|
|
404
|
-
style.sprite = normalizeSpriteUrl(
|
|
405
|
-
style.sprite,
|
|
406
|
-
this.accessToken,
|
|
407
|
-
styleUrl
|
|
408
|
-
);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
if (style.glyphs) {
|
|
412
|
-
style.glyphs = normalizeGlyphsUrl(
|
|
413
|
-
style.glyphs,
|
|
414
|
-
this.accessToken,
|
|
415
|
-
styleUrl
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
const styleSource = style.sources[sourceId];
|
|
420
|
-
if (styleSource.type !== SourceType.VECTOR) {
|
|
421
|
-
this.handleError(
|
|
422
|
-
new Error(`only works for vector sources, found ${styleSource.type}`)
|
|
423
|
-
);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
const source = this.getSource();
|
|
428
|
-
if (styleSource.url && styleSource.url.indexOf('mapbox://') === 0) {
|
|
429
|
-
// Tile source url, handle it directly
|
|
430
|
-
source.setUrl(
|
|
431
|
-
normalizeSourceUrl(
|
|
432
|
-
styleSource.url,
|
|
433
|
-
this.accessToken,
|
|
434
|
-
this.accessTokenParam_,
|
|
435
|
-
styleUrl
|
|
436
|
-
)
|
|
437
|
-
);
|
|
438
|
-
applyStyle(this, style, sourceIdOrLayersList)
|
|
439
|
-
.then(() => {
|
|
440
|
-
this.configureSource(source, style);
|
|
441
|
-
})
|
|
442
|
-
.catch((error) => {
|
|
443
|
-
this.handleError(error);
|
|
444
|
-
});
|
|
445
|
-
} else {
|
|
446
|
-
// TileJSON url, let ol-mapbox-style handle it
|
|
447
|
-
if (styleSource.tiles) {
|
|
448
|
-
styleSource.tiles = styleSource.tiles.map((url) =>
|
|
449
|
-
normalizeSourceUrl(
|
|
450
|
-
url,
|
|
451
|
-
this.accessToken,
|
|
452
|
-
this.accessTokenParam_,
|
|
453
|
-
styleUrl
|
|
454
|
-
)
|
|
455
|
-
);
|
|
456
|
-
}
|
|
457
|
-
setupVectorSource(
|
|
458
|
-
styleSource,
|
|
459
|
-
styleSource.url
|
|
460
|
-
? normalizeSourceUrl(
|
|
461
|
-
styleSource.url,
|
|
462
|
-
this.accessToken,
|
|
463
|
-
this.accessTokenParam_,
|
|
464
|
-
styleUrl
|
|
465
|
-
)
|
|
466
|
-
: undefined
|
|
467
|
-
).then((source) => {
|
|
468
|
-
applyStyle(this, style, sourceIdOrLayersList)
|
|
469
|
-
.then(() => {
|
|
470
|
-
this.configureSource(source, style);
|
|
471
|
-
})
|
|
472
|
-
.catch((error) => {
|
|
473
|
-
this.configureSource(source, style);
|
|
474
|
-
this.handleError(error);
|
|
475
|
-
});
|
|
185
|
+
this.dispatchEvent(new ErrorEvent(error));
|
|
186
|
+
const source = this.getSource();
|
|
187
|
+
source.setState(SourceState.ERROR);
|
|
476
188
|
});
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* Applies configuration from the provided source to this layer's source,
|
|
482
|
-
* and reconfigures the loader to add a feature that renders the background,
|
|
483
|
-
* if the style is configured with a background.
|
|
484
|
-
* @param {import("../source/VectorTile.js").default} source The source to configure from.
|
|
485
|
-
* @param {StyleObject} style The style to configure the background from.
|
|
486
|
-
*/
|
|
487
|
-
configureSource(source, style) {
|
|
488
|
-
const targetSource = this.getSource();
|
|
489
|
-
if (source !== targetSource) {
|
|
490
|
-
targetSource.setAttributions(source.getAttributions());
|
|
491
|
-
targetSource.setTileUrlFunction(source.getTileUrlFunction());
|
|
492
|
-
targetSource.setTileLoadFunction(source.getTileLoadFunction());
|
|
493
|
-
targetSource.tileGrid = source.tileGrid;
|
|
494
|
-
}
|
|
495
189
|
if (this.getBackground() === undefined) {
|
|
496
|
-
applyBackground(this,
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
const tileGrid = targetSource.getTileGrid();
|
|
500
|
-
this.setMaxResolution(tileGrid.getResolution(tileGrid.getMinZoom()));
|
|
190
|
+
applyBackground(this, options.styleUrl, {
|
|
191
|
+
accessToken: this.accessToken,
|
|
192
|
+
});
|
|
501
193
|
}
|
|
502
|
-
targetSource.setState(SourceState.READY);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Handle configuration or loading error.
|
|
507
|
-
* @param {Error} error The error.
|
|
508
|
-
* @protected
|
|
509
|
-
*/
|
|
510
|
-
handleError(error) {
|
|
511
|
-
this.dispatchEvent(new ErrorEvent(error));
|
|
512
|
-
const source = this.getSource();
|
|
513
|
-
source.setState(SourceState.ERROR);
|
|
514
194
|
}
|
|
515
195
|
}
|
|
516
196
|
|
|
@@ -155,7 +155,8 @@ class CanvasLayerRenderer extends LayerRenderer {
|
|
|
155
155
|
target.style.opacity === '' &&
|
|
156
156
|
opacity === 1 &&
|
|
157
157
|
(!opt_backgroundColor ||
|
|
158
|
-
(target
|
|
158
|
+
(target &&
|
|
159
|
+
target.style.backgroundColor &&
|
|
159
160
|
equals(
|
|
160
161
|
asArray(target.style.backgroundColor),
|
|
161
162
|
asArray(opt_backgroundColor)
|
|
@@ -184,9 +185,6 @@ class CanvasLayerRenderer extends LayerRenderer {
|
|
|
184
185
|
style.position = 'absolute';
|
|
185
186
|
style.width = '100%';
|
|
186
187
|
style.height = '100%';
|
|
187
|
-
if (opt_backgroundColor) {
|
|
188
|
-
style.backgroundColor = opt_backgroundColor;
|
|
189
|
-
}
|
|
190
188
|
context = createCanvasContext2D();
|
|
191
189
|
const canvas = context.canvas;
|
|
192
190
|
container.appendChild(canvas);
|
|
@@ -197,6 +195,13 @@ class CanvasLayerRenderer extends LayerRenderer {
|
|
|
197
195
|
this.container = container;
|
|
198
196
|
this.context = context;
|
|
199
197
|
}
|
|
198
|
+
if (
|
|
199
|
+
!this.containerReused &&
|
|
200
|
+
opt_backgroundColor &&
|
|
201
|
+
!this.container.style.backgroundColor
|
|
202
|
+
) {
|
|
203
|
+
this.container.style.backgroundColor = opt_backgroundColor;
|
|
204
|
+
}
|
|
200
205
|
}
|
|
201
206
|
|
|
202
207
|
/**
|
package/util.js
CHANGED