# leaflet / change a geojson divicon html

I have a geojson layer with a divIcon and now i want to change it. i have tried whit seticon but it does not work. How could i do it?

This is what I am trying:

papesjson.eachLayer(function(layer){
awesomeclase ="fa-circle-o-notch";
}
else if (layer.feature.properties.estado == "PENDIENTE REPOSICION"){
awesomeclase = "fa-plus";
}
awesomeclase = "fa-times";
}
else {
awesomeclase = "fa-circle";
}
var myIcon = L.divIcon({
iconSize: new L.Point(50, 50),
//iconAnchor:[50, 50],
className: "divicon",
html:'<i id = "'+layer.feature.properties.codigo+'" class="fa ' + awesomeclase + '" style="color:'+ getColor(layer.feature.properties.modelo) + ';">'
});

layer.setIcon(myIcon);
});

• could it be because the html snipplet is not valid? you open the <i> but don't close it … – christoph Jul 15 '15 at 3:49

not sure if this fits your use case, but you might be able to use pointToLayer when constructing the geojson

var papesjson = L.geoJson(someGeojson, {
pointToLayer: function (feature, latlng) {

awesomeclase ="fa-circle-o-notch";
}
else if (feature.properties.estado == "PENDIENTE REPOSICION"){
awesomeclase = "fa-plus";
}
awesomeclase = "fa-times";
}
else {
awesomeclase = "fa-circle";
}
var myIcon = L.divIcon({
iconSize: new L.Point(50, 50),
//iconAnchor:[50, 50],
className: "divicon",
html:'<i id = "'+feature.properties.codigo+'" class="fa ' + awesomeclase + '" style="color:'+ getColor(feature.properties.modelo) + ';">'
});

return L.marker(latlng, {icon: myIcon});
}
}

• Thanks for your answer but I have already do that to create papesjson. My goal is to redraw all points without add the layer again – Álvaro Hurtado Moreno Jul 15 '15 at 13:45
• you might consider adding the markers to a layerGroup when parsing from the geojson. Instead of using a geojson layer. My sense is that the markers will be easier to access/change from layerGroup. – toms Jul 15 '15 at 15:03

Thanks everyone, finally i found out that i wouldn´t update the properties of my geojson. Everything is working now!