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

fixed radius

Open abernier opened this issue 10 years ago • 11 comments

Hi,

I'd like my heat point around lat/lng to have a fixed (zoom independent) radius of 500m : how can I specify this ?

Thank you

abernier avatar Oct 29 '14 21:10 abernier

Nice suggestion, I'll look into it — shouldn't be hard to implement. Just need to recalculate the radius on each zoom.

mourner avatar Oct 29 '14 21:10 mourner

Also, in my opinion, having the radius expressed in meters by default makes more sense than pixels in that case.

Let me know if I can help in anything.

Cheers

abernier avatar Oct 31 '14 17:10 abernier

Having a similar but not exactly the same issue here. Because I am not sure about how to recalculate the radius of each feature on each zoom, I implement this by removing old layers and add back new layers on each zoom. Something like

map.on('zoomend', function() {
    // remove existing layer
    map.removeLayer(old_layer);
    // add in new
    new_layer = L.geoJson(data, data_options);
    map.addLayer(new_layer);
});

and in my data_options, I implemented the resizing method

var data_options = {
    pointToLayer: function(feature, latlng) {
        mk = L.circleMarker(latlng);

        var pointC = map.latLngToContainerPoint(latlng);
        var pointX = [pointC.x + 1, pointC.y];

        // convert containerpoints to latlng's
        var latLngC = map.containerPointToLatLng(pointC);
        var latLngX = map.containerPointToLatLng(pointX);

       // Assuming distance only depends on latitude 
        var distanceX = latLngC.distanceTo(latLngX);
      // 100 meters is the fixed distance here
        var pixels = 100 / distanceX;
        mk.setRadius(pixels);

        return mk;
    }
};

Hope this helps! I refer to http://stackoverflow.com/questions/27545098/leaflet-calculating-meters-per-pixel-at-zoom-level when I implemented method for calculating meters per pixel at different zoom levels.

bobintornado avatar Mar 22 '15 10:03 bobintornado

any updates here? re-drawing of whole heatmap doesn't solve my problem

ghost avatar Jun 08 '15 12:06 ghost

http://leafletjs.com/reference.html#circle Maybe by using circle itself (not circleMarker) could help? As the unites are in meters, not pixels.

Other than this point, you may want to check out some other statistical stuff for more accurate "heat" calculation.

bobintornado avatar Jun 08 '15 14:06 bobintornado

Hi folks! Firstly @mourner thank you for this plugin! Any update on this feature? And another wish is fixed radius starting from zoom level :)

kuzvac avatar Mar 25 '16 12:03 kuzvac

+1

mgoldgeier avatar Apr 13 '16 21:04 mgoldgeier

I think i made something looks like fixed radius

kuzvac avatar May 06 '16 11:05 kuzvac

@kuzvac Does keeping the radius fixed avoid merging of the lat/lng value colors on zoom out?

cpunekar avatar Jul 28 '16 21:07 cpunekar

@cpunekar can you please explain more detailed?

kuzvac avatar Aug 01 '16 14:08 kuzvac

Thanks @kuzvac for the reply. I wanted to have fixed radius when I asked this question but now since the intensity value of points get added as we zoom out, I was curious if we can recalculate the radius each time we zoom in and out. As in I want the radius to increase when we zoom in and to decrease when we zoom out. This would give me a better picture of the intensity values as I am not looking for density heatmap.

cpunekar avatar Aug 01 '16 17:08 cpunekar