Skip to content
Open
Changes from 5 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
8 changes: 6 additions & 2 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import simplify from './simplify';
import createFeature from './feature';

const maxMercatorLatitude = 85.05;
const minVectorLatitude = -maxMercatorLatitude * 8191/8192;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why 8191/8192? Probably should add a comment explaining this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

👍 will add comment if we end up going this route. for now, it's explained in the PR text


// converts GeoJSON feature into an intermediate projected JSON vector format with simplification data

export default function convert(data, options) {
Expand Down Expand Up @@ -136,7 +139,8 @@ function projectX(x) {
}

function projectY(y) {
const sin = Math.sin(y * Math.PI / 180);
const clampedY = y < minVectorLatitude ? minVectorLatitude : y > maxMercatorLatitude ? maxMercatorLatitude : y;
const sin = Math.sin(clampedY * Math.PI / 180);
const y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
return y2;

@mourner mourner May 2, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: If we do the 8191 / 8192 hack, I think it should follow after the projection (not before). Currently (looking at tests) the clamp is 1px off (3094 instead of 3095). E.g. we do return Math.max(y2, 8191 / 8192);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

return Math.max(y2, 8191 / 8192)

@mourner would this clamp features on every tile locally to 8191?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@peterqliu no, since this is a global projection — it projects latitude into 0..1 range (0 is near the north pole, 1 is near the south one). Tile-aware projection happens further down the line

}