Skip to content

Commit

Permalink
use array methods findIndex() and at()
Browse files Browse the repository at this point in the history
  • Loading branch information
dbauszus-glx committed Mar 5, 2024
1 parent d847fdc commit 3cbe626
Showing 1 changed file with 10 additions and 25 deletions.
35 changes: 10 additions & 25 deletions lib/layer/themes/graduated.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,16 @@ export default function(theme, feature) {

if (!isNaN(catValue) && catValue !== null) {

let catStyle;

// Iterate through cat array.
for (let i = 0; i < theme.cat_arr.length; i++) {

theme.cat_arr[i].style ??= theme.cat_arr[i]

// Break iteration is cat value is below current cat array value.
if (catValue <= parseFloat(theme.cat_arr[i].value)){

//Set a style if one has not been set yet
if(!catStyle){
catStyle ??= structuredClone(theme.cat_arr[i].style)
delete catStyle.label
}
break;
}

//Set the style for the element
catStyle = structuredClone(theme.cat_arr[i].style)
delete catStyle.label

}

// Merge catStyle for vector features.
const isLassThan = cat => catValue <= cat.value;

let index = theme.cat_arr.findIndex(isLassThan)

let cat = theme.cat_arr.at(index)

let catStyle = structuredClone(cat.style || cat)

delete catStyle.label

mapp.utils.merge(feature.style, catStyle)
}
}

0 comments on commit 3cbe626

Please sign in to comment.