Skip to content

Commit

Permalink
refactor(Layer): simplification => supp Layer.setStyle()
Browse files Browse the repository at this point in the history
  • Loading branch information
ftoromanoff committed Sep 25, 2024
1 parent 36b8277 commit dc03a6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 34 deletions.
40 changes: 14 additions & 26 deletions examples/misc_redraw_layer.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<div id="viewerDiv"></div>
<div id="description" style="border-radius: 5%;">
<select id="styleBox" onChange="selectStyle()" style="font-size: 15px; background-color: rgba(0,0,0,0.3); border-radius: 5%; width: 100px; height: 25px; color: white; text-align: center;">
<option>Style 1</option>
<option>Style 2</option>
<option value='0'>Style 1</option>
<option value='1'>Style 2</option>
</select>
</div>
<script src="js/GUI/GuiTools.js"></script>
Expand Down Expand Up @@ -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'; }
Expand All @@ -105,47 +104,36 @@
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 },
});
view.addLayer(wfsAgriLayer);

// 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');
}

Expand Down
8 changes: 0 additions & 8 deletions src/Layer/Layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dc03a6e

Please sign in to comment.