Skip to content

Commit

Permalink
Delete cache entries for other zoom levels on zoom change
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Tung committed Aug 12, 2015
1 parent 5117481 commit a4a638f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/leaflet.utfgrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ L.UtfGrid = (L.Layer || L.Class).extend({
this._update();

var zoom = this._map.getZoom();
map.on('zoomend', this._zoomend, this);

if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
return;
Expand All @@ -94,6 +95,7 @@ L.UtfGrid = (L.Layer || L.Class).extend({

onRemove: function () {
var map = this._map;
map.off('zoomend', this._zoomend, this);
map.off('click', this._click, this);
map.off('mousemove', this._move, this);
map.off('moveend', this._update, this);
Expand Down Expand Up @@ -226,6 +228,18 @@ L.UtfGrid = (L.Layer || L.Class).extend({
}
},

_zoomend: function () {
var curZoom = this._map.getZoom();
for (var key in this._cache) {
if (this._cache.hasOwnProperty(key)) {
var zoom = parseInt(key.split('_')[0]);
if (zoom !== curZoom) {
delete this._cache[key];
}
}
}
},

_loadTileP: function (zoom, x, y) {
var head = document.getElementsByTagName('head')[0],
key = zoom + '_' + x + '_' + y,
Expand Down

0 comments on commit a4a638f

Please sign in to comment.