Skip to content

Commit

Permalink
refacto: migrate Layer to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Jan 17, 2025
1 parent 1d94611 commit 6b5d183
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions src/Layer/Layer.js → src/Layer/Layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

tsdoc-undefined-tag: The TSDoc tag "@Property" is not defined in this configuration

Check warning on line 9 in src/Layer/Layer.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

tsdoc-malformed-inline-tag: Expecting a TSDoc tag starting with "{@"

Check warning on line 9 in src/Layer/Layer.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

tsdoc-escape-right-brace: The "}" character should be escaped using a backslash to avoid confusion with a TSDoc inline tag
Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

'D' is defined but never used

Check failure on line 36 in src/Layer/Layer.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

'T' is defined but never used
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

Check failure on line 47 in src/Layer/Layer.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

Unexpected any. Specify a different type
zoom: { min: number; max: number }; // TODO: Move-up?
info: InfoLayer;
private _promises: Promise<any>[]; // TODO: Typing???

Check failure on line 50 in src/Layer/Layer.ts

View workflow job for this annotation

GitHub Actions / Build bundle, check Linter and generate documentation

Unexpected any. Specify a different type
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
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 6b5d183

Please sign in to comment.