aboutsummaryrefslogtreecommitdiff
path: root/shared/src/commonMain/kotlin/mx/trackermap/TrackerMap/utils/MapCalculus.kt
blob: d4d69fa1f2f8cb92f1b893af6e68599d68389f5c (plain)
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
32
33
34
35
36
37
38
39
40
package mx.trackermap.TrackerMap.utils

class MapCalculus {
    companion object {
        /**
         * WhirlyGlobe library uses height rather than zoom levels, but it supports converting
         * Mapnik denominator scales to height, so we can first convert zoom levels to Mapnik
         * denominator scales, and then convert them to height using WhirlyGlobe.
         * Source: https://github.com/openstreetmap/mapnik-stylesheets/blob/master/zoom-to-scale.txt
         */
        fun zoomLevelToScale(zoom: Int): Double? =
            when (zoom) {
                1 -> 279541132.014
                2 -> 139770566.007
                3 -> 69885283.0036
                4 -> 34942641.5018
                5 -> 17471320.7509
                6 -> 8735660.37545
                7 -> 4367830.18772
                8 -> 2183915.09386
                9 -> 1091957.54693
                10 -> 545978.773466
                11 -> 272989.386733
                12 -> 136494.693366
                13 -> 68247.3466832
                14 -> 34123.6733416
                15 -> 17061.8366708
                16 -> 8530.9183354
                17 -> 4265.4591677
                18 -> 2132.72958385
                19 -> 1066.36479193
                20 -> 533.182395965
                21 -> 266.5911979825
                22 -> 133.29559899125
                23 -> 66.647799495625
                24 -> 33.3238997478125
                else -> null
        }
    }
}