-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
31 lines (24 loc) · 1007 Bytes
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(() => {
function coordinatesPrecision(zoom) {
return Math.ceil((zoom * Math.LN2 + Math.log(256 / 360 / 0.5)) / Math.LN10);
}
window.buildNextURL = (options, compare) => {
const nextURL = new URL(window.location.href);
const searchParams = nextURL.searchParams;
const rotation = Math.round(options.rotation);
const pitch = Math.round(options.pitch);
const precision = coordinatesPrecision(options.zoom);
searchParams.set('lng', options.lng.toFixed(precision));
searchParams.set('lat', options.lat.toFixed(precision));
searchParams.set('zoom', options.zoom.toFixed(precision));
if (rotation !== 0) {
searchParams.set('rotation', rotation.toString());
}
if (pitch !== 0) {
searchParams.set('pitch', pitch.toString());
}
searchParams.set('compare', compare);
searchParams.set('lang', options.lang);
return nextURL.toString();
};
})();