Skip to content

Commit

Permalink
redo placement for geojson sources too
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored and jfirebaugh committed Oct 17, 2015
1 parent 48d9aa8 commit d932579
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 40 deletions.
15 changes: 14 additions & 1 deletion js/source/geojson_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ function GeoJSONSource(options) {
abort: this._abortTile.bind(this),
unload: this._unloadTile.bind(this),
add: this._addTile.bind(this),
remove: this._removeTile.bind(this)
remove: this._removeTile.bind(this),
redoPlacement: this._redoTilePlacement.bind(this)
});
}

Expand Down Expand Up @@ -162,6 +163,12 @@ GeoJSONSource.prototype = util.inherit(Evented, /** @lends GeoJSONSource.prototy
}

tile.loadVectorData(data);

if (tile.redoWhenDone) {
tile.redoWhenDone = false;
tile.redoPlacement(this);
}

this.fire('tile.load', {tile: tile});

}.bind(this), this.workerID);
Expand All @@ -183,5 +190,11 @@ GeoJSONSource.prototype = util.inherit(Evented, /** @lends GeoJSONSource.prototy
tile.unloadVectorData(this.map.painter);
this.glyphAtlas.removeGlyphs(tile.uid);
this.dispatcher.send('remove tile', { uid: tile.uid, source: this.id }, null, tile.workerID);
},

redoPlacement: Source.redoPlacement,

_redoTilePlacement: function(tile) {
tile.redoPlacement(this);
}
});
12 changes: 12 additions & 0 deletions js/source/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ exports._loadTileJSON = function(options) {
}
};

exports.redoPlacement = function() {
if (!this._pyramid) {
return;
}

var ids = this._pyramid.orderedIDs();
for (var i = 0; i < ids.length; i++) {
var tile = this._pyramid.getTile(ids[i]);
this._redoTilePlacement(tile);
}
};

exports._renderTiles = function(layers, painter) {
if (!this._pyramid)
return;
Expand Down
29 changes: 29 additions & 0 deletions js/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,34 @@ Tile.prototype = {
this.buffers[b].destroy(painter.gl);
}
this.buffers = null;
},

redoPlacement: function(source) {
if (!this.loaded || this.redoingPlacement) {
this.redoWhenDone = true;
return;
}

this.redoingPlacement = true;

source.dispatcher.send('redo placement', {
uid: this.uid,
source: source.id,
angle: source.map.transform.angle,
pitch: source.map.transform.pitch,
collisionDebug: source.map.collisionDebug
}, done.bind(this), this.workerID);

function done(_, data) {
this.reloadSymbolData(data, source.map.painter);
source.fire('tile.load', {tile: this});

this.redoingPlacement = false;
if (this.redoWhenDone) {
this.redoPlacement(source);
this.redoWhenDone = false;
}
}

}
};
43 changes: 4 additions & 39 deletions js/source/vector_tile_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,6 @@ VectorTileSource.prototype = util.inherit(Evented, {
}
},

redoPlacement: function() {
if (!this._pyramid) {
return;
}

var ids = this._pyramid.orderedIDs();
for (var i = 0; i < ids.length; i++) {
var tile = this._pyramid.getTile(ids[i]);
this._redoTilePlacement(tile);
}
},

render: Source._renderTiles,
featuresAt: Source._vectorFeaturesAt,
featuresIn: Source._vectorFeaturesIn,
Expand Down Expand Up @@ -94,7 +82,7 @@ VectorTileSource.prototype = util.inherit(Evented, {

if (tile.redoWhenDone) {
tile.redoWhenDone = false;
this._redoTilePlacement(tile);
tile.redoPlacement(this);
}

this.fire('tile.load', {tile: tile});
Expand All @@ -120,32 +108,9 @@ VectorTileSource.prototype = util.inherit(Evented, {
this.dispatcher.send('remove tile', { uid: tile.uid, source: this.id }, null, tile.workerID);
},

_redoTilePlacement: function(tile) {

if (!tile.loaded || tile.redoingPlacement) {
tile.redoWhenDone = true;
return;
}

tile.redoingPlacement = true;

this.dispatcher.send('redo placement', {
uid: tile.uid,
source: this.id,
angle: this.map.transform.angle,
pitch: this.map.transform.pitch,
collisionDebug: this.map.collisionDebug
}, done.bind(this), tile.workerID);

function done(_, data) {
tile.reloadSymbolData(data, this.map.painter);
this.fire('tile.load', {tile: tile});
redoPlacement: Source.redoPlacement,

tile.redoingPlacement = false;
if (tile.redoWhenDone) {
this._redoTilePlacement(tile);
tile.redoWhenDone = false;
}
}
_redoTilePlacement: function(tile) {
tile.redoPlacement(this);
}
});

0 comments on commit d932579

Please sign in to comment.