Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust queryRenderedSymbols with tile perspective approximation #4792

Merged
merged 2 commits into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/symbol/collision_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,14 @@ class CollisionTile {
features.push(ignoredFeatures[i]);
}

// "perspectiveRatio" is a tile-based approximation of how much larger symbols will
// be in the distance. It won't line up exactly with the actually rendered symbols
// Being exact would require running the collision detection logic in symbol_sdf.vertex
// in the CPU
const perspectiveScale = scale / this.perspectiveRatio;

// Account for the rounding done when updating symbol shader variables.
const roundedScale = Math.pow(2, Math.ceil(Math.log(scale) / Math.LN2 * 10) / 10);
const roundedScale = Math.pow(2, Math.ceil(Math.log(perspectiveScale) / Math.LN2 * 10) / 10);

for (let i = 0; i < features.length; i++) {
const blocking = collisionBoxArray.get(features[i]);
Expand All @@ -255,10 +261,10 @@ class CollisionTile {

// Check if query intersects with the feature box at current scale.
const anchor = blocking.anchorPoint.matMult(rotationMatrix);
const x1 = anchor.x + blocking.x1 / scale;
const y1 = anchor.y + blocking.y1 / scale * yStretch;
const x2 = anchor.x + blocking.x2 / scale;
const y2 = anchor.y + blocking.y2 / scale * yStretch;
const x1 = anchor.x + blocking.x1 / perspectiveScale;
const y1 = anchor.y + blocking.y1 / perspectiveScale * yStretch;
const x2 = anchor.x + blocking.x2 / perspectiveScale;
const y2 = anchor.y + blocking.y2 / perspectiveScale * yStretch;
const bbox = [
new Point(x1, y1),
new Point(x2, y1),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,90 +1,189 @@
[
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
}
]
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.999974190748432
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.999980926513672,
4.999974190748432
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.999974190748432
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.999980926513672,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
2.9999542236328125,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.999980926513672,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
4.000061604283047
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
},
{
"geometry": {
"type": "Point",
"coordinates": [
4.000053405761719,
2.999955856573024
]
},
"type": "Feature",
"properties": {}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@
"version": 8,
"metadata": {
"test": {
"ignored": {
"native": "https://github.com/mapbox/mapbox-gl-native/issues/8967"
},
"collisionDebug": true,
"width": 500,
"height": 500,
"debug": true,
"width": 1000,
"height": 1000,
"queryGeometry": [
[
0,
0
100,
85
],
[
500,
500
850,
400
]
]
}
Expand All @@ -30,6 +34,7 @@
"data": "local://data/121points.geojson"
}
},
"glyphs": "local://glyphs/{fontstack}/{range}.pbf",
"sprite": "local://sprites/sprite",
"layers": [
{
Expand All @@ -38,7 +43,13 @@
"source": "geojson",
"layout": {
"symbol-placement": "point",
"icon-image": "bicycle-12"
"icon-image": "bicycle-12",
"text-field": "A lot of test text so that the collision box is big",
"text-max-width": 10,
"text-font": [
"Open Sans Semibold",
"Arial Unicode MS Bold"
]
},
"interactive": true
}
Expand Down