@mapwhit/tilerenderer 1.2.2 → 1.3.0
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/build/min/package.json +1 -1
- package/package.json +1 -1
- package/src/style/style.js +70 -23
package/build/min/package.json
CHANGED
package/package.json
CHANGED
package/src/style/style.js
CHANGED
|
@@ -41,6 +41,7 @@ class Style extends Evented {
|
|
|
41
41
|
loadGlyphRange: this.loadGlyphRange.bind(this)
|
|
42
42
|
});
|
|
43
43
|
#layerIndex = new StyleLayerIndex();
|
|
44
|
+
#opsQueue = [];
|
|
44
45
|
|
|
45
46
|
constructor(map, options = {}) {
|
|
46
47
|
super();
|
|
@@ -89,7 +90,10 @@ class Style extends Evented {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
setGlobalStateProperty(name, value) {
|
|
92
|
-
this.
|
|
93
|
+
if (!this._loaded) {
|
|
94
|
+
this.#opsQueue.push(() => this.setGlobalStateProperty(name, value));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
93
97
|
|
|
94
98
|
const newValue = value === null ? (this.stylesheet.state?.[name]?.default ?? null) : value;
|
|
95
99
|
|
|
@@ -107,7 +111,10 @@ class Style extends Evented {
|
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
setGlobalState(newStylesheetState) {
|
|
110
|
-
this.
|
|
114
|
+
if (!this._loaded) {
|
|
115
|
+
this.#opsQueue.push(() => this.setGlobalState(newStylesheetState));
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
111
118
|
|
|
112
119
|
const changedGlobalStateRefs = [];
|
|
113
120
|
|
|
@@ -225,6 +232,9 @@ class Style extends Evented {
|
|
|
225
232
|
this.light = this.stylesheet.light;
|
|
226
233
|
this._light = new Light(this.light);
|
|
227
234
|
|
|
235
|
+
this.#opsQueue.forEach(op => op());
|
|
236
|
+
this.#opsQueue = [];
|
|
237
|
+
|
|
228
238
|
this.fire(new Event('data', { dataType: 'style' }));
|
|
229
239
|
this.fire(new Event('style.load'));
|
|
230
240
|
}
|
|
@@ -301,12 +311,6 @@ class Style extends Evented {
|
|
|
301
311
|
return false;
|
|
302
312
|
}
|
|
303
313
|
|
|
304
|
-
_checkLoaded() {
|
|
305
|
-
if (!this._loaded) {
|
|
306
|
-
throw new Error('Style is not done loading');
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
314
|
/**
|
|
311
315
|
* Apply queued style updates in a batch and recalculate zoom-dependent paint properties.
|
|
312
316
|
*/
|
|
@@ -390,13 +394,18 @@ class Style extends Evented {
|
|
|
390
394
|
}
|
|
391
395
|
|
|
392
396
|
listImages() {
|
|
393
|
-
this.
|
|
397
|
+
if (!this._loaded) {
|
|
398
|
+
return;
|
|
399
|
+
}
|
|
394
400
|
|
|
395
401
|
return this.imageManager.listImages();
|
|
396
402
|
}
|
|
397
403
|
|
|
398
404
|
addSource(id, source) {
|
|
399
|
-
this.
|
|
405
|
+
if (!this._loaded) {
|
|
406
|
+
this.#opsQueue.push(() => this.addSource(id, source));
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
400
409
|
|
|
401
410
|
if (this._sources[id] !== undefined) {
|
|
402
411
|
throw new Error('There is already a source with this ID');
|
|
@@ -432,7 +441,10 @@ class Style extends Evented {
|
|
|
432
441
|
* @throws {Error} if no source is found with the given ID
|
|
433
442
|
*/
|
|
434
443
|
removeSource(id) {
|
|
435
|
-
this.
|
|
444
|
+
if (!this._loaded) {
|
|
445
|
+
this.#opsQueue.push(() => this.removeSource(id));
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
436
448
|
|
|
437
449
|
if (this._sources[id] === undefined) {
|
|
438
450
|
throw new Error('There is no source with this ID');
|
|
@@ -464,7 +476,10 @@ class Style extends Evented {
|
|
|
464
476
|
* @param {GeoJSON|string} data GeoJSON source
|
|
465
477
|
*/
|
|
466
478
|
setGeoJSONSourceData(id, data) {
|
|
467
|
-
this.
|
|
479
|
+
if (!this._loaded) {
|
|
480
|
+
this.#opsQueue.push(() => this.setGeoJSONSourceData(id, data));
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
468
483
|
|
|
469
484
|
assert(this._sources[id] !== undefined, 'There is no source with this ID');
|
|
470
485
|
const geojsonSource = this._sources[id].getSource();
|
|
@@ -519,7 +534,10 @@ class Style extends Evented {
|
|
|
519
534
|
* @param {string} [before] ID of an existing layer to insert before
|
|
520
535
|
*/
|
|
521
536
|
addLayer(layerObject, before) {
|
|
522
|
-
this.
|
|
537
|
+
if (!this._loaded) {
|
|
538
|
+
this.#opsQueue.push(() => this.addLayer(layerObject, before));
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
523
541
|
|
|
524
542
|
const id = layerObject.id;
|
|
525
543
|
|
|
@@ -568,7 +586,10 @@ class Style extends Evented {
|
|
|
568
586
|
* @param {string} [before] ID of an existing layer to insert before
|
|
569
587
|
*/
|
|
570
588
|
moveLayer(id, before) {
|
|
571
|
-
this.
|
|
589
|
+
if (!this._loaded) {
|
|
590
|
+
this.#opsQueue.push(() => this.moveLayer(id, before));
|
|
591
|
+
return;
|
|
592
|
+
}
|
|
572
593
|
this._changed = true;
|
|
573
594
|
|
|
574
595
|
const layer = this._layers.get(id);
|
|
@@ -593,7 +614,10 @@ class Style extends Evented {
|
|
|
593
614
|
* @fires error
|
|
594
615
|
*/
|
|
595
616
|
removeLayer(id) {
|
|
596
|
-
this.
|
|
617
|
+
if (!this._loaded) {
|
|
618
|
+
this.#opsQueue.push(() => this.removeLayer(id));
|
|
619
|
+
return;
|
|
620
|
+
}
|
|
597
621
|
|
|
598
622
|
const layer = this._layers.get(id);
|
|
599
623
|
if (!layer) {
|
|
@@ -624,7 +648,10 @@ class Style extends Evented {
|
|
|
624
648
|
}
|
|
625
649
|
|
|
626
650
|
setLayerZoomRange(layerId, minzoom, maxzoom) {
|
|
627
|
-
this.
|
|
651
|
+
if (!this._loaded) {
|
|
652
|
+
this.#opsQueue.push(() => this.setLayerZoomRange(layerId, minzoom, maxzoom));
|
|
653
|
+
return;
|
|
654
|
+
}
|
|
628
655
|
|
|
629
656
|
const layer = this.getLayer(layerId);
|
|
630
657
|
if (!layer) {
|
|
@@ -646,7 +673,10 @@ class Style extends Evented {
|
|
|
646
673
|
}
|
|
647
674
|
|
|
648
675
|
setFilter(layerId, filter) {
|
|
649
|
-
this.
|
|
676
|
+
if (!this._loaded) {
|
|
677
|
+
this.#opsQueue.push(() => this.setFilter(layerId, filter));
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
650
680
|
|
|
651
681
|
const layer = this.getLayer(layerId);
|
|
652
682
|
if (!layer) {
|
|
@@ -680,7 +710,10 @@ class Style extends Evented {
|
|
|
680
710
|
}
|
|
681
711
|
|
|
682
712
|
setLayoutProperty(layerId, name, value) {
|
|
683
|
-
this.
|
|
713
|
+
if (!this._loaded) {
|
|
714
|
+
this.#opsQueue.push(() => this.setLayoutProperty(layerId, name, value));
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
684
717
|
|
|
685
718
|
const layer = this.getLayer(layerId);
|
|
686
719
|
if (!layer) {
|
|
@@ -713,7 +746,10 @@ class Style extends Evented {
|
|
|
713
746
|
}
|
|
714
747
|
|
|
715
748
|
setPaintProperty(layerId, name, value) {
|
|
716
|
-
this.
|
|
749
|
+
if (!this._loaded) {
|
|
750
|
+
this.#opsQueue.push(() => this.setPaintProperty(layerId, name, value));
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
717
753
|
|
|
718
754
|
const layer = this.getLayer(layerId);
|
|
719
755
|
if (!layer) {
|
|
@@ -749,7 +785,10 @@ class Style extends Evented {
|
|
|
749
785
|
}
|
|
750
786
|
|
|
751
787
|
setFeatureState(feature, state) {
|
|
752
|
-
this.
|
|
788
|
+
if (!this._loaded) {
|
|
789
|
+
this.#opsQueue.push(() => this.setFeatureState(feature, state));
|
|
790
|
+
return;
|
|
791
|
+
}
|
|
753
792
|
const sourceId = feature.source;
|
|
754
793
|
const sourceLayer = feature.sourceLayer;
|
|
755
794
|
const sourceCache = this._sources[sourceId];
|
|
@@ -776,7 +815,10 @@ class Style extends Evented {
|
|
|
776
815
|
}
|
|
777
816
|
|
|
778
817
|
removeFeatureState(target, key) {
|
|
779
|
-
this.
|
|
818
|
+
if (!this._loaded) {
|
|
819
|
+
this.#opsQueue.push(() => this.removeFeatureState(target, key));
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
780
822
|
const sourceId = target.source;
|
|
781
823
|
const sourceCache = this._sources[sourceId];
|
|
782
824
|
|
|
@@ -802,7 +844,9 @@ class Style extends Evented {
|
|
|
802
844
|
}
|
|
803
845
|
|
|
804
846
|
getFeatureState(feature) {
|
|
805
|
-
this.
|
|
847
|
+
if (!this._loaded) {
|
|
848
|
+
return;
|
|
849
|
+
}
|
|
806
850
|
const sourceId = feature.source;
|
|
807
851
|
const sourceLayer = feature.sourceLayer;
|
|
808
852
|
const sourceCache = this._sources[sourceId];
|
|
@@ -962,7 +1006,10 @@ class Style extends Evented {
|
|
|
962
1006
|
}
|
|
963
1007
|
|
|
964
1008
|
setLight(lightOptions) {
|
|
965
|
-
this.
|
|
1009
|
+
if (!this._loaded) {
|
|
1010
|
+
this.#opsQueue.push(() => this.setLight(lightOptions));
|
|
1011
|
+
return;
|
|
1012
|
+
}
|
|
966
1013
|
|
|
967
1014
|
const light = this._light.getLight();
|
|
968
1015
|
let _update = false;
|