Skip to content

Conversation

@Desplandis
Copy link
Contributor

@Desplandis Desplandis commented Jun 11, 2025

Description

This PR introduces several changes to the base Layer and layer-related classes. The main changes includes the migration of LayerUpdateState and LayerUpdateStrategy to typescript, the reorganization of Layer properties for better separation of concerns and the addition of a startup lifecycle method as a first step to cleanup the mess that is View#preprocessLayer. This will not break existing layers within iTowns but could break custom layers inheriting directly from Layer.

Motivation and Context

The motivation for the following changes is as follow:

  • Introduction of Layer#startup lifecycle method for separation of concerns, allowing for more explicit initialization of layers. Follow-up: remove View#preprocessLayer and most of the complexity of View#addLayer.
  • Migration of LayerUpdateState and LayerUpdateStrategy to typescript (I will personally rebase Further simplify tile subdivision mechanism #2525 on this PR since there is some function paramater changes to chooseNextLevelToFetch).
    Follow-up: migrate TileMesh-related modules to typescript (see Migrate TileMesh-related modules to typescript #2557) / migrate LayerNodeProcessing
  • Move ImageryLayers to its own module as I have short-term plan to migrate all layers to typescript (with some type hacks) and have no plan to migrate ImageryLayers (which given the code needs an entire refactoring...).
    Follow-up: migrate Layer modules to typescript
  • Move some layers properties to inherited classes for better separation of concerns, facilitate the typechecking of Layer and children.
    • layerUpdateStrategy used only on RasterLayer-derived classes
    • style used only on *3DTilesLayer, FeatureGeometryLayer and ColorLayer
    • mergeFeatures/addLabel used only on FeatureGeometryLayer and ColorLayer
      Follow-up: migrate Layer modules to typescript

Changes considered but not done on this PR:

  • Cleanup the mess in View#preprocessLayer
  • Moving the caching mechanism in classes where it is effectively used
  • Some things that I surely forgot ;)

Screenshots (if appropriate)

@Desplandis Desplandis force-pushed the cleanup/layer branch 2 times, most recently from b56d9e0 to 2c2e6bf Compare June 11, 2025 13:19
@Desplandis Desplandis force-pushed the cleanup/layer branch 6 times, most recently from 8f932c2 to 2292cc4 Compare June 25, 2025 14:37
@Desplandis Desplandis marked this pull request as ready for review June 25, 2025 14:55
@Desplandis
Copy link
Contributor Author

@AnthonyGlt @mgermerie @HoloTheDrunk If anyone want to review this PR. Especially if you depend on some properties here.

@AnthonyGlt
Copy link
Contributor

@Desplandis Thank you for the PR.
I like this clean up. It makes the code easier to understand !

nodeLevel: number,
currentLevel: number,
failureParams: { lowestLevelError: number },
zoom?: { min: number; max: number },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zoom is bothering me a bit because it's only used for _dichotomy() but I don't have an idea to make it better so OK 👍

*/
this.isColorLayer = true;

this.style = style instanceof Style ? style : new Style(style);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to move style into Layer, in order to centralize common properties (visibility, opacity/scale, etc.) that every layer can have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since not all layers are styled (e.g. elevation layers, pointcloud layers), I decided to remove those properties from the base Layer class.

Comment on lines +188 to +196
async startup(/* context */) {
try {
await Promise.all(this._promises);
this._resolve();
} catch (error) {
this._reject(error);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
async startup(/* context */) {
try {
await Promise.all(this._promises);
this._resolve();
} catch (error) {
this._reject(error);
}
}
async startup(/* context */) {
await Promise.all(this._promises)
.then(this._resolve)
.catch (this._reject);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depends on whether we want to use the async paradigm or not, but I will follow your suggestion here.

@Desplandis Desplandis merged commit 35935c7 into iTowns:master Sep 25, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants