humangeo / leaflet-dvf

Leaflet Data Visualization Framework
MIT License
689 stars 152 forks source link

How to change DataLayer Radius on ZoomStart/ZoomEnd? #37

Closed phillipebarbosa closed 10 years ago

phillipebarbosa commented 10 years ago

Hi! Good Morning!

I'm starting to use the leaflet-dvf plugin and I need to change the Radius of my DataLayer depending of the current zoom. I noticed that some Layers have a method to Redraw, but DataLayer doesn't... I also tried to use another kind of Layer, but it didn't fit on what I need. There is a way to do that, change the radius and redraw the DataLayer?

Thanks in advance!

Phillipe.

sfairgrieve commented 10 years ago

Can you provide more specific details about what you're trying to accomplish? I think I understand what you're saying, but I just want to make sure before I answer. Your goal is to change the radius of markers dynamically based on zooming in/out, rather than the fixed radius approach that Leaflet currently supports? So rather than a marker having a radius of 10 pixels at any zoom level, you want it to have radius X at zoom level X, radius Y at zoom Y, etc. I think there are multiple ways to solve this problem, but it would help to know what the intended result is. For instance, one approach might be to use L.Polygon or L.Circle classes rather than marker classes. These classes generate shapes with fixed sizes in terms of geospatial coverage which would make them appear small when zoomed out and large when zoomed in - which might solve your issue. Another approach might be to call the DataLayer's setDisplayOption in the event handler for zoomend. You could then pass in a new L.LinearFunction instance or a basic function that rescales the radius based on the current zoom level. I can provide examples if either or these sound like what you're looking for.

phillipebarbosa commented 10 years ago

Hi!!

setDisplayOption in the zoom event handler is exactly what I was looking for!! This solved my problem very well!!

Thank You!!