Skip to content

Commit

Permalink
refactor(StyleContext): add setFeature to access feature.type
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Dec 13, 2023
1 parent b736f72 commit 6b44ef9
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Core/Style.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,24 @@ function defineStyleProperty(style, category, name, value, defaultValue) {
*
* @property {Object} globals Style type (fill, stroke, point, text and or icon) to consider, it also
* contains the current zoom.
* @property {Object} collection The FeatureCollection to which the FeatureGeometry is attached
* @property {Object} collection The FeatureCollection to which the FeatureGeometry is attached.
* @property {Object} properties Properties of the FeatureGeometry.
* @property {string} type Geometry type of the feature. Can be `point`, `line`, or `polygon`.
* @property {Coordinates} coordinates The coordinates (in world space) of the last vertex (x, y, z) set with
* setLocalCoordinatesFromArray().
* private properties:
* @property {Coordinates} worldCoord @private Coordinates object to store coordinates in world space.
* @property {Coordinates} localCoordinates @private Coordinates object to store coordinates in local space.
* @property {boolean} worldCoordsComputed @private Have the world coordinates already been computed
* from the local coordinates?
* @property {Feature} feature @private The itowns feature of interest.
* @property {FeatureGeometry} geometry @private The FeatureGeometry to compute the style.
*/
export class StyleContext {
#worldCoord = new Coordinates('EPSG:4326', 0, 0, 0);
#localCoordinates = new Coordinates('EPSG:4326', 0, 0, 0);
#worldCoordsComputed = true;
#feature = {};
#geometry = {};
/**
* @constructor
Expand All @@ -185,6 +189,10 @@ export class StyleContext {
this.globals = {};
}

setFeature(f) {
this.#feature = f;
}

setGeometry(g) {
this.#geometry = g;
}
Expand All @@ -203,6 +211,10 @@ export class StyleContext {
return this.#geometry.properties;
}

get type() {
return this.#feature.type;
}

get coordinates() {
if (!this.#worldCoordsComputed) {
this.#worldCoordsComputed = true;
Expand Down Expand Up @@ -646,7 +658,7 @@ class Style {
* Map style object properties (fill, stroke, point, text and icon) from context to Style.
* Only the necessary properties are mapped to object.
* if a property is expression, the mapped value will be the expression result depending on context.
* @param {Object} context The context of the FeatureGeometry that we want to get the Style.
* @param {StyleContext} context The context of the FeatureGeometry that we want to get the Style.
*
* @return {Style} mapped style depending on context.
*/
Expand Down

0 comments on commit 6b44ef9

Please sign in to comment.