Leaflet / Leaflet.VectorGrid

Display gridded vector data (sliced GeoJSON or protobuf vector tiles) in Leaflet 1.0.0
593 stars 192 forks source link

Blank tiles on zoomout #227

Open mattesCZ opened 4 years ago

mattesCZ commented 4 years ago

In #151 there was introduced an optimization for tile loading inside _isCurrentTile function.

    _isCurrentTile : function(coords, tileBounds) {

        if (!this._map) {
            return true;
        }

        var zoom = this._map._animatingZoom ? this._map._animateToZoom : this._map._zoom;
        var currentZoom = zoom === coords.z;

        var tileBounds = this._tileCoordsToBounds(coords);
        var currentBounds = this._map.getBounds().overlaps(tileBounds); 

        return currentZoom && currentBounds;

    },

I've experienced some issues when zooming out - some tiles were not loaded on zoomend. After some investigation, I found out that there is a problem with checking currentBounds in _isCurrentTile.

Imagine that the user is on zoom 15, some map bounds are active and zooms out with scroll. Immediately after the scroll event map._zoom is 15, map._animateToZoom is 14 and map.getBounds() returns the "old" bounds before zoom transition. This is all fine, but the code in _isCurrentTile mixes together the "old" bounds with "new" zoom 14. If some tiles for zoom 14 are somehow "cached", but they don't overlap current bounds, they are filled with empty data and never loaded again. This cached tiles should be checked against something like map._animateToBounds, ie. the bounds that will be active after the zoom transition to level 14.

I will send a PR soon.

StefanBrand commented 3 years ago

@mattesCZ Do you think my issue #218 is solved by your PR?

mattesCZ commented 3 years ago

@StefanBrand I'm not sure, but it's possible. Can you build the code in the fork and try it?

StefanBrand commented 3 years ago

No, I cannot dedicate time to this at the moment and probably not in the near future.