Skip to content

Conversation

shintonik
Copy link
Contributor

I don't really know if this is a bug or a feature. The load event of a TileLayer is only fired once. My expectation (and understanding of the underlying code) is that this event should be fired every time there are no tiles of the TileLayer left to load.

This example demonstrates the possible bug. http://jsfiddle.net/kGCPb/4/
Zoom in and out and you will see the load event (in the debug console) only once after the initialization of the map. Every pan/zoom of the map after that results in a negative number of _tilesToLoad of the TileLayer. But the event is only fired if the _tilesToLoad is zero.

I think this bug was already issued before as part of another bug. https://github.com/CloudMade/Leaflet/issues/177

Anyway. Adding this line (like proposed in the issue of lapinos03) should fix that problem.

_addTilesFromCenterOut: function (bounds) {
  var queue = [],
  center = bounds.getCenter();

  var j, i;
  for (j = bounds.min.y; j <= bounds.max.y; j++) {
    for (i = bounds.min.x; i <= bounds.max.x; i++) {
      if (!((i + ':' + j) in this._tiles)) {
        queue.push(new L.Point(i, j));
      }
    }
  }

  // load tiles in order of their distance to center
  queue.sort(function (a, b) {
    return a.distanceTo(center) - b.distanceTo(center);
  });

  var fragment = document.createDocumentFragment();

  // New line
  if(queue.length == 0) return;

  this._tilesToLoad = queue.length;

  console.log(this._tilesToLoad);

  var k, len;
    for (k = 0, len = this._tilesToLoad; k < len; k++) {
        this._addTile(queue[k], fragment);
    }

    this._container.appendChild(fragment);
},

@ghost ghost assigned mourner Jun 21, 2012
@mourner
Copy link
Member

mourner commented Jun 21, 2012

Thanks for the report, will be fixed.

mourner added a commit that referenced this pull request Jun 25, 2012
TileLayer load event is only fired once
@mourner mourner merged commit 3f0f7d7 into Leaflet:master Jun 25, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants