Skip to content

Commit

Permalink
#5 layer cleans up on remove
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
spacemansteve committed May 2, 2016
1 parent 255f4ce commit a858941
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
16 changes: 3 additions & 13 deletions example/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions leafletSolrHeatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand Down

0 comments on commit a858941

Please sign in to comment.