question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Radius with respect to zoom level

See original GitHub issue

@mourner Is it possible to change the radius based on zoom level. For eg. if I zoom out, the radius of a lat/lng should decrease and if we zoom in the radius should increase, but keeping the allocated intensity value to the given lat/lng value and not adding up the intensities on zoom out.

I tried to modify the draw() function but it doesnt work. The radius() function just gets called once upon initialization, I tried to call it on each zoom in/ out activity from redraw() but it doesn’t work, following is the sample code of what I am trying to achieve:

  draw: function(t) {
        this._ctx.canvas.height = this._ctx.canvas.height + (this._r * 10);
        this._ctx.canvas.width = this._ctx.canvas.width + (this._r * 10);
        this._circle || this.radius(this.defaultRadius), this._grad || this.gradient(this.defaultGradient);

The canvas draw fails to plot the points on the map.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
mertemincommented, Sep 19, 2017

@zhuyinjing Sorry I don’t remember which version was that, but you can just copy leaflet.heat code from https://jsfiddle.net/mertk/zawj9uwm/15/ and play with it.

1reaction
mertemincommented, Aug 10, 2016

If you want to update radius with zoom level, you need to edit a couple methods. I actually experiment this idea a little bit and got some promising results.

First, I changed radius function’s signature and replaced r with zoom parameter.

radius: function (zoom, blur) {
        blur = blur === undefined ? 15 : blur;

        // recalculate radius based on zoom level
        var r = this.defaultRadius * Math.pow(2, zoom - 15);

And updated draw method to accept current zoom level. I also made sure draw method calls radius method every time zoom level is changed. Otherwise, radius is called only once.

Here is a link to an example. It displays rectangles, not circles. You should be able to change it easily.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the mathematical relationship between Radius ...
MIN ZOOM = 1 MAX ZOOM = 22 R = radius of the circle that have center in the position get from the...
Read more >
Make circles radius react to zoom level - Stack Overflow
I tried this code but I really can't explain the results. What happens is that every time I zoom in or out, the...
Read more >
Zoom levels - - OpenStreetMap Wiki
Level # Tiles Tile width (° of longitudes) m / pixel (on Equator) ~ Scale (on screen) 00 000 000 000 001 360.0000 156...
Read more >
[Google Maps API v3] How can I set the zoom level based on ...
You can use Circle() as a helper to avoid maths. Create an instance of Circle() with 25 miles radius. var circle = new...
Read more >
zoom - CSS: Cascading Style Sheets - MDN Web Docs
The non-standard zoom CSS property can be used to control the magnification level of an element. transform: scale() should be used instead ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found