-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Attenuate label size scaling with distance #4547
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
12cd4e7
Fix "labelMinScale" logic in getGlyphQuads:
ChrisLoer 9b6f46d
Fix comment: Tile.coord is a TileCoord, not a Coordinate
ChrisLoer 8332149
Make render test summary failures searchable
ChrisLoer abfaa59
Recalculate collision box shape at placement time based on distance f…
ChrisLoer cf3d37a
Fix short-circuit guard for queries against empty collision tiles. `g…
ChrisLoer 3d33278
Attenuate the effect of perspective on label scale:
ChrisLoer 1e2d4e7
Standardizing on highp precision based on discussion in https://githu…
ChrisLoer a594f4d
Generate line collision boxes for scales < 1.
ChrisLoer f0939ba
Throttle symbol re-placement to once every 300ms.
ChrisLoer b4aa8eb
Support pitch-scaling attenuation behavior in debug collision boxes.
ChrisLoer 2b05c3a
Add 'max-camera-distance' uniform for hiding labels in the distance t…
ChrisLoer 1593dce
Render tests for icon and text pitch scaling.
ChrisLoer 88b28eb
Update existing pitched map text rendering tests to match new pitched…
ChrisLoer 648fc0e
Fix type info in comments: Coordinate -> TileCoord
ChrisLoer 71ca322
Small performance enhancement: don't add "pitch padding" boxes for li…
ChrisLoer 3fe790c
Don't reuse wrapped tiles in SourceCache.
ChrisLoer ff95426
Add pitched-collision render tests, including case of wrapped tiles.
ChrisLoer ecfeb4e
Tiny shader logic simplification.
ChrisLoer d3b83f1
Make debug collision boxes use same fade texture as the symbols.
ChrisLoer 6f06f78
Make perspective_zoom_adjust use the same .1 precision used by labelm…
ChrisLoer 4b0235a
Add simple CanvasSource debug page.
ChrisLoer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Mapbox GL JS debug page</title> | ||
<meta charset='utf-8'> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no"> | ||
<link rel='stylesheet' href='/dist/mapbox-gl.css' /> | ||
<style> | ||
body { margin: 0; padding: 0; } | ||
html, body, #map { height: 100%; } | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<canvas id="testCanvasID" width="200" height="100" | ||
style="border:10px solid blue;"> | ||
Canvas not supported | ||
</canvas> | ||
<div id='map'></div> | ||
|
||
<script type="application/javascript"> | ||
function drawToCanvas() { | ||
var canvas = document.getElementById('testCanvasID'); | ||
if (canvas.getContext) { | ||
var ctx = canvas.getContext('2d'); | ||
|
||
ctx.fillStyle = 'rgb(200, 0, 0)'; | ||
ctx.fillRect(10, 10, 50, 50); | ||
|
||
ctx.fillStyle = 'rgba(0, 0, 200, 0.5)'; | ||
ctx.fillRect(30, 30, 50, 50); | ||
} | ||
} | ||
</script> | ||
<script src='/dist/mapbox-gl-dev.js'></script> | ||
<script src='/debug/access_token_generated.js'></script> | ||
<script> | ||
|
||
var canvasStyle = { | ||
"version": 8, | ||
"sources": { | ||
"canvas": { | ||
"type": "canvas", | ||
"canvas": "testCanvasID", | ||
"coordinates": [ | ||
[-122.51596391201019, 37.56238816766053], | ||
[-122.51467645168304, 37.56410183312965], | ||
[-122.51309394836426, 37.563391708549425], | ||
[-122.51423120498657, 37.56161849366671] | ||
] | ||
} | ||
}, | ||
"layers": [{ | ||
"id": "background", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "rgb(4,7,14)" | ||
} | ||
}, { | ||
"id": "canvas", | ||
"type": "raster", | ||
"source": "canvas" | ||
}] | ||
}; | ||
|
||
var map = new mapboxgl.Map({ | ||
container: 'map', | ||
minZoom: 14, | ||
zoom: 17, | ||
center: [-122.514426, 37.562984], | ||
bearing: -96, | ||
style: canvasStyle, | ||
hash: false | ||
}); | ||
|
||
drawToCanvas(); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
attribute vec2 a_pos; | ||
attribute vec2 a_anchor_pos; | ||
attribute vec2 a_extrude; | ||
attribute vec2 a_data; | ||
|
||
uniform mat4 u_matrix; | ||
uniform float u_scale; | ||
uniform float u_pitch; | ||
uniform float u_collision_y_stretch; | ||
uniform float u_camera_to_center_distance; | ||
|
||
varying float v_max_zoom; | ||
varying float v_placement_zoom; | ||
varying float v_perspective_zoom_adjust; | ||
varying vec2 v_fade_tex; | ||
|
||
void main() { | ||
gl_Position = u_matrix * vec4(a_pos + a_extrude / u_scale, 0.0, 1.0); | ||
vec4 projectedPoint = u_matrix * vec4(a_anchor_pos, 0, 1); | ||
highp float camera_to_anchor_distance = projectedPoint.w; | ||
highp float collision_perspective_ratio = 1.0 + 0.5 * ((camera_to_anchor_distance / u_camera_to_center_distance) - 1.0); | ||
|
||
highp float incidence_stretch = camera_to_anchor_distance / (u_camera_to_center_distance * cos(u_pitch)); | ||
highp float collision_adjustment = max(1.0, incidence_stretch / u_collision_y_stretch); | ||
|
||
gl_Position = u_matrix * vec4(a_pos + a_extrude * collision_perspective_ratio * collision_adjustment / u_scale, 0.0, 1.0); | ||
|
||
v_max_zoom = a_data.x; | ||
v_placement_zoom = a_data.y; | ||
|
||
v_perspective_zoom_adjust = floor(log2(collision_perspective_ratio * collision_adjustment) * 10.0); | ||
v_fade_tex = vec2((v_placement_zoom + v_perspective_zoom_adjust) / 255.0, 0.0); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the units here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hesitate to say "pixels" because that's not quite right, but it's distance in view-space coordinates, which is pixel-derived. It's the same units as "cameraToCenterDistance", which is defined as:
0.5 / Math.tan(this._fov / 2) * this.height
(andheight
is in pixels)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, can you add a this explanation as a comment?