I have a Leaflet map that displays pins from a geojson feed. I want to be able to set custom icons based on an attribute in the geojson that can have one of three values, let's sat Green, Orange, Red, that each have pre-defined custom icons.
If I set
return L.marker(latlng, {icon: Red});
it works fine, but if I set
return L.marker(latlng, {icon: feature.icon});
having verified that the value of feature.icon is Red, it does not work, and returns "Uncaught TypeError: Cannot read property 'popupAnchor' of undefined" relating to a line quite a bit below which is binding a popup to the layer.
I can't help thinking it's a simple syntax error, but cannot work out exactly how I should do this.
I have tried various combinations of single and double quotes, without success.
UPDATE: thanks to the comments and answer below I realised the error in my thinking. I was passing the icon as a text value rather than as an icon object. So the logic to sort this was to test against the text value that was present in the geojson and use that to choose and set the appropriate icon.