This seems trivial but I can't find the answer anywhere. I have set the className attribute of a circleMarker:
var marker = L.circleMarker([lat, lng], {
radius: 6,
color: 'black',
weight: 2,
opacity: 1,
fillColor: 'red',
fillOpacity: 1.0,
className: 'redSpot'
}).addTo(map);
and I simply want to access the className property later on, something like:
marker.className
But this gives 'undefined' rather than 'redSpot'. Other attempts all give 'undefined':
marker.attr('className')
marker.data('className')
How do you access the className attribute?
I'm not sure what the final story is on this, but in all versions of Leaflet I tested (0.7 - 1.0), the circleMarker class DOES NOT inherit the className option for its constructor...even though the docs said it should. Weird. I know the leaflet team has described caveats and bugs related to this option.
Try this.
var marker = L.circleMarker([lat, lng], {
radius: 6,
color: 'black',
weight: 2,
opacity: 1,
fillColor: 'red',
fillOpacity: 1.0
}).addTo(map);
marker.className = "redSpot";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With