From 6b5d18310e51fa83913f76fdcdfbdab8b9bc77f8 Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Fri, 17 Jan 2025 08:21:43 +0100 Subject: [PATCH] refacto: migrate Layer to typescript --- src/Layer/{Layer.js => Layer.ts} | 54 +++++++++++++++----------------- 1 file changed, 25 insertions(+), 29 deletions(-) rename src/Layer/{Layer.js => Layer.ts} (93%) diff --git a/src/Layer/Layer.js b/src/Layer/Layer.ts similarity index 93% rename from src/Layer/Layer.js rename to src/Layer/Layer.ts index 2b65fcb7c4..24168a9b21 100644 --- a/src/Layer/Layer.js +++ b/src/Layer/Layer.ts @@ -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. @@ -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 extends THREE.EventDispatcher { + 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[]; // TODO: Typing??? + ready: boolean; + whenReady: Promise; + + 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>} - * @protected - */ this._promises = []; - /** - * @type {Promise} - */ 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;