I have a set of data in json which I wanna set an specific marker color for each in leaflet. the data is like this:
var BillingDate = [
{"branchcode":"668",
"saleyear":"99",
"saleprd":"3",
"LastX":"36.649717",
"LastY":"52.488193",
"flag":"1",
"flag_Title":null
},
{
"branchcode":"669",
"saleyear":"99",
"saleprd":"3",
"LastX":"36.712585",
"LastY":"52.935543",
"flag":"0",
"flag_Title":null
}
{
"branchcode":"669",
"saleyear":"99",
"saleprd":"3",
"LastX":"36.712585",
"LastY":"52.935543",
"flag":"2",
"flag_Title":null
}
];
I wanna say that if flag===0 set marker color to Blue, if flag===1 set marker color to Red and so on. how am I able to do that in leaflet? because the if loop function itself wont work i guess... I'm using this code with Awsome Markers:
var customColor = "blue";
if (ODO[i].flag === 1)
customColor = "red";
else if (ODO[i].flag === 2)
customColor = "orange";
else if (ODO[i].flag === 3)
customColor = "green";
var customMarker = L.AwesomeMarkers.icon({
markerColor: customColor
});
var mainMap = L.marker( [ODO[i].LastX, ODO[i].LastY] , {icon: customMarker})
.bindPopup( popup );
markerClusters.addLayer( mainMap );
but it gives me an error for
Layer.js:52 Uncaught TypeError: t.addLayer is not a function
at i.addTo (Layer.js:52)
at MarkerOnMap (functions.js:61)
at Object.success (app.js:213)
at i (0:4002)
at XMLHttpRequest.Request.f.onload (0:4179)
on the line: window.mainMap.addLayer( markerClusters ); markerClusterLayer = L.markerClusterGroup({disableClusteringAtZoom: 13}).addTo(mainMap);
anyone can help with this?
window.mainMap
vsmainMap
. I suspect one of those isundefined
.