mirror of
https://github.com/markqvist/Sideband.git
synced 2024-12-27 00:19:25 -05:00
Added ability to use quad-key sources in mapview
This commit is contained in:
parent
fe8db4b950
commit
0a2a87775e
@ -89,6 +89,21 @@ class Downloader:
|
||||
response.raise_for_status()
|
||||
return callback, (url, response)
|
||||
|
||||
def __to_quad(self, x, y, z):
|
||||
quad_key = []
|
||||
i = z
|
||||
while i > 0:
|
||||
digit = 0
|
||||
mask = 1 << (i-1)
|
||||
if (x & mask) != 0:
|
||||
digit += 1
|
||||
if (y & mask) != 0:
|
||||
digit += 2
|
||||
quad_key.append(str(digit))
|
||||
|
||||
i -= 1
|
||||
return "".join(quad_key)
|
||||
|
||||
def _load_tile(self, tile):
|
||||
if tile.state == "done":
|
||||
return
|
||||
@ -97,9 +112,16 @@ class Downloader:
|
||||
# Logger.debug("Downloader: use cache {}".format(cache_fn))
|
||||
return tile.set_source, (cache_fn,)
|
||||
tile_y = tile.map_source.get_row_count(tile.zoom) - tile.tile_y - 1
|
||||
|
||||
if tile.map_source.quad_key:
|
||||
uri = tile.map_source.url.format(
|
||||
q=self.__to_quad(tile.tile_x,tile_y,tile.zoom), s=choice(tile.map_source.subdomains)
|
||||
)
|
||||
else:
|
||||
uri = tile.map_source.url.format(
|
||||
z=tile.zoom, x=tile.tile_x, y=tile_y, s=choice(tile.map_source.subdomains)
|
||||
)
|
||||
|
||||
# Logger.debug("Downloader: download(tile) {}".format(uri))
|
||||
response = requests.get(uri, headers={'User-agent': USER_AGENT}, timeout=5)
|
||||
try:
|
||||
|
@ -23,7 +23,7 @@ class MapSource:
|
||||
"""
|
||||
|
||||
attribution_osm = 'Maps & Data © [i][ref=http://www.osm.org/copyright]OpenStreetMap contributors[/ref][/i]'
|
||||
attribution_thunderforest = 'Maps © [i][ref=http://www.thunderforest.com]Thunderforest[/ref][/i], Data © [i][ref=http://www.osm.org/copyright]OpenStreetMap contributors[/ref][/i]'
|
||||
attribution_ve = 'Maps © [i][ref=http://www.virtualearth.net]VirtualEarth[/ref][/i]'
|
||||
|
||||
# list of available providers
|
||||
# cache_key: (is_overlay, minzoom, maxzoom, url, attribution)
|
||||
@ -35,6 +35,13 @@ class MapSource:
|
||||
"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
|
||||
attribution_osm,
|
||||
),
|
||||
"ve": (
|
||||
0,
|
||||
0,
|
||||
19,
|
||||
"http://ecn.t3.tiles.virtualearth.net/tiles/a{q}.jpeg?g=1",
|
||||
attribution_ve,
|
||||
),
|
||||
"osm-hot": (
|
||||
0,
|
||||
0,
|
||||
@ -42,63 +49,6 @@ class MapSource:
|
||||
"http://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png",
|
||||
"",
|
||||
),
|
||||
"osm-de": (
|
||||
0,
|
||||
0,
|
||||
18,
|
||||
"http://{s}.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png",
|
||||
"Tiles @ OSM DE",
|
||||
),
|
||||
"osm-fr": (
|
||||
0,
|
||||
0,
|
||||
20,
|
||||
"http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png",
|
||||
"Tiles @ OSM France",
|
||||
),
|
||||
"cyclemap": (
|
||||
0,
|
||||
0,
|
||||
17,
|
||||
"http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png",
|
||||
"Tiles @ Andy Allan",
|
||||
),
|
||||
"thunderforest-cycle": (
|
||||
0,
|
||||
0,
|
||||
19,
|
||||
"http://{s}.tile.thunderforest.com/cycle/{z}/{x}/{y}.png",
|
||||
attribution_thunderforest,
|
||||
),
|
||||
"thunderforest-transport": (
|
||||
0,
|
||||
0,
|
||||
19,
|
||||
"http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png",
|
||||
attribution_thunderforest,
|
||||
),
|
||||
"thunderforest-landscape": (
|
||||
0,
|
||||
0,
|
||||
19,
|
||||
"http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
|
||||
attribution_thunderforest,
|
||||
),
|
||||
"thunderforest-outdoors": (
|
||||
0,
|
||||
0,
|
||||
19,
|
||||
"http://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png",
|
||||
attribution_thunderforest,
|
||||
),
|
||||
# no longer available
|
||||
# "mapquest-osm": (0, 0, 19, "http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpeg", "Tiles Courtesy of Mapquest", {"subdomains": "1234", "image_ext": "jpeg"}),
|
||||
# "mapquest-aerial": (0, 0, 19, "http://oatile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpeg", "Tiles Courtesy of Mapquest", {"subdomains": "1234", "image_ext": "jpeg"}),
|
||||
# more to add with
|
||||
# https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js
|
||||
# not working ?
|
||||
# "openseamap": (0, 0, 19, "http://tiles.openseamap.org/seamark/{z}/{x}/{y}.png",
|
||||
# "Map data @ OpenSeaMap contributors"),
|
||||
}
|
||||
|
||||
def __init__(
|
||||
@ -111,6 +61,7 @@ class MapSource:
|
||||
image_ext="png",
|
||||
attribution="© OpenStreetMap contributors",
|
||||
subdomains="abc",
|
||||
quad_key = False,
|
||||
**kwargs
|
||||
):
|
||||
if cache_key is None:
|
||||
@ -124,6 +75,7 @@ class MapSource:
|
||||
self.image_ext = image_ext
|
||||
self.attribution = attribution
|
||||
self.subdomains = subdomains
|
||||
self.quad_key = quad_key
|
||||
self.cache_fmt = "{cache_key}_{zoom}_{tile_x}_{tile_y}.{image_ext}"
|
||||
self.dp_tile_size = min(dp(self.tile_size), self.tile_size * 2)
|
||||
self.default_lat = self.default_lon = self.default_zoom = None
|
||||
@ -132,6 +84,7 @@ class MapSource:
|
||||
|
||||
@staticmethod
|
||||
def from_provider(key, **kwargs):
|
||||
quad_key = kwargs.get('quad_key', False)
|
||||
provider = MapSource.providers[key]
|
||||
cache_dir = kwargs.get('cache_dir', CACHE_DIR)
|
||||
options = {}
|
||||
@ -145,6 +98,7 @@ class MapSource:
|
||||
url=url,
|
||||
cache_dir=cache_dir,
|
||||
attribution=attribution,
|
||||
quad_key=quad_key,
|
||||
**options
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user