From 91fff36615deeb03f933e1840ad6aa6447fce2e9 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Mon, 6 Apr 2015 17:16:47 -0700 Subject: [PATCH] redo placement for geojson sources too --- js/source/geojson_source.js | 15 +++++++++++- js/source/source.js | 12 +++++++++ js/source/tile.js | 29 ++++++++++++++++++++++ js/source/vector_tile_source.js | 43 +++------------------------------ 4 files changed, 59 insertions(+), 40 deletions(-) diff --git a/js/source/geojson_source.js b/js/source/geojson_source.js index 83e36c47867..2bfac27b3cd 100644 --- a/js/source/geojson_source.js +++ b/js/source/geojson_source.js @@ -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) }); } @@ -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); @@ -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); } }); diff --git a/js/source/source.js b/js/source/source.js index 39a0d9fbf76..80c9b60e0f4 100644 --- a/js/source/source.js +++ b/js/source/source.js @@ -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; diff --git a/js/source/tile.js b/js/source/tile.js index 67c07f6581a..af77fd62b93 100644 --- a/js/source/tile.js +++ b/js/source/tile.js @@ -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; + } + } + } }; diff --git a/js/source/vector_tile_source.js b/js/source/vector_tile_source.js index ad25bbf589d..a32b63e0247 100644 --- a/js/source/vector_tile_source.js +++ b/js/source/vector_tile_source.js @@ -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, @@ -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}); @@ -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); } });