Leaflet.glify icon indicating copy to clipboard operation
Leaflet.glify copied to clipboard

How can I pass a className to individual points?

Open neilm-code opened this issue 3 years ago • 2 comments

Hi, I know I can pass a custom className for the whole canvas. But I was wondering if there is any way to pass a custom className to the individual rendered points right now?

To put this in context, I am basically trying to hide individual points on click trigger. If passing the custom className to individual points after the render is not supported atm, do you have any thoughts/suggestions on how I can do that with the functionality that is already there?

Thank you guys, you are doing a great job ❤️

neilm-code avatar Apr 16 '21 20:04 neilm-code

I'm pretty much sure you can not at all, since points rendered on canvas are not HTML elements.

If you want to dynamically hide/show certain points, you should change the data source during the runtime and trigger re-render (there may be better ways to do so, though that's the only one I know, and most certainly it should work).

smellyshovel avatar Jul 05 '21 09:07 smellyshovel

@neilm-code Doable by storing the index of the point in the properties of its GeoJSON. Then write your click handler to get the index from the feature and pass it to .remove(). Here's an example of how I've used this method to fetch data about the point on click: see renderGeography()

melgrove avatar Jun 04 '22 07:06 melgrove