Skip to content

Commit

Permalink
refacto: move style up in layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Desplandis committed Jan 15, 2025
1 parent 011670a commit 1d94611
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
12 changes: 12 additions & 0 deletions src/Layer/ColorLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import RasterLayer from 'Layer/RasterLayer';
import { updateLayeredMaterialNodeImagery } from 'Process/LayeredMaterialNodeProcessing';
import { RasterColorTile } from 'Renderer/RasterTile';
import { deprecatedColorLayerOptions } from 'Core/Deprecated/Undeprecator';
import Style from 'Core/Style';

/**
* Fires when the visiblity of the layer has changed.
Expand Down Expand Up @@ -93,6 +94,7 @@ class ColorLayer extends RasterLayer {
deprecatedColorLayerOptions(config);

const {
style = {},
effect_type = 0,
effect_parameter = 1.0,
transparent,
Expand All @@ -119,6 +121,16 @@ class ColorLayer extends RasterLayer {
this.opacity = 1.0;
this.defineLayerProperty('opacity', this.opacity);

if (style && !(style instanceof Style)) {
if (typeof style.fill?.pattern === 'string') {
console.warn('Using style.fill.pattern = { source: Img|url } is adviced');
style.fill.pattern = { source: style.fill.pattern };
}
this.style = new Style(style);
} else {
this.style = style || new Style();
}

/**
* @type {number}
*/
Expand Down
9 changes: 8 additions & 1 deletion src/Layer/LabelLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import GeometryLayer from 'Layer/GeometryLayer';
import Coordinates from 'Core/Geographic/Coordinates';
import Extent from 'Core/Geographic/Extent';
import Label from 'Core/Label';
import { readExpression, StyleContext } from 'Core/Style';
import Style, { readExpression, StyleContext } from 'Core/Style';
import { ScreenGrid } from 'Renderer/Label2DRenderer';

const context = new StyleContext();
Expand Down Expand Up @@ -177,6 +177,7 @@ class LabelLayer extends GeometryLayer {
constructor(id, config = {}) {
const {
domElement,
style,
performance = true,
forceClampToTerrain = false,
margin,
Expand All @@ -194,6 +195,12 @@ class LabelLayer extends GeometryLayer {
this.forceClampToTerrain = forceClampToTerrain;
this.margin = margin;

if (style && !(style instanceof Style)) {
this.style = new Style(style);
} else {
this.style = style || new Style();
}

this.toHide = new THREE.Group();

this.labelDomelement = domElement;
Expand Down
17 changes: 0 additions & 17 deletions src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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 Style from 'Core/Style';

/**
* @property {boolean} isLayer - Used to checkout whether this layer is a Layer.
Expand Down Expand Up @@ -52,11 +51,6 @@ class Layer extends THREE.EventDispatcher {
* @param {Source|boolean} config.source - instantiated Source specifies data source to display.
* if config.source is a boolean, it can only be false. if config.source is false,
* the layer doesn't need Source (like debug Layer or procedural layer).
* @param {StyleOptions} [config.style] - an object that contain any properties
* (order, zoom, fill, stroke, point, text or/and icon)
* and sub properties of a Style (@see {@link StyleOptions}). Or directly a {@link Style} .<br/>
* When entering a StyleOptions the missing style properties will be look for in the data (if any)
* what won't be done when you use a Style.
* @param {number} [config.cacheLifeTime=Infinity] - set life time value in cache.
* This value is used for cache expiration mechanism.
* @param {(boolean|Object)} [config.addLabelLayer] - Used to tell if this layer has
Expand Down Expand Up @@ -92,7 +86,6 @@ class Layer extends THREE.EventDispatcher {
const {
source,
name,
style = {},
subdivisionThreshold = 256,
addLabelLayer = false,
cacheLifeTime,
Expand Down Expand Up @@ -135,16 +128,6 @@ class Layer extends THREE.EventDispatcher {

this.crs = crs;

if (style && !(style instanceof Style)) {
if (typeof style.fill?.pattern === 'string') {
console.warn('Using style.fill.pattern = { source: Img|url } is adviced');
style.fill.pattern = { source: style.fill.pattern };
}
this.style = new Style(style);
} else {
this.style = style || new Style();
}

/**
* @type {number}
*/
Expand Down

0 comments on commit 1d94611

Please sign in to comment.