I'm aiming to have my markers in three different colours depending on their rating
property. I have seen a similar post where an object was used to define the colours. Each marker has a rating
attribute between 1 and 5.
I was thinking of using a else if statement e.g
if (rating < 3) {
markerColor: 'red'
} else if (rating = 3 ) {
markerColor: 'orange'
} else {
markerColor: 'green'
}
I am creating my markers as follows:
for (var i = 0; i < data.length; i++) {
var customOptions = {
'maxWidth': '500',
'className' : 'custom'
};
//Custom icon
var blueMarker = L.AwesomeMarkers.icon({
markerColor: 'blue'
});
//Create markerLocation variable
var markerLocation = new L.LatLng(data[i].lat, data[i].lon);
//Create marker variable
var marker = new L.Marker(markerLocation, {icon: blueMarker});
marker.bindPopup("<p><h2>Rating:</h2> " + data[i].rating_value,
customOptions);
}
Would the else if statement be used when assigning the blueMarker variable?
Thanks
I used
var = customColour = "green";
if (data[i].rating_value < 3)
customColor = "red";
else if (data[i].rating_value === 3)
customColor = "orange";
//Create custom icon
var customMarker = L.AwesomeMarkers.icon({
markerColor: customColour
});
//Create markerLocation variable
var markerLocation = new L.LatLng(data[i].lat, data[i].lon);
//Create marker variable
var marker = new L.Marker(markerLocation, {icon: customMarker});
However the AwesomeMarkers plugin only accepts colours, so I dont think using customColour worked. https://github.com/lvoogdt/Leaflet.awesome-markers. Thanks
customColor
vscustomColour
?