Skip to content

Commit

Permalink
Merge pull request #25 from suchyDev/master
Browse files Browse the repository at this point in the history
Clickable attribution labels
  • Loading branch information
tito committed Nov 28, 2016
2 parents cf25fec + 57b38cc commit 1e61b9c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
39 changes: 17 additions & 22 deletions mapview/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,26 @@ class MapSource(object):
"""Base class for implementing a map source / provider
"""

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]'

# list of available providers
# cache_key: (is_overlay, minzoom, maxzoom, url, attribution)
providers = {
"osm": (0, 0, 19, "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
""),
"osm-hot": (0, 0, 19, "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",
"@ OpenCycleMap via OpenStreetMap"),
"thunderforest-transport": (0, 0, 19, "http://{s}.tile.thunderforest.com/transport/{z}/{x}/{y}.png",
"@ OpenCycleMap via OpenStreetMap"),
"thunderforest-landscape": (0, 0, 19, "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
"@ OpenCycleMap via OpenStreetMap"),
"thunderforest-outdoors": (0, 0, 19, "http://{s}.tile.thunderforest.com/outdoors/{z}/{x}/{y}.png",
"@ OpenCycleMap via OpenStreetMap"),
"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"}),
"osm": (0, 0, 19, "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", attribution_osm),
"osm-hot": (0, 0, 19, "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 ?
Expand Down
11 changes: 10 additions & 1 deletion mapview/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from kivy.clock import Clock
from kivy.metrics import dp
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.scatter import Scatter
from kivy.uix.behaviors import ButtonBehavior
Expand All @@ -21,6 +22,9 @@
from mapview.source import MapSource
from mapview.utils import clamp

import webbrowser



Builder.load_string("""
<MapMarker>:
Expand Down Expand Up @@ -48,13 +52,14 @@
size: self.size
StencilPop
Label:
ClickableLabel:
text: root.map_source.attribution if hasattr(root.map_source, "attribution") else ""
size_hint: None, None
size: self.texture_size[0] + sp(8), self.texture_size[1] + sp(4)
font_size: "10sp"
right: [root.right, self.center][0]
color: 0, 0, 0, 1
markup: True
canvas.before:
Color:
rgba: .8, .8, .8, .8
Expand All @@ -78,6 +83,10 @@
""")

class ClickableLabel(Label):
def on_ref_press(self, *args):
webbrowser.open(str(args[0]), new=2)


class Tile(Rectangle):
@property
Expand Down

0 comments on commit 1e61b9c

Please sign in to comment.