[shotwell] map: update marker locations when media position changed



commit 039449397070fb1350d2ea6f0b608f84a6ea31eb
Author: Andreas Brauchli <a brauchli elementarea net>
Date:   Sat Jul 2 16:45:26 2016 +0200

    map: update marker locations when media position changed
    
    - Update the cached markers with new position
    - Regroup markers

 src/MapWidget.vala | 38 ++++++++++++++++++++++++++++++++------
 1 file changed, 32 insertions(+), 6 deletions(-)
---
diff --git a/src/MapWidget.vala b/src/MapWidget.vala
index 899c9475..825674b5 100644
--- a/src/MapWidget.vala
+++ b/src/MapWidget.vala
@@ -227,7 +227,7 @@ private class MarkerGroupRaster : Object {
             MARKER_GROUP_RASTER_HEIGHT_PX + (MARKER_GROUP_RASTER_HEIGHT_PX / 2);
     }
 
-    private void regroup() {
+    internal void regroup() {
         lock (position_markers) {
             var position_markers_current = (owned) position_markers;
             position_markers = new Gee.HashSet<PositionMarker>();
@@ -457,6 +457,30 @@ private class MapWidget : Gtk.Bin {
         }
     }
 
+    public void media_source_position_changed(Gee.List<MediaSource> media, GpsCoords gps_coords) {
+        if (page == null)
+            return;
+        var view_collection = page.get_view();
+        foreach (var source in media) {
+            var view = view_collection.get_view_for_source(source);
+            if (view == null)
+                continue;
+            var marker = data_view_marker_cache.get(view);
+            if (marker != null) {
+                if (gps_coords.has_gps > 0) {
+                    // update individual marker cache
+                    marker.champlain_marker.set_location(gps_coords.latitude, gps_coords.longitude);
+                } else {
+                    // TODO: position removal not supported by GUI
+                    // remove marker from cache, map_layer
+                    // remove from marker_group_raster (needs a removal method which also removes the
+                    // item from the group if (marker_group_raster.find_position_marker(view) is MarkerGroup)
+                }
+            }
+        }
+        marker_group_raster.regroup();
+    }
+
     private void setup_map() {
         map_view = gtk_champlain_widget.get_view();
         map_view.add_layer(marker_layer);
@@ -605,19 +629,21 @@ private class MapWidget : Gtk.Bin {
     private bool internal_drop_received(Gee.List<MediaSource> media, double lat, double lon) {
         if (map_edit_lock)
             return false;
+
         bool success = false;
+        GpsCoords gps_coords = GpsCoords() {
+            has_gps = 1,
+            latitude = lat,
+            longitude = lon
+        };
         foreach (var m in media) {
             Positionable p = m as Positionable;
             if (p != null) {
-                GpsCoords gps_coords = GpsCoords() {
-                    has_gps = 1,
-                    latitude = lat,
-                    longitude = lon
-                };
                 p.set_gps_coords(gps_coords);
                 success = true;
             }
         }
+        media_source_position_changed(media, gps_coords);
         return success;
     }
 }


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