File tree 4 files changed +15
-22
lines changed
4 files changed +15
-22
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ function redirect(req) {
23
23
if ( req . originUrl && req . url . match ( matcher ) ) {
24
24
if ( ! disabledHosts . includes ( getHostname ( req . originUrl ) ) ) {
25
25
return {
26
- redirectUrl : runtimeMapUrl + '?' + req . url . split ( '?' ) [ 1 ] ,
26
+ redirectUrl : runtimeMapUrl + '?' + req . url . split ( '?' ) . pop ( ) ,
27
27
}
28
28
}
29
29
}
Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ function convertType(item) {
47
47
val = tileTypes [ tileIndex < tileTypes . length && tileIndex >= 0 ? tileIndex : 0 ]
48
48
break
49
49
case 'z' : // base64 encoded coords
50
- val = Buffer . from ( item , 'base64' ) . toString ( 'utf-8' )
50
+ val = Uint8Array . fromBase64 ( item ) . toString ( 'utf-8' )
51
51
}
52
52
53
53
return [ val , type === 'm' ]
Original file line number Diff line number Diff line change 1
1
import { parsePB , tileTypes } from './parsePB.js'
2
2
import { parseDMS } from './parseDMS.js'
3
- import { getMapZoom } from './zoom.js'
3
+ import { altitude2zoom } from './zoom.js'
4
4
5
5
export const nominatimQ = 'https://nominatim.openstreetmap.org/search?limit=1&format=json&q='
6
6
const cidMatch = / ^ 0 x [ \d a - f ] + : 0 x [ \d a - f ] + $ / i
@@ -41,13 +41,13 @@ export async function readPB(param) {
41
41
let data = parsePB ( param . split ( '!' ) . slice ( 1 ) ) [ 0 ]
42
42
43
43
/** @type {number[] } */
44
- let mapArea = data [ 0 ] [ 0 ]
44
+ let mapArea = data [ 0 ] [ 0 ] . reverse ( )
45
45
mapData . area = {
46
- lat : mapArea [ 2 ] ,
46
+ lat : mapArea [ 0 ] ,
47
47
lon : mapArea [ 1 ] ,
48
48
}
49
49
50
- mapData . zoom = getMapZoom ( mapArea [ 0 ] )
50
+ mapData . zoom = altitude2zoom ( mapArea [ 2 ] )
51
51
52
52
/** @type {any[] | string } */
53
53
let currMarkers = data [ 1 ]
@@ -98,6 +98,8 @@ export async function readQ(addr) {
98
98
99
99
/** @type {LatLon[] } */
100
100
const json = await res . json ( )
101
+ if ( ! json . length ) return null
102
+
101
103
/** @type {LatLon } */
102
104
const body = json [ 0 ]
103
105
Original file line number Diff line number Diff line change 1
- const factor = 35200000
2
- const precision = 10
1
+ const earthCircumference = 40_075_000.017 // in m
2
+ const factor = 1.25
3
3
4
4
/**
5
5
* Converts *altitude over the map* to *zoom level of the map*
6
- * TODO: Should be rewritten!!!
6
+ * https://stackoverflow.com/a/37142662
7
7
*
8
- * Reference: https://groups.google.com/g/google-earth-browser-plugin/c/eSL9GlAkWBk/m/T4mdToJz_FgJ
9
- * @param {number } alt Altitude as number
10
- * @returns {number } Zoom level between 0 and 19
8
+ * @param {number } alt Altitude in m
9
+ * @returns {number } Zoom level
11
10
*/
12
- export function getMapZoom ( alt ) {
13
- let zoom = Math . log2 ( factor / alt ) * 1.225
14
- zoom = Math . round ( ( zoom + Number . EPSILON ) * precision ) / precision
15
-
16
- if ( zoom < 0 ) {
17
- zoom = 0
18
- } else if ( zoom > 19 ) {
19
- zoom = 19
20
- }
21
- return zoom
11
+ export function altitude2zoom ( alt ) {
12
+ return ( Math . log2 ( earthCircumference / alt ) + 1 ) * factor
22
13
}
You can’t perform that action at this time.
0 commit comments