I'm using geoJson in a featureLayer so I can use the setFilter-Function. My question is: How can I use the setStyle-Function and give Elements with different properties different colors?
My Code:
var jsonLayer = L.mapbox.featureLayer(geoJson).addTo(map);
//Filter for start_year
jsonLayer.setFilter(function(f){return f.properties["start_date"] <=outyear;})
jsonLayer.setStyle(getStyle(this));
function getStyle(feature){return{
stroke: '#555555',
strokewidth: 1,
fillColor: getColor(feature)}};
function getColor(feature){
if (feature.properties.start_date<="1700"){return "#c78432"};
else if (feature.properties.start_date>="1800"){return "#F9A63F";}
else {return "#B8B8B8"};}
This obviously does not work correctly.
Aucun commentaire:
Enregistrer un commentaire