mm-v1 icon indicating copy to clipboard operation
mm-v1 copied to clipboard

Add ability to cache map area

Open Feodor0090 opened this issue 2 years ago • 2 comments

Feodor0090 avatar Jun 10 '23 22:06 Feodor0090

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

Petrprogs avatar Jun 29 '23 08:06 Petrprogs

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: image

So, all tiles that are in this polygon refers to searched location (Moscow in this case) and we need to download them

Petrprogs avatar Jun 29 '23 10:06 Petrprogs