I want my features to change every time I hit checkbox. I’ve added event listenter to a change. I supposed I would go this statement (as I stated that the ‘zero’ value is [0]) if (currentValue.length == 1) { feature.set('number', data_languages[language][index]); feature.changed() }
Then it was supposed to go ‘else’ statement (as any data in my variable data_languages[language][index] is an array of 4 elements). But I keep going the ‘if’ statement.
Here is the code:
input.addEventListener('change', function () {
console.log(vectorLayer.getSource().getFeatures())
if (input.checked) {
var language = Object.keys(language_codes).find(key => language_codes[key] == input.id.split(':')[0]);
var category = input.id.split(':')[1]
if (category) {
category = parseInt(category)
// console.log(language, category)
var features = vectorLayer.getSource().getFeatures();
features.forEach(function (feature, index) {
var currentValue = feature.get('number');
if (currentValue.length == 1) {
feature.set('number', data_languages[language][index]);
feature.changed()
} else {
console.log(feature.get('number'))
}
});
}
}
});
I’m just exploring Openlayers and some things seem quite difficult to understand. I hope anyone can help me figure out what I am doing wrong here.
baeko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.