From dc03a6e56f7be5e25adfa741d8f2a5e4a6b772b7 Mon Sep 17 00:00:00 2001 From: ftoromanoff Date: Fri, 5 Jan 2024 15:30:00 +0100 Subject: [PATCH] refactor(Layer): simplification => supp Layer.setStyle() --- examples/misc_redraw_layer.html | 40 ++++++++++++--------------------- src/Layer/Layer.js | 8 ------- 2 files changed, 14 insertions(+), 34 deletions(-) diff --git a/examples/misc_redraw_layer.html b/examples/misc_redraw_layer.html index a88a6ce1a1..b85255b353 100644 --- a/examples/misc_redraw_layer.html +++ b/examples/misc_redraw_layer.html @@ -13,8 +13,8 @@
@@ -81,7 +81,6 @@ format: 'application/json', }); - // Define the functions that sets the color according to the properties function color1(properties) { if (properties.code_cultu == '28') { return '#FD8A8A'; } @@ -105,33 +104,29 @@ else { return '#E0E0E0'; } } - // Set the two different styles - const style1 = { - fill: { - color: color1, - opacity: 0.8 - }, - stroke: { - color: 'black', - width: 1.0, - }, - }; - - const style2 = { + const color = function (p) { + const styleBox = document.getElementById('styleBox'); + if (styleBox.value === '0') { + return color1(p); + } else if (styleBox.value === '1') { + return color2(p); + } + } + const style = { fill: { - color: color2, + color, opacity: 0.8 }, stroke: { color: 'black', width: 1.0, }, - }; + } // Create the layer where you specified the starting style var wfsAgriLayer = new itowns.ColorLayer('wfsAgri', { transparent: true, - style: style1, + style, source: wfsAgriLayer, zoom: { min: 11 }, }); @@ -139,13 +134,6 @@ // Function that calls the onChange event in the combobox function selectStyle() { - const styleBox = document.getElementById('styleBox'); - const layer = view.getLayerById('wfsAgri'); - if (styleBox.value === 'Style 1') { - layer.setStyle(style1); - } else if (styleBox.value === 'Style 2') { - layer.setStyle(style2); - } view.redrawLayer('wfsAgri'); } diff --git a/src/Layer/Layer.js b/src/Layer/Layer.js index fa4981b0a3..6b0c74a7bf 100644 --- a/src/Layer/Layer.js +++ b/src/Layer/Layer.js @@ -270,14 +270,6 @@ class Layer extends THREE.EventDispatcher { invalidateCache() { throw new Error('invalidateCache is not supported yet in this type of layer'); } - - /** - * Set the style of the layer. - * @param {StyleOptions} style Object containing style parameters. {@link StyleOptions} - */ - setStyle(style) { - this.style = new Style(style); - } } export default Layer;