Open Feodor0090 opened 1 year ago
So I think that we need to get the coordinates of the 4 extreme points of the selected area in order to get a polygon. Next, we get the x, y and z tiles of these points and cache all the tiles that are included in this polygon
Example code in Python for getting tiles coords from lon and lat:
import math def deg2num(lat_deg, lon_deg, zoom): lat_rad = math.radians(lat_deg) n = 2.0 ** zoom xtile = int((lon_deg + 180.0) / 360.0 * n) ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n) return (xtile, ytile) print(deg2num(37.617698, 55.755864, 4)) # Output: (10, 6) # x = 10, y = 6
We can use "https://api-maps.yandex.ru/services/search/v2/". In "features" json array we need "boundedBy" key.
"features": [
{
"type": "Feature",
"properties": {
"id": "1",
"name": "Moscow",
"description": "Russian Federation",
"boundedBy": [
[
36.803268,
55.142226
],
[
37.967799,
56.021286
]
],
Its values are diagonal points. From them we can make polygon:
So, all tiles that are in this polygon refers to searched location (Moscow in this case) and we need to download them
So I think that we need to get the coordinates of the 4 extreme points of the selected area in order to get a polygon. Next, we get the x, y and z tiles of these points and cache all the tiles that are included in this polygon
Example code in Python for getting tiles coords from lon and lat: