Use union type for source state

This commit is contained in:
Andreas Hocevar
2021-09-04 20:55:13 +02:00
parent 492458a141
commit 57f147988d
24 changed files with 49 additions and 73 deletions
+1 -1
View File
@@ -260,7 +260,7 @@ class BaseLayer extends BaseObject {
/**
* @abstract
* @return {import("../source/State.js").default} Source state.
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
return abstract();
+2 -3
View File
@@ -7,7 +7,6 @@ import CollectionEventType from '../CollectionEventType.js';
import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
import ObjectEventType from '../ObjectEventType.js';
import SourceState from '../source/State.js';
import {assert} from '../asserts.js';
import {assign, clear} from '../obj.js';
import {getIntersection} from '../extent.js';
@@ -343,10 +342,10 @@ class LayerGroup extends BaseLayer {
}
/**
* @return {import("../source/State.js").default} Source state.
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
return SourceState.READY;
return 'ready';
}
}
+1 -2
View File
@@ -5,7 +5,6 @@ import BaseLayer from './Base.js';
import EventType from '../events/EventType.js';
import LayerProperty from './Property.js';
import RenderEventType from '../render/EventType.js';
import SourceState from '../source/State.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {listen, unlistenByKey} from '../events.js';
@@ -213,7 +212,7 @@ class Layer extends BaseLayer {
*/
getSourceState() {
const source = this.getSource();
return !source ? SourceState.UNDEFINED : source.getState();
return !source ? 'undefined' : source.getState();
}
/**
+3 -4
View File
@@ -4,7 +4,6 @@
import BaseEvent from '../events/Event.js';
import EventType from '../events/EventType.js';
import MVT from '../format/MVT.js';
import SourceState from '../source/State.js';
import VectorTileLayer from '../layer/VectorTile.js';
import VectorTileSource from '../source/VectorTile.js';
import {applyBackground, applyStyle} from 'ol-mapbox-style';
@@ -144,7 +143,7 @@ class MapboxVectorLayer extends VectorTileLayer {
constructor(options) {
const declutter = 'declutter' in options ? options.declutter : true;
const source = new VectorTileSource({
state: SourceState.LOADING,
state: 'loading',
format: new MVT(),
});
@@ -179,12 +178,12 @@ class MapboxVectorLayer extends VectorTileLayer {
accessToken: this.accessToken,
})
.then(() => {
source.setState(SourceState.READY);
source.setState('ready');
})
.catch((error) => {
this.dispatchEvent(new ErrorEvent(error));
const source = this.getSource();
source.setState(SourceState.ERROR);
source.setState('error');
});
if (this.getBackground() === undefined) {
applyBackground(this, options.styleUrl, {