使用时
.geoJSON()
style
styles
再次执行检查的属性
fluxPrimaire
geoJSON Docs
:
var states = [{
"type": "Feature",
"properties": { "party": "Republican" },
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}, {
"type": "Feature",
"properties": { "party": "Democrat" },
"geometry": {
"type": "Polygon",
"coordinates": [[
[-109.05, 41.00],
[-102.06, 40.99],
[-102.03, 36.99],
[-109.04, 36.99],
[-109.05, 41.00]
]]
}
}];
L.geoJSON(states, {
//this is where you will perform your check to change the polyline color
style: function (feature) {
switch (feature.properties.party) {
case 'Republican': return { color: "#ff0000" };
case 'Democrat': return { color: "#0000ff" };
}
}
}).addTo(map);
var layerFluxMatiere = L.geoJson(geoJsonFluxMatiere, {
style: function (feature) {
if(feature.properties.fluxPrimaire == true){
return { color: '#ff0000' };
}else{
return { color: '#0000ff' };
}
},
}).addTo(map);