Skip to content

Commit

Permalink
Ensure "Tile#loadVectorData" preserves the most recent "rawTileData" (#…
Browse files Browse the repository at this point in the history
…3233)

fixes #3221
  • Loading branch information
lucaswoj authored and mourner committed Sep 21, 2016
1 parent dde8278 commit 9574056
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
4 changes: 3 additions & 1 deletion js/source/tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ Tile.prototype = {
// empty GeoJSON tile
if (!data) return;

// If we are redoing placement for the same tile, we will not recieve
// a new "rawTileData" object. If we are loading a new tile, we will
// recieve a new "rawTileData" object.
if (data.rawTileData) {
this.rawTileData = data.rawTileData;
}
Expand Down Expand Up @@ -119,7 +122,6 @@ Tile.prototype = {
this.symbolInstancesArray = null;
this.collisionTile = null;
this.featureIndex = null;
this.rawTileData = null;
this.buckets = null;
this.state = 'unloaded';
},
Expand Down
51 changes: 50 additions & 1 deletion test/js/source/tile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ var fs = require('fs');
var path = require('path');
var vtpbf = require('vt-pbf');
var sinon = require('sinon');
var FeatureIndex = require('../../../js/data/feature_index');
var CollisionTile = require('../../../js/symbol/collision_tile');
var CollisionBoxArray = require('../../../js/symbol/collision_box');
var SymbolInstancesArray = require('../../../js/symbol/symbol_instances');
var SymbolQuadsArray = require('../../../js/symbol/symbol_quads');
var util = require('../../../js/util/util');

test('querySourceFeatures', function(t) {
var features = [{
Expand Down Expand Up @@ -50,7 +56,10 @@ test('querySourceFeatures', function(t) {
tile.querySourceFeatures(result, {});
t.equal(result.length, 0);

tile.rawTileData = fs.readFileSync(path.join(__dirname, '/../../fixtures/mbsv5-6-18-23.vector.pbf'));
tile.loadVectorData(
createVectorData({rawTileData: createRawTileData()}),
createPainter()
);

result = [];
tile.querySourceFeatures(result, { 'sourceLayer': 'does-not-exist'});
Expand Down Expand Up @@ -82,5 +91,45 @@ test('querySourceFeatures', function(t) {
t.end();
});

t.test('loadVectorData preserves the most recent rawTileData', function(t) {
var tile = new Tile(new TileCoord(1, 1, 1));
tile.state = 'loaded';

tile.loadVectorData(
createVectorData({rawTileData: createRawTileData()}),
createPainter()
);
tile.loadVectorData(
createVectorData(),
createPainter()
);

var features = [];
tile.querySourceFeatures(features, { 'sourceLayer': 'road' });
t.equal(features.length, 3);

t.end();
});

t.end();
});

function createRawTileData() {
return fs.readFileSync(path.join(__dirname, '/../../fixtures/mbsv5-6-18-23.vector.pbf'));
}

function createVectorData(options) {
var collisionBoxArray = new CollisionBoxArray();
return util.extend({
collisionBoxArray: collisionBoxArray.serialize(),
collisionTile: (new CollisionTile(0, 0, collisionBoxArray)).serialize(),
symbolInstancesArray: (new SymbolInstancesArray()).serialize(),
symbolQuadsArray: (new SymbolQuadsArray()).serialize(),
featureIndex: (new FeatureIndex(new TileCoord(1, 1, 1))).serialize(),
buckets: []
}, options);
}

function createPainter() {
return { style: {} };
}

0 comments on commit 9574056

Please sign in to comment.