heatcanvas icon indicating copy to clipboard operation
heatcanvas copied to clipboard

How to refresh layer with Leaflet/OSM

Open mikekay01 opened this issue 12 years ago • 5 comments

How do I refresh my heatmap with new data in a Leaflet/OSM environment?

I can successfully build the map using: heatmap = new L.TileLayer.HeatCanvas...

and can load the map using: for (var i in MapData) { console.log('data'); heatmap.pushData(MapData[i][0], MapData[i][1], MapData[i][2]) }

My problem is I do not know how to clear the heatmap and load new data.

I have tried using heatmap.clear(), but this seems to have no effect as everytime I push data into the heatmap it simply adds to the existing data.

Does anyone know how to basically clear the data from a heatmap, load new data in, and redraw the map?

mikekay01 avatar Mar 05 '13 21:03 mikekay01

I just sent a pull request to remove the data when using heatmap.clear().

What you need to do for now, I believe, is:

//clear the data heatmap.data = []; //add the data for (var i in MapData) { heatmap.pushData(MapData[i][0], MapData[i][1], MapData[i][2]) } //redraw already clears the heatmap heatmap.redraw();

bozdoz avatar Mar 05 '13 21:03 bozdoz

I'm testing right now...

mikekay01 avatar Mar 05 '13 21:03 mikekay01

How'd that go? :)

bozdoz avatar Mar 06 '13 00:03 bozdoz

It seems to work .

Sent from my iPhone

On Mar 5, 2013, at 6:03 PM, Benjamin J DeLong [email protected] wrote:

How'd that go? :)

— Reply to this email directly or view it on GitHub.

mikekay01 avatar Mar 06 '13 00:03 mikekay01

Sorry, I just got back to this portion of my project. Unfortunately, it doesn't work. The map continues to add new data points. Is there a fix for this situation?

mikekay01 avatar Apr 09 '13 17:04 mikekay01