When a checkbox will be checked or unchecked, I want the icon to appear or dissappear. Below I am showing how the icon url path looks. Is there any way I can do that? I've been trying myself to add this code to the switch case, but I'm a beginner with js & jquery and I don't know what Im doing wrong.
$('#someId').change(function() {
if(this.checked) {
$(icon = greenIcon).show(1);
}
else {
$(icon = greenIcon).hide(1);
}
});
$('#someId2').click(function() {
if(this.checked) {
$(icon = yellowIcon).show(1);
}
else {
$(icon = yellowIcon).hide(1);
}
});
$('#someId3').click(function() {
if(this.checked) {
$(icon = redIcon).show(1);
}
else {
$(icon = redIcon).hide(1);
}
});
$('#someId4').click(function() {
if(this.checked) {
$(icon = blueIcon).show(1);
}
else {
$(icon = blueIcon).hide(1);
}
});
into this
switch (feature.properties.status) {
case 0:
icon = greenIcon; break;
case 1:
case 11:
case 12:
icon = yellowIcon; break;
case 2:
case 21:
case 22:
icon = redIcon; break;
case 5:
default:
icon = blueIcon; break;
}
Icons are added to the code like this:
var greenIcon = new LeafIcon({iconUrl: L.Icon.Default.imagePath + 'marker-icon-ok.png'});
var redIcon = new LeafIcon({iconUrl: L.Icon.Default.imagePath + 'marker-icon-err.png'});
var yellowIcon = new LeafIcon({iconUrl: L.Icon.Default.imagePath + 'marker-icon-warn.png'});
var blueIcon = new LeafIcon({iconUrl: L.Icon.Default.imagePath + 'marker-icon-sleep.png'});
So when a checkbox is checked or unchecked, the icon would appear or dissappear. Is it possible?
Aucun commentaire:
Enregistrer un commentaire