Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to cache map area #82

Open
Feodor0090 opened this issue Jun 10, 2023 · 2 comments
Open

Add ability to cache map area #82

Feodor0090 opened this issue Jun 10, 2023 · 2 comments
Assignees
Labels

Comments

@Feodor0090
Copy link
Contributor

No description provided.

@Feodor0090 Feodor0090 self-assigned this Jun 13, 2023
@Petrprogs
Copy link
Contributor

Petrprogs commented Jun 29, 2023

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
Copy link
Contributor

Petrprogs commented Jun 29, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants