Skip to content

Error switching tilelayer - Uncaught TypeError: Cannot read property '_panTransition' of null #965

Closed
@benlumley

Description

Hi

I'm getting this error when removing a tileLayer:

Uncaught TypeError: Cannot read property '_panTransition' of null

I believe it happens when the layer is still panning when it is removed.

I couldn't find a way to detect or stop the transition to resolve this. As I've extended L.TileLayer to add some other functionality (I'm using leaflet as a viewer for high res manuscript images, and need to alter the behaviour of _tileShouldBeLoaded so out of bound tiles aren't loaded) - so I've also copy/pasted the _update method (where the _panTransition error occurs) into here and added the following line:

if (!this._map) { return; }

So it looks like this:

_update: function (e) {
    if (!this._map) { return; }

    if (this._map._panTransition && this._map._panTransition._inProgress) { return; }

    var bounds   = this._map.getPixelBounds(),
        zoom     = this._map.getZoom(),
        tileSize = this.options.tileSize;

    if (zoom > this.options.maxZoom || zoom < this.options.minZoom) {
        return;
    }

    var nwTilePoint = new L.Point(
            Math.floor(bounds.min.x / tileSize),
            Math.floor(bounds.min.y / tileSize)),
        seTilePoint = new L.Point(
            Math.floor(bounds.max.x / tileSize),
            Math.floor(bounds.max.y / tileSize)),
        tileBounds = new L.Bounds(nwTilePoint, seTilePoint);

    this._addTilesFromCenterOut(tileBounds);

    if (this.options.unloadInvisibleTiles || this.options.reuseTiles) {
        this._removeOtherTiles(tileBounds);
    }
}

Looking a bit deeper, TileLayer onRemove sets _map to null - which is presumably why this issue occurs. So perhaps a better fix would be to stop the _panTransition there?

So, there's probably a better fix than this - but reporting anyway.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions