I'm working on a project and I'm using Leaflet. From an object list extracted from the DB, I can currently display markers with custom icons. Now I'm working to display polylines from data I got in DB. With Javascript, I get the list and I arrive to display polylines but they are all blue where I want them to have differents colors depending on a property of the polyline.
var geoJsonFluxMatiere = {
'type': 'FeatureCollection',
'features': []
};
for (indexfluxMatiere = 0; indexfluxMatiere < listeFluxMatiere.length; indexfluxMatiere++) {
var tableauFluxMatiere = {
type: 'Feature',
properties: {
'id': listeFluxMatiere[indexfluxMatiere].idFluxMatiere,
'fluxPrimaire': listeFluxMatiere[indexfluxMatiere].fluxPrimaire
},
geometry: {
'type': 'LineString',
'coordinates': [
[listeFluxMatiere[indexfluxMatiere].posXDepart, listeFluxMatiere[indexfluxMatiere].poxYDepart],
[listeFluxMatiere[indexfluxMatiere].posXArrivee, listeFluxMatiere[indexfluxMatiere].posYArrivee]
]
}
}
geoJsonFluxMatiere['features'].push(tableauFluxMatiere);
}
var layerFluxMatiere = L.geoJson(geoJsonFluxMatiere, {
pointToLayer: function (feature, latlng) {
if(feature.properties.fluxPrimaire == true){
var polylineFluxMatiere = new L.polyline(
feature.geometry.coordinates,
{
color: 'red',
}
);
}else{
var polylineFluxMatiere = new L.polyline(
feature.geometry.coordinates,
{
color: 'green',
}
);
}
return polylineFluxMatiere;
},
}).addTo(map);
Coordinates are ok and the polylines are displayed where they have to but it's like color's parameter is ignored.
Did I do something wrong ?
By the way, I'm sorry for my english if it is not perfect.
Thank you !
Raphaël