From a858941871bba6648e5b64419ce178d7f34ccfc7 Mon Sep 17 00:00:00 2001 From: Steve McDonald Date: Mon, 2 May 2016 09:22:28 -0400 Subject: [PATCH] #5 layer cleans up on remove added leaflet onRemove function to remove listeners and L.heat layer. onRemove removes all map click handlers, I was having trouble removing them individually. I think this could cause problems if an app had other handers listening. --- example/example.js | 16 +++------------- leafletSolrHeatmap.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/example/example.js b/example/example.js index b15c39c..dbb1457 100644 --- a/example/example.js +++ b/example/example.js @@ -30,20 +30,10 @@ function resetSolr() colorMap = colorMap.split(','); - if (solr) - { - map.removeLayer(solr); - map.off('moveend'); - solr._clearLayers(); - if (solr.heatmapLayer) - { - // this code highlights the problem of L.SolrHeatmap creating L.Heat - // perhaps L.SolrHeatmap needs to override remove layer - map.removeLayer(solr.heatmapLayer); - map.off("click"); - } - } + + if (solr) + map.removeLayer(solr); // if the doi field is present, we format it as an html link to the jstor document // first, a function to generate the html diff --git a/leafletSolrHeatmap.js b/leafletSolrHeatmap.js index 49ef18b..150124d 100644 --- a/leafletSolrHeatmap.js +++ b/leafletSolrHeatmap.js @@ -35,6 +35,18 @@ L.SolrHeatmap = L.GeoJSON.extend({ _this._getData(); }, + onRemove: function(passedMap) + { + var _this = this; + passedMap.off('moveend'); + _this._clearLayers(); + if (_this.heatmapLayer) + { + passedMap.removeLayer(_this.heatmapLayer); + map.off("click"); // will this remove click handlers that it shouldn't + } + }, + _computeHeatmapObject: function(data) { var _this = this; _this.facetHeatmap = {},