Ankerseite verbessert
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
"""
|
||||
Map access inspired by Norbert Walter
|
||||
Map access inspired by Norbert Walter (mapconverter)
|
||||
|
||||
- North always up no rotation
|
||||
|
||||
"""
|
||||
|
||||
@@ -15,6 +17,10 @@ class MapService():
|
||||
|
||||
def __init__(self, logger, cfg):
|
||||
self.cachepath = os.path.join(cfg['histpath'], "tilecache")
|
||||
self.server = "freenauticalchart.net"
|
||||
self.serverpath = "/qmap-de/{2}/{0}/{1}.png" # 0:x, 1:y, 2:zoom
|
||||
self.apikey = None # future use
|
||||
self.useragent = "OBP/1.0 (X11; Linux x86_64; rv:0.1) OBP60v/0.1"
|
||||
self.lat = 53.56938345759218
|
||||
self.lon = 9.679658234303275
|
||||
self.dither_type = Image.FLOYDSTEINBERG
|
||||
@@ -27,12 +33,16 @@ class MapService():
|
||||
self.width = width
|
||||
self.height = height
|
||||
|
||||
def get_px_meters(self, lat, zoom):
|
||||
# Erdumfang am Äquator: 40075016 m
|
||||
return 40075016 * math.cos(math.radians(lat)) / (2 ** (zoom + 8))
|
||||
|
||||
def web_get_tile(self, domain, path):
|
||||
ssl_context = ssl.create_default_context()
|
||||
conn = http.client.HTTPSConnection(domain, 443, context=ssl_context)
|
||||
headers = {
|
||||
#"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0"
|
||||
"User-Agent": "OBP/1.0 (X11; Linux x86_64; rv:0.1) OBP60v/0.1"
|
||||
"User-Agent": self.useragent
|
||||
}
|
||||
data = None
|
||||
try:
|
||||
@@ -85,10 +95,10 @@ class MapService():
|
||||
#print(f"Tile {x}, {y} loaded from disk cache.")
|
||||
with open(tile_path, 'rb') as f:
|
||||
tile_data = f.read()
|
||||
#ram_cache.set(cache_key, tile_data) # Load into RAM cache
|
||||
return Image.open(tile_path)
|
||||
|
||||
data = self.web_get_tile("freenauticalchart.net", f"/qmap-de/{zoom}/{x}/{y}.png")
|
||||
print(self.serverpath.format(x, y, zoom))
|
||||
data = self.web_get_tile(self.server, self.serverpath.format(x, y, zoom))
|
||||
if data:
|
||||
tile = Image.open(BytesIO(data))
|
||||
tile.save(tile_path)
|
||||
|
||||
Reference in New Issue
Block a user