From 1d946118011586e09344331001a8af0d51b9f81f Mon Sep 17 00:00:00 2001 From: Bouillaguet Quentin Date: Wed, 15 Jan 2025 16:55:55 +0100 Subject: [PATCH] refacto: move style up in layer --- src/Layer/ColorLayer.js | 12 ++++++++++++ src/Layer/LabelLayer.js | 9 ++++++++- src/Layer/Layer.js | 17 ----------------- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/Layer/ColorLayer.js b/src/Layer/ColorLayer.js index 082879f4f6..77b9f4db47 100644 --- a/src/Layer/ColorLayer.js +++ b/src/Layer/ColorLayer.js @@ -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. @@ -93,6 +94,7 @@ class ColorLayer extends RasterLayer { deprecatedColorLayerOptions(config); const { + style = {}, effect_type = 0, effect_parameter = 1.0, transparent, @@ -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} */ diff --git a/src/Layer/LabelLayer.js b/src/Layer/LabelLayer.js index ff2ffccc42..22ddb93161 100644 --- a/src/Layer/LabelLayer.js +++ b/src/Layer/LabelLayer.js @@ -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(); @@ -177,6 +177,7 @@ class LabelLayer extends GeometryLayer { constructor(id, config = {}) { const { domElement, + style, performance = true, forceClampToTerrain = false, margin, @@ -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; diff --git a/src/Layer/Layer.js b/src/Layer/Layer.js index 8eb67b9f22..2b65fcb7c4 100644 --- a/src/Layer/Layer.js +++ b/src/Layer/Layer.js @@ -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. @@ -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} .
- * 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 @@ -92,7 +86,6 @@ class Layer extends THREE.EventDispatcher { const { source, name, - style = {}, subdivisionThreshold = 256, addLabelLayer = false, cacheLifeTime, @@ -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} */