Commit ec803d53 authored by Andreas Brauchli's avatar Andreas Brauchli Committed by Jens Georg

map: Cache position markers while on same page

While on the same page, cache all created DataViewPositionMarkers for
quick retrieval when switching between a selection and no
selection.

The cache is emptied when the page is switched.
parent a1163ffa
......@@ -258,7 +258,9 @@ private class MapWidget : Gtk.Bin {
private Champlain.MarkerLayer marker_layer = new Champlain.MarkerLayer();
public bool map_edit_lock { get; set; }
private MarkerGroupRaster marker_group_raster = null;
private weak Page page = null;
private Gee.Map<DataView, DataViewPositionMarker> data_view_marker_cache =
new Gee.HashMap<DataView, DataViewPositionMarker>();
private weak Page? page = null;
private Clutter.Image? map_edit_locked_image;
private Clutter.Image? map_edit_unlocked_image;
private Clutter.Actor map_edit_lock_button = new Clutter.Actor();
......@@ -305,7 +307,10 @@ private class MapWidget : Gtk.Bin {
}
public void set_page(Page page) {
this.page = page;
if (this.page != page) {
this.page = page;
data_view_marker_cache.clear();
}
}
public void clear() {
......@@ -522,13 +527,17 @@ private class MapWidget : Gtk.Bin {
}
private DataViewPositionMarker create_position_marker(DataView view) {
// TODO: store markers in map to only create them once
var position_marker = data_view_marker_cache.get(view);
if (position_marker != null)
return position_marker;
DataSource data_source = view.get_source();
Positionable p = (Positionable) data_source;
GpsCoords gps_coords = p.get_gps_coords();
Champlain.Marker champlain_marker = create_champlain_marker(gps_coords, marker_image,
marker_selected_image, marker_image_width, marker_image_height);
return new DataViewPositionMarker(this, view, champlain_marker);
position_marker = new DataViewPositionMarker(this, view, champlain_marker);
data_view_marker_cache.set(view, position_marker);
return position_marker;
}
internal MarkerGroup create_marker_group(GpsCoords gps_coords) {
......@@ -555,13 +564,11 @@ private class MapWidget : Gtk.Bin {
}
private bool internal_drop_received(Gee.List<MediaSource> media, double lat, double lon) {
if (map_edit_lock) {
if (map_edit_lock)
return false;
}
int i = 0;
bool success = false;
while (i < media.size) {
Positionable p = media.get(i) as Positionable;
foreach (var m in media) {
Positionable p = m as Positionable;
if (p != null) {
GpsCoords gps_coords = GpsCoords() {
has_gps = 1,
......@@ -571,7 +578,6 @@ private class MapWidget : Gtk.Bin {
p.set_gps_coords(gps_coords);
success = true;
}
++i;
}
return success;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment