Skip to content

Commit

Permalink
[JavaScript] BaseLayerState used Enum load status
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Jul 27, 2023
1 parent 7c46cf8 commit 05bbba1
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions assets/src/modules/state/BaseLayer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import EventDispatcher from './../../utils/EventDispatcher.js';
import { convertBoolean } from './../utils/Converters.js';
import { BaseLayerTypes } from './../config/BaseLayer.js';
import { MapLayerLoadStatus } from './MapLayer.js';

/**
* Class representing a base layer state
Expand All @@ -20,6 +20,7 @@ export class BaseLayerState extends EventDispatcher {
super()
this._baseLayerConfig = baseLayerCfg;
this._itemState = itemState;
this._loadStatus = MapLayerLoadStatus.Undefined;
}

/**
Expand Down Expand Up @@ -119,32 +120,39 @@ export class BaseLayerState extends EventDispatcher {
}

/**
* Is base layer loading?
* The layer load status
* @see MapLayerLoadStatus
*
* @type {Boolean}
* @type {String}
**/
get loading() {
return this._loading;
get loadStatus() {
return this._loadStatus;
}


/**
* Set base layer's loading state
* Set layer load status
* @see MapLayerLoadStatus
*
* @param {Boolean}
* @param {String} status - Expected values provided by the map layer load status enum
**/
set loading(loading) {
const newVal = convertBoolean(loading);
set loadStatus(status) {
const statusKeys = Object.keys(MapLayerLoadStatus).filter(key => MapLayerLoadStatus[key] === status);
if (statusKeys.length != 1) {
throw new TypeError('Unkonw status: `'+status+'`!');
}

// No changes
if (this._loading == newVal) {
if (this._loadStatus == status) {
return;
}
// Set new value
this._loading = newVal;
this._loadStatus = status;

this.dispatch({
type: 'baselayer.loading.changed',
type: 'layer.load.status.changed',
name: this.name,
loading: this.loading,
loadStatus: this.loadStatus,
})
}
}
Expand Down

0 comments on commit 05bbba1

Please sign in to comment.