1

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){
    if (layer.feature.properties.estado == "BAJA"){
        awesomeclase ="fa-circle-o-notch";
    }
    else if (layer.feature.properties.estado == "PENDIENTE REPOSICION"){
        awesomeclase = "fa-plus";
    }
    else if (layer.feature.properties.estado == "RETIRADA"){
        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);
}); 
1
  • could it be because the html snipplet is not valid? you open the <i> but don't close it …
    – christoph
    Jul 15, 2015 at 3:49

2 Answers 2

2

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) {

        if (feature.properties.estado == "BAJA"){
            awesomeclase ="fa-circle-o-notch";
        }
        else if (feature.properties.estado == "PENDIENTE REPOSICION"){
            awesomeclase = "fa-plus";
        }
        else if (feature.properties.estado == "RETIRADA"){
            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});
    }
}
2
  • 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 Jul 15, 2015 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, 2015 at 15:03
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.