Skip to content

Invalid out-of-bounds tiles are requested from the server when noWrap and bounds are set #4646

Closed
@joanrieu

Description

Symptom

Invalid out-of-bounds tiles are requested from the server, resulting in 404 errors in the console and the default image-couldn't-be-loaded rectangles being displayed instead of no tiles.

Trigger

This problem happens when a layer has both the noWrap and the bounds options.

Visual comparison

The layers are defined with noWrap: true and bounds: [[-90, -180], [90, 180]]. Incorrect behavior on the left, fixed one on the right.

Visual comparison

Bug

The following function located inside GridLayer does not respect the noWrap option: map.wrapLatLng(...) is always called.

_tileCoordsToBounds: function (coords) {

    // ...

    nw = map.wrapLatLng(map.unproject(nwPoint, coords.z)),
    se = map.wrapLatLng(map.unproject(sePoint, coords.z));

    return new L.LatLngBounds(nw, se);
},

Fix

If the noWrap option is set on the layer, map.wrapLatLng should not be called.

Explanation

The _tileCoordsToBounds(...) function is called by _isValidTile(...), which relies on it to validate a tile by checking that it is in the user-defined bounds (if any), as seen below.

_isValidTile: function (coords) {

    // ...

    if (!this.options.bounds) { return true; }

    // don't load tile if it doesn't intersect the bounds in options
    var tileBounds = this._tileCoordsToBounds(coords);
    return L.latLngBounds(this.options.bounds).overlaps(tileBounds);
},

Workaround (until a fix is released)

You can patch the layer._tileCoordsToBounds function on your layers, changing the offending call.

Version

I am facing this bug in version v1.0.0-rc.1 and the few changes to this file in master are completely unrelated.

Activity

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

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions