0

Я хочу сохранить несколько плиток в каталоге моего приложения. Я думаю, что могу начать через bbox, но я не знаю текущие значения (z, y, x) для загрузки. Bbox всегда такой:

[
   southwest: Point{type=Point, bbox=null, coordinates=[-180.0, -90.0]}, 
   northeast: Point{type=Point, bbox=null, coordinates=[180.0, 90.0]}, 
   infiniteBounds: true
]

Как я могу получить z, y, x для загрузки вручную? Как фоновая задача (без пользовательского интерфейса, просто сохранить изображения в каталоге приложения).

binding.mapView.getMapboxMap().getStyle { style ->
                    style(styleUri = MAP_STYLE) {

                        val url = "https://.../wmts/...:{z}/{y}/{x}?format=image/png"
                        //val url = "file://" + requireActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES) + "/{z}/{y}/{x}.png"

                        style.addSource(
                            rasterSource("tile_source_id") {
                                tileSize(256)
                                tileSet(url, listOf(url)) {}
                            }
                        )
                        style.addLayerAbove(rasterLayer("tile_layer_id", "tile_source_id") {}, "water")
                    }
                }

1 ответ 1

0

Specifies the tile's column {x} and row {y}, as described in the Slippy Map Tilenames specification.

import kotlin.math.*

fun getXYTile(lat : Double, lon: Double, zoom : Int) : Pair<Int, Int> {
        val latRad = Math.toRadians(lat)
        var xtile = floor( (lon + 180) / 360 * (1 shl zoom) ).toInt()
        var ytile = floor( (1.0 - asinh(tan(latRad)) / PI) / 2 * (1 shl zoom) ).toInt()

        if (xtile < 0) {
            xtile = 0
        }
        if (xtile >= (1 shl zoom)) {
            xtile= (1 shl zoom) - 1
        }
        if (ytile < 0) {
            ytile = 0
        }
        if (ytile >= (1 shl zoom)) {
            ytile = (1 shl zoom) - 1
        }

        return Pair(xtile, ytile)
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.