-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refacto: migrate Layer to typescript
- Loading branch information
1 parent
1d94611
commit 6b5d183
Showing
1 changed file
with
25 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { STRATEGY_MIN_NETWORK_TRAFFIC } from 'Layer/LayerUpdateStrategy'; | |
import InfoLayer from 'Layer/InfoLayer'; | ||
import Source from 'Source/Source'; | ||
import Cache from 'Core/Scheduler/Cache'; | ||
import { ProjectionLike } from 'Core/Geographic/Crs'; | ||
|
||
/** | ||
* @property {boolean} isLayer - Used to checkout whether this layer is a Layer. | ||
Check warning on line 9 in src/Layer/Layer.ts GitHub Actions / Build bundle, check Linter and generate documentation
Check warning on line 9 in src/Layer/Layer.ts GitHub Actions / Build bundle, check Linter and generate documentation
|
||
|
@@ -32,7 +33,29 @@ import Cache from 'Core/Scheduler/Cache'; | |
* @property {number} [zoom.min=0] - this is the minimum zoom from which it'll be visible. | ||
* | ||
*/ | ||
class Layer extends THREE.EventDispatcher { | ||
abstract class Layer<D, T> extends THREE.EventDispatcher { | ||
Check failure on line 36 in src/Layer/Layer.ts GitHub Actions / Build bundle, check Linter and generate documentation
|
||
readonly isLayer: true; | ||
readonly id: string; | ||
|
||
name: string; | ||
crs: ProjectionLike; | ||
source: Source; // TODO | ||
subdivisionThreshold: number; // TODO: Move-up | ||
sizeDiagonalTexture: number; // TODO: Move-up | ||
options: unknown; | ||
addLabelLayer: boolean; | ||
updateStrategy: any; // TODO | ||
zoom: { min: number; max: number }; // TODO: Move-up? | ||
info: InfoLayer; | ||
private _promises: Promise<any>[]; // TODO: Typing??? | ||
ready: boolean; | ||
whenReady: Promise<this>; | ||
|
||
private _resolve: (value: unknown) => void; // TODO | ||
private _reject: (value: unknown) => void; // TODO | ||
cache: Cache; | ||
mergeFeatures: boolean; | ||
|
||
/** | ||
* Don't use directly constructor to instance a new Layer. Instead, use | ||
* another available type of Layer, implement a new one inheriting from this | ||
|
@@ -82,7 +105,7 @@ class Layer extends THREE.EventDispatcher { | |
* layerToListen.addEventListener('visible-property-changed', (event) => console.log(event)); | ||
* layerToListen.addEventListener('opacity-property-changed', (event) => console.log(event)); | ||
*/ | ||
constructor(id, config = {}) { | ||
constructor(id: string, config = {}) { | ||
const { | ||
source, | ||
name, | ||
|
@@ -98,32 +121,18 @@ class Layer extends THREE.EventDispatcher { | |
|
||
super(); | ||
|
||
/** | ||
* @type {boolean} | ||
* @readonly | ||
*/ | ||
this.isLayer = true; | ||
|
||
/** | ||
* @type {string} | ||
* @readonly | ||
*/ | ||
this.id = id; | ||
Object.defineProperty(this, 'id', { | ||
writable: false, | ||
}); | ||
|
||
/** | ||
* @type {string} | ||
*/ | ||
this.name = name; | ||
|
||
if (source === undefined || source === true) { | ||
throw new Error(`Layer ${id} needs Source`); | ||
} | ||
/** | ||
* @type {Source} | ||
*/ | ||
this.source = source || new Source({ url: 'none' }); | ||
|
||
this.crs = crs; | ||
|
@@ -153,20 +162,10 @@ class Layer extends THREE.EventDispatcher { | |
|
||
this.info = new InfoLayer(this); | ||
|
||
/** | ||
* @type {boolean} | ||
*/ | ||
this.ready = false; | ||
|
||
/** | ||
* @type {Array<Promise<any>>} | ||
* @protected | ||
*/ | ||
this._promises = []; | ||
|
||
/** | ||
* @type {Promise<this>} | ||
*/ | ||
this.whenReady = new Promise((re, rj) => { | ||
this._resolve = re; | ||
this._reject = rj; | ||
|
@@ -178,9 +177,6 @@ class Layer extends THREE.EventDispatcher { | |
|
||
this._promises.push(this.source.whenReady); | ||
|
||
/** | ||
* @type {Cache} | ||
*/ | ||
this.cache = new Cache(cacheLifeTime); | ||
|
||
this.mergeFeatures = mergeFeatures; | ||
|