From a2ae7b93fc43a01b9700436100d35fe8ed1bd9eb Mon Sep 17 00:00:00 2001 From: Serge Noiraud Date: Fri, 10 Jan 2020 17:40:33 +0100 Subject: [PATCH] Geography: Add custom tiles provider (#976) * Geography: Add custom tiles provider Fixes #11416 * Geography: some cleanup --- gramps/gen/config.py | 1 + gramps/plugins/lib/maps/constants.py | 4 +++ gramps/plugins/lib/maps/geography.py | 47 ++++++++++++++++++++++++++++ gramps/plugins/lib/maps/osmgps.py | 17 ++++++++-- gramps/plugins/view/geoclose.py | 1 + gramps/plugins/view/geofamclose.py | 1 + gramps/plugins/view/geomoves.py | 1 + gramps/plugins/view/geoperson.py | 1 + gramps/plugins/view/geoplaces.py | 1 + 9 files changed, 72 insertions(+), 2 deletions(-) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index 8a2ea79a3..be9a3fdad 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -186,6 +186,7 @@ register('geography.zoom_when_center', 12) register('geography.show_cross', False) register('geography.path', "") register('geography.use-keypad', True) +register('geography.personal-map', "") # note that other calls to "register" are done in realtime (when # needed), for instance to four 'interface.clipboard' variables -- diff --git a/gramps/plugins/lib/maps/constants.py b/gramps/plugins/lib/maps/constants.py index 45c0a5d14..c87fd87b1 100644 --- a/gramps/plugins/lib/maps/constants.py +++ b/gramps/plugins/lib/maps/constants.py @@ -64,6 +64,7 @@ VIRTUAL_EARTH_HYBRID = 13 YAHOO_STREET = 14 YAHOO_SATELLITE = 15 YAHOO_HYBRID = 16 +PERSONAL = 30 TILES_PATH = { OPENSTREETMAP : "openstreetmap", @@ -82,6 +83,7 @@ TILES_PATH = { YAHOO_STREET : "yahoostreet", YAHOO_SATELLITE : "yahoosat", YAHOO_HYBRID : "yahoohybrid", + PERSONAL : "personal", } MAP_TITLE = { @@ -101,6 +103,7 @@ MAP_TITLE = { YAHOO_STREET : "Yahoo street", YAHOO_SATELLITE : "Yahoo sat", YAHOO_HYBRID : "Yahoo hybrid", + PERSONAL : "Personal map", } MAP_TYPE = { @@ -114,5 +117,6 @@ MAP_TYPE = { 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, } diff --git a/gramps/plugins/lib/maps/geography.py b/gramps/plugins/lib/maps/geography.py index 356a1553b..ea732cd24 100644 --- a/gramps/plugins/lib/maps/geography.py +++ b/gramps/plugins/lib/maps/geography.py @@ -125,6 +125,7 @@ class GeoGraphyView(OsmGps, NavigationView): ('geography.map_service', constants.OPENSTREETMAP), ('geography.max_places', 5000), ('geography.use-keypad', True), + ('geography.personal-map', ""), ) def __init__(self, title, pdata, dbstate, uistate, @@ -143,6 +144,8 @@ class GeoGraphyView(OsmGps, NavigationView): self.lock = config.get("geography.lock") if config.get('geography.path') == "": config.set('geography.path', GEOGRAPHY_PATH) + if not config.is_set('geography.personal-map'): + config.set('geography.personal-map', "") self.uistate = uistate self.uistate.connect('font-changed', self.font_changed) @@ -1266,8 +1269,52 @@ class GeoGraphyView(OsmGps, NavigationView): 'from the keyboard.'), 5, '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')) 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] + print(self.current_map, constants.PERSONAL, + map_source, config.get('geography.personal-map')) + config.set('geography.personal-map', map_source) + self.clear_map(None, name) + if map_source == "": + print("reset osm") + 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'): + print("set personal") + config.set("geography.map_service", constants.PERSONAL) + self.change_new_map(name, map_source) + self.reload_tiles() + def set_tilepath(self, *obj): """ Save the tile path in the config section. diff --git a/gramps/plugins/lib/maps/osmgps.py b/gramps/plugins/lib/maps/osmgps.py index 5d3c19f2a..3bee74882 100644 --- a/gramps/plugins/lib/maps/osmgps.py +++ b/gramps/plugins/lib/maps/osmgps.py @@ -147,6 +147,15 @@ class OsmGps: """ 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 obj is not None: self.osm.layer_remove_all() self.osm.image_remove_all() @@ -277,8 +286,12 @@ class OsmGps: pt2 = bbox[1] self.zoom = config.get("geography.zoom") tile_size = float(256) - # get the file extension depending on the map provider - img_format = self.osm.source_get_image_format(map_idx) + 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] # 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) diff --git a/gramps/plugins/view/geoclose.py b/gramps/plugins/view/geoclose.py index d3aac4e2c..c6377e679 100644 --- a/gramps/plugins/view/geoclose.py +++ b/gramps/plugins/view/geoclose.py @@ -204,6 +204,7 @@ class GeoClose(GeoGraphyView): ('geography.center-lat', 0.0), ('geography.center-lon', 0.0), ('geography.use-keypad', True), + ('geography.personal-map', ""), ('geography.map_service', constants.OPENSTREETMAP), ('geography.max_places', 5000), diff --git a/gramps/plugins/view/geofamclose.py b/gramps/plugins/view/geofamclose.py index 39cd524ce..bfbe33cb1 100644 --- a/gramps/plugins/view/geofamclose.py +++ b/gramps/plugins/view/geofamclose.py @@ -203,6 +203,7 @@ class GeoFamClose(GeoGraphyView): ('geography.center-lat', 0.0), ('geography.center-lon', 0.0), ('geography.use-keypad', True), + ('geography.personal-map', ""), ('geography.map_service', constants.OPENSTREETMAP), ('geography.max_places', 5000), diff --git a/gramps/plugins/view/geomoves.py b/gramps/plugins/view/geomoves.py index 405828aa1..d88e257eb 100644 --- a/gramps/plugins/view/geomoves.py +++ b/gramps/plugins/view/geomoves.py @@ -191,6 +191,7 @@ class GeoMoves(GeoGraphyView): ('geography.center-lat', 0.0), ('geography.center-lon', 0.0), ('geography.use-keypad', True), + ('geography.personal-map', ""), ('geography.map_service', constants.OPENSTREETMAP), ('geography.max_places', 5000), diff --git a/gramps/plugins/view/geoperson.py b/gramps/plugins/view/geoperson.py index 523ae1169..7d2e8efe5 100644 --- a/gramps/plugins/view/geoperson.py +++ b/gramps/plugins/view/geoperson.py @@ -191,6 +191,7 @@ class GeoPerson(GeoGraphyView): ('geography.center-lat', 0.0), ('geography.center-lon', 0.0), ('geography.use-keypad', True), + ('geography.personal-map', ""), #('geography.gps_mode', GPS_DISABLED), #('geography.gps_update_rate', float(1.0)), diff --git a/gramps/plugins/view/geoplaces.py b/gramps/plugins/view/geoplaces.py index d054a9100..bc520c7ff 100644 --- a/gramps/plugins/view/geoplaces.py +++ b/gramps/plugins/view/geoplaces.py @@ -176,6 +176,7 @@ class GeoPlaces(GeoGraphyView): ('geography.map_service', constants.OPENSTREETMAP), ('geography.max_places', 5000), ('geography.use-keypad', True), + ('geography.personal-map', ""), # specific to geoplaces :