Skip to content

Commit

Permalink
fix overscaled featuresAt
Browse files Browse the repository at this point in the history
fix #2103
  • Loading branch information
ansis committed Feb 11, 2016
1 parent e752a88 commit 25e5ed9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 20 deletions.
2 changes: 1 addition & 1 deletion js/data/feature_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ FeatureTree.prototype.query = function(args, callback) {
var radius, bounds;
if (typeof x !== 'undefined' && typeof y !== 'undefined') {
// a point (or point+radius) query
radius = (params.radius || 0) * EXTENT / args.scale;
radius = (params.radius || 0) * EXTENT / args.tileSize / args.scale;
bounds = [x - radius, y - radius, x + radius, y + radius];
} else {
// a rectangle query
Expand Down
1 change: 1 addition & 0 deletions js/source/source.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ exports._vectorFeaturesAt = function(coord, params, callback) {
x: result.x,
y: result.y,
scale: result.scale,
tileSize: result.tileSize,
source: this.id,
params: params
}, callback, result.tile.workerID);
Expand Down
3 changes: 2 additions & 1 deletion js/source/tile_pyramid.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,8 @@ TilePyramid.prototype = {
tile: tile,
x: pos.x,
y: pos.y,
scale: this.transform.worldSize / Math.pow(2, tile.coord.z)
scale: Math.pow(2, this.transform.zoom - tile.coord.z),
tileSize: tile.tileSize
};
}
}
Expand Down
16 changes: 12 additions & 4 deletions test/js/data/feature_tree.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ test('featuretree', function(t) {
ft.insert(feature.bbox(), 'road', feature);
ft.query({
params: { },
scale: 1,
tileSize: 512,
x: 0,
y: 0
}, function(err, features) {
Expand All @@ -48,6 +50,8 @@ test('featuretree with args', function(t) {
params: {
radius: 5
},
scale: 1,
tileSize: 512,
x: 0,
y: 0
}, function(err, features) {
Expand All @@ -68,7 +72,8 @@ test('featuretree point query', function(t) {

ft.query({
source: "mapbox.mapbox-streets-v5",
scale: 724.0773439350247,
scale: 1.4142135624,
tileSize: 512,
params: {
radius: 30,
includeGeometry: true
Expand Down Expand Up @@ -100,7 +105,8 @@ test('featuretree rect query', function(t) {

ft.query({
source: "mapbox.mapbox-streets-v5",
scale: 724.0773439350247,
scale: 1.4142135624,
tileSize: 512,
params: {
includeGeometry: true
},
Expand Down Expand Up @@ -149,7 +155,8 @@ test('featuretree query with layerIds', function(t) {

ft.query({
source: "mapbox.mapbox-streets-v5",
scale: 724.0773439350247,
scale: 1.4142135624,
tileSize: 512,
params: {
radius: 30,
layerIds: ['water']
Expand All @@ -163,7 +170,8 @@ test('featuretree query with layerIds', function(t) {

ft.query({
source: "mapbox.mapbox-streets-v5",
scale: 724.0773439350247,
scale: 1.4142135624,
tileSize: 512,
params: {
radius: 30,
layerIds: ['none']
Expand Down
80 changes: 66 additions & 14 deletions test/js/source/tile_pyramid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,25 +233,77 @@ test('TilePyramid#removeTile', function(t) {
});

test('TilePyramid#tileAt', function(t) {
var pyramid = createPyramid({
load: function(tile) { tile.loaded = true; },
minzoom: 1,
maxzoom: 10,
tileSize: 512
t.test('regular tile', function(t) {
var pyramid = createPyramid({
load: function(tile) { tile.loaded = true; },
minzoom: 1,
maxzoom: 1,
tileSize: 512
});

var transform = new Transform();
transform.resize(512, 512);
transform.zoom = 1.5;
pyramid.update(true, transform);

var result = pyramid.tileAt(new Coordinate(0, 3, 2));

t.deepEqual(result.tile.coord.id, 65);
t.deepEqual(result.scale, 1.4142135623730951);
t.deepEqual(result.tileSize, 512);
t.deepEqual(result.x, 0);
t.deepEqual(result.y, 4096);

t.end();
});

var transform = new Transform();
transform.resize(512, 512);
transform.zoom = 1.5;
pyramid.update(true, transform);
t.test('reparsed overscaled tile', function(t) {
var pyramid = createPyramid({
load: function(tile) { tile.loaded = true; },
reparseOverscaled: true,
minzoom: 1,
maxzoom: 1,
tileSize: 512
});

var transform = new Transform();
transform.resize(512, 512);
transform.zoom = 2.5;
pyramid.update(true, transform);

var result = pyramid.tileAt(new Coordinate(0, 3, 2));

t.deepEqual(result.tile.coord.id, 130);
t.deepEqual(result.scale, 1.4142135623730951);
t.deepEqual(result.tileSize, 1024);
t.deepEqual(result.x, 0);
t.deepEqual(result.y, 4096);
t.end();
});

var result = pyramid.tileAt(new Coordinate(0, 3, 2));
t.test('overscaled tile', function(t) {
var pyramid = createPyramid({
load: function(tile) { tile.loaded = true; },
minzoom: 1,
maxzoom: 1,
tileSize: 512
});

t.deepEqual(result.tile.coord.id, 65);
t.deepEqual(result.scale, 724.0773439350247);
t.deepEqual(result.x, 0);
t.deepEqual(result.y, 4096);
var transform = new Transform();
transform.resize(512, 512);
transform.zoom = 2.5;
pyramid.update(true, transform);

var result = pyramid.tileAt(new Coordinate(0, 3, 2));

t.deepEqual(result.tile.coord.id, 65);
t.deepEqual(result.scale, 2 * 1.4142135623730951);
t.deepEqual(result.tileSize, 512);
t.deepEqual(result.x, 0);
t.deepEqual(result.y, 4096);

t.end();
});
t.end();
});

Expand Down

0 comments on commit 25e5ed9

Please sign in to comment.