diff --git a/src/leaflet.utfgrid.js b/src/leaflet.utfgrid.js index 8369cfe..a4dfafd 100644 --- a/src/leaflet.utfgrid.js +++ b/src/leaflet.utfgrid.js @@ -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; @@ -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); @@ -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,