[shotwell] Set custom map source



commit 553ac248e8c61f58b92dcba6ddba3913d3879e0c
Author: Jens Georg <mail jensge org>
Date:   Thu May 3 22:37:55 2018 +0200

    Set custom map source

 meson.build        |  2 +-
 src/MapWidget.vala | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/meson.build b/meson.build
index 23ea2a0b..37ffcf08 100644
--- a/meson.build
+++ b/meson.build
@@ -53,7 +53,7 @@ gexiv2 = dependency('gexiv2', version: '>= 0.11.0')
 libraw = dependency('libraw', version : '>= 0.13.2')
 libexif = dependency('libexif', version : '>= 0.6.16')
 unity = dependency('unity', required : false)
-champlain = dependency('champlain-0.12')
+champlain = dependency('champlain-0.12', version: '>= 0.12.16')
 champlain_gtk = dependency('champlain-gtk-0.12')
 clutter = dependency('clutter-1.0')
 clutter_gtk = dependency('clutter-gtk-1.0')
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index 56295404..c4f9bc8e 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -581,9 +581,33 @@ private class MapWidget : Gtk.Bin {
         marker_group_raster.regroup();
     }
 
+    private Champlain.MapSource create_map_source() {
+        var map_source = new Champlain.MapSourceChain();
+        var file_cache = new Champlain.FileCache.full(10 * 1024 * 1024,
+            AppDirs.get_cache_dir().get_child("tiles").get_path(), new Champlain.ImageRenderer());
+        var memory_cache = new Champlain.MemoryCache.full(10 * 1024 * 1024, new Champlain.ImageRenderer());
+        var error_source = new Champlain.NullTileSource.full(new Champlain.ImageRenderer());
+        var osm = Champlain.MapSourceFactory.dup_default().create(Champlain.MAP_SOURCE_OSM_MAPNIK);
+        var user_agent = "Shotwell/%s libchamplain/%s".printf(_VERSION, Champlain.VERSION_S);
+        if (osm is Champlain.NetworkTileSource) {
+            (osm as Champlain.NetworkTileSource).set_user_agent(user_agent);
+            (osm as Champlain.NetworkTileSource).max_conns = 2;
+        } else if (osm is Champlain.NetworkBboxTileSource) {
+            (osm as Champlain.NetworkBboxTileSource).set_user_agent(user_agent);
+        }
+
+        map_source.push(error_source);
+        map_source.push(osm);
+        map_source.push(file_cache);
+        map_source.push(memory_cache);
+
+        return map_source;
+    }
+
     private void setup_map() {
         map_view = gtk_champlain_widget.get_view();
         map_view.add_layer(marker_layer);
+        map_view.set_map_source(create_map_source());
 
         // add lock/unlock button to top left corner of map
         map_edit_lock_button.content_gravity = Clutter.ContentGravity.TOP_RIGHT;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]