From 4f667dd96d749bbcfc05d73ac80be189288b2780 Mon Sep 17 00:00:00 2001 From: derekhe Date: Wed, 24 Nov 2021 22:45:32 +0800 Subject: [PATCH] Add more google maps server. Hope can fix the loading issue for some people --- 7zignore | 1 + config-prod.ini | 2 +- config.ini | 2 +- src/app.py | 7 ++++--- src/server.py | 8 +++++++- src/settings.py | 3 ++- 6 files changed, 16 insertions(+), 7 deletions(-) diff --git a/7zignore b/7zignore index d1ea5417..50578c23 100644 --- a/7zignore +++ b/7zignore @@ -3,6 +3,7 @@ cache doc nginx/logs/* +nginx/temp/* src/__pycache__/* .git dist/ \ No newline at end of file diff --git a/config-prod.ini b/config-prod.ini index 831a363e..3aaadb92 100644 --- a/config-prod.ini +++ b/config-prod.ini @@ -9,7 +9,7 @@ max_cache_size_g = 20 threads = 200 [google] -server = mt1.google.com +server = khms1.google.com [general] warning = enabled \ No newline at end of file diff --git a/config.ini b/config.ini index 1018e8d2..6b00f64c 100644 --- a/config.ini +++ b/config.ini @@ -9,7 +9,7 @@ max_cache_size_g = 20 threads = 200 [google] -server = mt1.google.com +server = khms1.google.com [general] warning = disabled diff --git a/src/app.py b/src/app.py index c581343c..b6fe4498 100644 --- a/src/app.py +++ b/src/app.py @@ -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 * @@ -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 @@ -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") diff --git a/src/server.py b/src/server.py index a80bb13c..e2c9fd12 100644 --- a/src/server.py +++ b/src/server.py @@ -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") 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) diff --git a/src/settings.py b/src/settings.py index b2b4dd0d..4f8dadfa 100644 --- a/src/settings.py +++ b/src/settings.py @@ -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):