Skip to content
Open
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
10 changes: 8 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 tileResolution = 8192;

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

export default function convert(data, options) {
Expand Down Expand Up @@ -135,8 +138,11 @@ function projectX(x) {
return x / 360 + 0.5;
}

// clamps the rendered latitude to what's renderable on the south extreme, and what's Mercator on the north extreme

function projectY(y) {
const sin = Math.sin(y * Math.PI / 180);
const clampedY = Math.min(Math.max(y, -maxMercatorLatitude), maxMercatorLatitude);
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 Math.max(y2, (tileResolution - 1) / tileResolution);
}