Skip to content

Commit

Permalink
Merge pull request gramps-project#1530 from SNoiraud/B12971
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-Hall committed Aug 20, 2023
2 parents f63b9b4 + 44629e3 commit 7b2a1bc
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 66 deletions.
8 changes: 4 additions & 4 deletions gramps/plugins/lib/maps/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
YAHOO_STREET = 14
YAHOO_SATELLITE = 15
YAHOO_HYBRID = 16
PERSONAL = 30
# PERSONAL = 30

TILES_PATH = {
OPENSTREETMAP: "openstreetmap",
Expand All @@ -82,7 +82,7 @@
YAHOO_STREET: "yahoostreet",
YAHOO_SATELLITE: "yahoosat",
YAHOO_HYBRID: "yahoohybrid",
PERSONAL: "personal",
# PERSONAL: "personal",
}

MAP_TITLE = {
Expand All @@ -102,7 +102,7 @@
YAHOO_STREET: "Yahoo street",
YAHOO_SATELLITE: "Yahoo sat",
YAHOO_HYBRID: "Yahoo hybrid",
PERSONAL: "Personal map",
# PERSONAL: "Personal map",
}

MAP_TYPE = {
Expand All @@ -116,5 +116,5 @@
VIRTUAL_EARTH_STREET: osmgpsmap.MapSource_t.VIRTUAL_EARTH_STREET,
VIRTUAL_EARTH_SATELLITE: osmgpsmap.MapSource_t.VIRTUAL_EARTH_SATELLITE,
VIRTUAL_EARTH_HYBRID: osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID,
PERSONAL: None,
# PERSONAL: None,
}
77 changes: 39 additions & 38 deletions gramps/plugins/lib/maps/geography.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class GeoGraphyView(OsmGps, NavigationView):
("geography.map_service", constants.OPENSTREETMAP),
("geography.max_places", 5000),
("geography.use-keypad", True),
("geography.personal-map", ""),
# ("geography.personal-map", ""),
)

def __init__(self, title, pdata, dbstate, uistate, bm_type, nav_group):
Expand Down Expand Up @@ -169,8 +169,8 @@ def __init__(self, title, pdata, dbstate, uistate, bm_type, nav_group):
parent=uistate.window,
)

if not config.is_set("geography.personal-map"):
config.set("geography.personal-map", "")
# if not config.is_set("geography.personal-map"):
# config.set("geography.personal-map", "")

self.uistate = uistate
self.uistate.connect("font-changed", self.font_changed)
Expand Down Expand Up @@ -1462,53 +1462,54 @@ def map_options(self, configdialog):
"geography.use-keypad",
extra_callback=self.update_shortcuts,
)
label = configdialog.add_text(
grid,
_(
"If you want to use a specific map provider,"
" You can set the following field to the"
" provider's url.\ni.e:\n"
"http://tile.stamen.com/toner/#Z/#X/#Y.png\n"
"http://tile.stamen.com/terrain/#Z/#X/#Y.jpg\n"
"http://tile.stamen.com/watercolor/#Z/#X/#Y.jpg\n"
"http://tile.xn--pnvkarte-m4a.de/tilegen/#Z/#X/#Y.png\n"
),
6,
line_wrap=False,
)
# set the possibility to copy/paste the urls
label.set_selectable(True)
start = label.get_text().find("http")
end = label.get_text().find("http", start + 1)
label.select_region(start, end)
url = configdialog.add_entry(
grid,
_("Personal map"),
7,
"geography.personal-map",
self.choosen_map,
)
if config.get("geography.personal-map") != "":
url.set_text(config.get("geography.personal-map"))
# label = configdialog.add_text(
# grid,
# _(
# "If you want to use a specific map provider,"
# " You can set the following field to the"
# " provider's url.\ni.e:\n"
# "http://tile.stadiamaps.com/tiles/stamen_toner/#{z}/#{x}/#{y}{r}.png?api_key=YOUR-API-KEY\n"
# "http://tile.stadiamaps.com/tiles/stamen_toner_lite/#{z}/#{x}/#{y}{r}.png?api_key=YOUR-API-KEY\n"
# "http://tile.stadiamaps.com/tiles/stamen_terrain/#{z}/#{x}/#{y}{r}.png?api_key=YOUR-API-KEY\n"
# "http://tile.stadiamaps.com/tiles/stamen_watercolor/#{z}/#{x}/#{y}{r}.jpg?api_key=YOUR-API-KEY\n"
# "http://tile.xn--pnvkarte-m4a.de/tilegen/#Z/#X/#Y.png\n"
# ),
# 6,
# line_wrap=False,
# )
# # set the possibility to copy/paste the urls
# label.set_selectable(True)
# start = label.get_text().find("http")
# end = label.get_text().find("http", start + 1)
# label.select_region(start, end)
# url = configdialog.add_entry(
# grid,
# _("Personal map"),
# 7,
# "geography.personal-map",
# self.choosen_map,
# )
# if config.get("geography.personal-map") != "":
# url.set_text(config.get("geography.personal-map"))
return _("The map"), grid

def choosen_map(self, *obj):
"""
Save the provider map path in the config section.
"""
map_source = obj[0].get_text()
name = constants.TILES_PATH[constants.PERSONAL]
config.set("geography.personal-map", map_source)
self.clear_map(None, name)
# name = constants.TILES_PATH[constants.PERSONAL]
# config.set("geography.personal-map", map_source)
# self.clear_map(None, name)
if map_source == "":
config.set("geography.map_service", constants.OPENSTREETMAP)
self.change_map(self.osm, config.get("geography.map_service"))
self.reload_tiles()
return
if map_source != config.get("geography.personal-map"):
config.set("geography.map_service", constants.PERSONAL)
self.change_new_map(name, map_source)
self.reload_tiles()
# if map_source != config.get("geography.personal-map"):
# config.set("geography.map_service", constants.PERSONAL)
# self.change_new_map(name, map_source)
# self.reload_tiles()

def set_tilepath(self, *obj):
"""
Expand Down
50 changes: 27 additions & 23 deletions gramps/plugins/lib/maps/osmgps.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,15 @@ def change_map(self, obj, map_type):
"""
Change the current map
"""
if map_type == constants.PERSONAL:
map_source = config.get("geography.personal-map")
if map_source == "":
return
name = constants.TILES_PATH[map_type]
self.change_new_map(name, map_source)
config.set("geography.map_service", map_type)
self.current_map = map_type
return
# if map_type == constants.PERSONAL:
# map_source = config.get("geography.pers# onal-map")
# if map_source == "":
# return
# name = constants.TILES_PATH[map_type]
# self.change_new_map(name, map_source)
# config.set("geography.map_service", map_type)
# self.current_map = map_type
# return
if obj is not None:
self.osm.layer_remove_all()
self.osm.image_remove_all()
Expand All @@ -201,10 +201,11 @@ def change_map(self, obj, map_type):
if 0:
self.osm = DummyMapNoGpsPoint()
else:
if map_type == constants.PERSONAL:
self.osm = osmgpsmap.Map(repo_uri=map_source)
else:
self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
# if map_type == constants.PERSONAL:
# self.osm = osmgpsmap.Map(repo_uri=map_source)
# else:
# self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
if http_proxy:
self.osm.set_property("proxy_uri", http_proxy)
self.osm.set_property("tile_cache", tiles_path)
Expand Down Expand Up @@ -266,10 +267,11 @@ def change_new_map(self, name, map_source):
self.osm = DummyMapNoGpsPoint()
else:
map_type = int(config.get("geography.map_service"))
if map_type == constants.PERSONAL:
self.osm = osmgpsmap.Map(repo_uri=map_source)
else:
self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
# if map_type == constants.PERSONAL:
# self.osm = osmgpsmap.Map(repo_uri=map_source)
# else:
# self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
self.osm = osmgpsmap.Map(map_source=constants.MAP_TYPE[map_type])
if http_proxy:
self.osm.set_property("proxy_uri", http_proxy)
self.osm.set_property("tile_cache", tiles_path)
Expand Down Expand Up @@ -314,12 +316,14 @@ def reload_tiles(self):
pt2 = bbox[1]
self.zoom = config.get("geography.zoom")
tile_size = float(256)
if map_idx != constants.PERSONAL:
# get the file extension depending on the map provider
img_format = self.osm.source_get_image_format(map_idx)
else:
filename = config.get("geography.personal-map")
img_format = os.path.splitext(filename)[1]
# if map_idx != constants.PERSONAL:
# # get the file extension depending on the map provider
# img_format = self.osm.source_get_image_format(map_idx)
# else:
# filename = config.get("geography.personal-map")
# img_format = os.path.splitext(filename)[1]
# get the file extension depending on the map provider
img_format = self.osm.source_get_image_format(map_idx)
# calculate the number of images to download in rows and columns
pt1_x = floor(lon2pixel(self.zoom, pt1.rlon, tile_size) / tile_size)
pt1_y = floor(lat2pixel(self.zoom, pt1.rlat, tile_size) / tile_size)
Expand Down
2 changes: 1 addition & 1 deletion gramps/plugins/mapservices/openstreetmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ def calc_url(self):
return

titledescr = place_displayer.display(self.database, place)
self.url = "http://nominatim.openstreetmap.org/" "search.php?q=%s" % "+".join(
self.url = "http://nominatim.openstreetmap.org/" "search?q=%s" % "+".join(
titledescr.split()
)
32 changes: 32 additions & 0 deletions gramps/plugins/webreport/narrativeweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1983,8 +1983,10 @@ def __init__(self, name, dbase):
self.__stamenopts = None
self.__googleopts = None
self.__googlemapkey = None
self.__stamenmapkey = None
self.__olv = None
self.googlemapkeyhelp = None
self.stamenmapkeyhelp = None
self.__ancestortree = None
self.__css = None
self.__gallery = None
Expand Down Expand Up @@ -2681,6 +2683,30 @@ def __add_place_map_options(self, menu):
)
)
addopt("stamenopts", self.__stamenopts)
self.__stamenmapkey = StringOption(_("Stamen maps API key"), "")
self.__stamenmapkey.set_help(
_(
"The API key used for the Stamen maps.\n"
"This key is mandatory and must be valid"
)
)
if not config.is_set("paths.stamen-get-api-key"):
# The following will be used to change the URL if it changes without
# creating a patch. We will only need to change gramps.ini
config.register(
"paths.stamen-get-api-key",
"https://stadiamaps.com/stamen/onboarding",
)
keyvalue = config.get("paths.stamen-get-api-key")
self.stamenmapkeyhelp = StringOption(_("How to get the API key"), keyvalue)
self.stamenmapkeyhelp.connect("value-changed", self.url_changed)
keytooltip = _(
"Copy and paste this value in your browser."
"\nThe Stamen maps service must be selected."
)
self.stamenmapkeyhelp.set_help(keytooltip)
addopt("stamenmapkey", self.__stamenmapkey)
addopt("stamenmapkeyhelp", self.stamenmapkeyhelp)

self.__placemap_options()

Expand Down Expand Up @@ -3022,6 +3048,12 @@ def __placemap_options(self):
else:
self.__googlemapkey.set_available(False)
self.googlemapkeyhelp.set_available(False)
if (place_active or family_active) and mapservice_opts == "StamenMap":
self.__stamenmapkey.set_available(True)
self.stamenmapkeyhelp.set_available(True)
else:
self.__stamenmapkey.set_available(False)
self.stamenmapkeyhelp.set_available(False)

def url_changed(self):
"""
Expand Down

0 comments on commit 7b2a1bc

Please sign in to comment.