Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Add more google maps server. Hope can fix the loading issue for some …
Browse files Browse the repository at this point in the history
…people
  • Loading branch information
derekhe committed Nov 24, 2021
1 parent 06b7ebe commit 4f667dd
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
1 change: 1 addition & 0 deletions 7zignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
cache
doc
nginx/logs/*
nginx/temp/*
src/__pycache__/*
.git
dist/
2 changes: 1 addition & 1 deletion config-prod.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ max_cache_size_g = 20
threads = 200

[google]
server = mt1.google.com
server = khms1.google.com

[general]
warning = enabled
2 changes: 1 addition & 1 deletion config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ max_cache_size_g = 20
threads = 200

[google]
server = mt1.google.com
server = khms1.google.com

[general]
warning = disabled
Expand Down
7 changes: 4 additions & 3 deletions src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from diskcache import Cache
from multiprocessing import Process
from runner import add_cert, override_hosts, restore_hosts, get_hosts_origin_ips, del_cert
from server import run_server, clear_cache
from server import run_server, clear_cache, url_mapping
from settings import Settings
from threading import Thread
from tkinter import *
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_google_access(self):

def request_google(self):
return requests.get(
f"https://{self.selected_google_server.get()}/vt/lyrs=s&x=1&y=1&z=1", timeout=3,
url_mapping(self.selected_google_server.get(), 1, 1, 1), timeout=3,
proxies={"https": self.settings.proxy_url}, verify=False)

@staticmethod
Expand Down Expand Up @@ -289,7 +289,8 @@ def run(self):
self.server_process = Process(
target=run_server,
args=(
self.settings.cache_size, self.settings.proxy_url, self.settings.google_server, get_hosts_origin_ips()))
self.settings.cache_size, self.settings.proxy_url, self.settings.google_server,
get_hosts_origin_ips()))
self.server_process.start()
self.nginx_process = subprocess.Popen(
"nginx.exe", shell=True, cwd="./nginx")
Expand Down
8 changes: 7 additions & 1 deletion src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ def mtx(dummy=None):
response.headers[k] = v
return response

def url_mapping(server, tile_x, tile_y, level_of_detail):
if "mt" in server:
return f"https://{server}/vt/lyrs=s&x={tile_x}&y={tile_y}&z={level_of_detail}"

if "khms" in server:
return f"https://{server}/kh/v=908?x={tile_x}&y={tile_y}&z={level_of_detail}"

@app.route("/tiles/akh<path>")
def tiles(path):
quadkey = re.findall(r"(\d+).jpeg", path)[0]
tile_x, tile_y, level_of_detail = quad_key_to_tile_xy(quadkey)

url = f"https://{__google_server}/vt/lyrs=s&x={tile_x}&y={tile_y}&z={level_of_detail}"
url = url_mapping(__google_server, tile_x, tile_y, level_of_detail)

cache_key = f"{level_of_detail}{tile_x}{tile_y}"
content = __cache.get(cache_key)
Expand Down
3 changes: 2 additions & 1 deletion src/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def cache_size(self):

@property
def google_servers(self):
return ['mt1.google.com', 'mt2.google.com', 'mt3.google.com']
return ["khms1.google.com", "khms2.google.com",
"khms3.google.com", 'mt1.google.com', 'mt2.google.com', 'mt3.google.com']

@property
def google_server(self):
Expand Down

0 comments on commit 4f667dd

Please sign in to comment.