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

Resolve Z units to meters #3509

Merged
merged 4 commits into from
Nov 1, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions js/geo/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ class Transform {
mat4.rotateX(m, m, this._pitch);
mat4.rotateZ(m, m, this.angle);
mat4.translate(m, m, [-this.x, -this.y, 0]);
mat4.scale(m, m, [1, 1,
// scale vertically to meters per pixel (inverse of ground resolution)
(Math.pow(2, this.zoom) * 512) / (2 * Math.PI * 6378137 * Math.abs(Math.cos(this.center.lat * (Math.PI / 180)))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document or split this up a bit more? maybe replace 2 * Math.PI * 6378137 with a circumferenceOfEarth constant

1]);

this.projMatrix = m;

Expand Down
23 changes: 7 additions & 16 deletions js/render/draw_fill_extrusion.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ function drawExtrusion(painter, source, layer, coord) {
setPattern(image, tile, coord, painter, program, true);
}

setMatrix(program, painter, coord, tile, layer);
painter.gl.uniformMatrix4fv(program.u_matrix, false, painter.translatePosMatrix(
coord.posMatrix,
tile,
layer.paint['fill-extrusion-translate'],
layer.paint['fill-extrusion-translate-anchor']
));

setLight(program, painter);

for (const segment of buffers.segments) {
Expand All @@ -171,21 +177,6 @@ function drawExtrusion(painter, source, layer, coord) {
}
}

function setMatrix(program, painter, coord, tile, layer) {
const zScale = Math.pow(2, painter.transform.zoom) / 50000;

painter.gl.uniformMatrix4fv(program.u_matrix, false, mat4.scale(
mat4.create(),
painter.translatePosMatrix(
coord.posMatrix,
tile,
layer.paint['fill-extrusion-translate'],
layer.paint['fill-extrusion-translate-anchor']
),
[1, 1, zScale, 1])
);
}

function setLight(program, painter) {
const gl = painter.gl;
const light = painter.style.light;
Expand Down