[libchamplain] Add signal 'reload-tiles' to ChamplainMapSource, if emitted all visible tiles are reloaded by Champl
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libchamplain] Add signal 'reload-tiles' to ChamplainMapSource, if emitted all visible tiles are reloaded by Champl
- Date: Sun, 24 Jan 2010 20:08:14 +0000 (UTC)
commit 6ed9a40fa0356c54b3e459916583bf6554398359
Author: Simon Wenner <simon wenner ch>
Date: Fri Jun 26 17:13:50 2009 +0200
Add signal 'reload-tiles' to ChamplainMapSource, if emitted all visible tiles are reloaded by ChamplainView
champlain/champlain-map-source.c | 18 ++++++++-
champlain/champlain-memphis-map-source.c | 3 +
champlain/champlain-view.c | 64 ++++++++++++++++++++++++++++++
3 files changed, 84 insertions(+), 1 deletions(-)
---
diff --git a/champlain/champlain-map-source.c b/champlain/champlain-map-source.c
index e2cb51e..d4de9e5 100644
--- a/champlain/champlain-map-source.c
+++ b/champlain/champlain-map-source.c
@@ -54,6 +54,7 @@ void champlain_map_source_real_fill_tile (ChamplainMapSource *map_source,
enum
{
/* normal signals */
+ RELOAD_TILES,
LAST_SIGNAL
};
@@ -70,7 +71,7 @@ enum
PROP_MAP_PROJECTION,
};
-/* static guint champlain_map_source_signals[LAST_SIGNAL] = { 0, }; */
+static guint champlain_map_source_signals[LAST_SIGNAL] = { 0, };
G_DEFINE_TYPE (ChamplainMapSource, champlain_map_source, G_TYPE_INITIALLY_UNOWNED);
@@ -321,6 +322,21 @@ champlain_map_source_class_init (ChamplainMapSourceClass *klass)
CHAMPLAIN_MAP_PROJECTION_MERCATOR,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
g_object_class_install_property (object_class, PROP_MAP_PROJECTION, pspec);
+
+ /**
+ * ChamplainMapSource::reload-tiles:
+ * @map_source: the #ChamplainMapSource that received the signal
+ *
+ * The ::reload-tiles signal is emitted when the map source changed
+ * its style or data
+ *
+ * Since: 0.6
+ */
+ champlain_map_source_signals[RELOAD_TILES] =
+ g_signal_new ("reload-tiles", G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE,
+ 0, NULL);
}
static void
diff --git a/champlain/champlain-memphis-map-source.c b/champlain/champlain-memphis-map-source.c
index 139d2b6..8a0bfd3 100644
--- a/champlain/champlain-memphis-map-source.c
+++ b/champlain/champlain-memphis-map-source.c
@@ -343,6 +343,9 @@ champlain_memphis_map_source_load_rules (
else
memphis_rule_set_load_from_file (priv->rules, DEFAULT_RULES_PATH);
g_static_rw_lock_writer_unlock (&MemphisLock);
+
+ g_signal_emit_by_name (CHAMPLAIN_MAP_SOURCE (self),
+ "reload-tiles", NULL);
}
void
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 91e0f9f..df59212 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -215,6 +215,8 @@ static void license_set_position (ChamplainView *view);
static void view_load_visible_tiles (ChamplainView *view);
static void view_position_tile (ChamplainView* view, ChamplainTile* tile);
static void view_tiles_reposition (ChamplainView* view);
+static void view_reload_tiles_cb (ChamplainMapSource *map_source,
+ ChamplainView* view);
static void view_update_state (ChamplainView *view);
static void view_update_anchor (ChamplainView *view, gint x, gint y);
static gboolean view_set_zoom_level_at (ChamplainView *view,
@@ -1382,6 +1384,9 @@ champlain_view_init (ChamplainView *view)
priv->state = CHAMPLAIN_STATE_DONE;
g_object_notify (G_OBJECT (view), "state");
+
+ g_signal_connect (priv->map_source, "reload-tiles",
+ G_CALLBACK (view_reload_tiles_cb), view);
}
static void
@@ -2352,6 +2357,62 @@ view_tiles_reposition (ChamplainView* view)
}
static void
+view_reload_tiles_cb (ChamplainMapSource *map_source,
+ ChamplainView* view)
+{
+ ChamplainViewPrivate *priv = view->priv;
+ ChamplainRectangle viewport = priv->viewport_size;
+ gint size;
+ ChamplainZoomLevel *level;
+
+ viewport.x += priv->anchor.x;
+ viewport.y += priv->anchor.y;
+
+ size = champlain_map_source_get_tile_size (priv->map_source);
+ level = priv->map->current_level;
+
+ if (viewport.x < 0)
+ viewport.x = 0;
+ if (viewport.y < 0)
+ viewport.y = 0;
+
+ gint x_count = ceil((float)viewport.width / size) + 1;
+ gint y_count = ceil((float)viewport.height / size) + 1;
+
+ gint x_first = viewport.x / size;
+ gint y_first = viewport.y / size;
+
+ x_count += x_first;
+ y_count += y_first;
+
+ if(x_count > champlain_zoom_level_get_width (level))
+ x_count = champlain_zoom_level_get_width (level);
+ if(y_count > champlain_zoom_level_get_height (level))
+ y_count = champlain_zoom_level_get_height (level);
+
+ gint i;
+ gint tile_count = champlain_zoom_level_tile_count (priv->map->current_level);
+
+ for (i = 0; i < tile_count; i++)
+ {
+ ChamplainTile *tile = champlain_zoom_level_get_nth_tile (priv->map->current_level, i);
+
+ if (tile == NULL)
+ continue;
+
+ gint tile_x = champlain_tile_get_x (tile);
+ gint tile_y = champlain_tile_get_y (tile);
+
+ if (tile_x < x_first || tile_x > x_count ||
+ tile_y < y_first || tile_y > y_count)
+ continue;
+
+ if (champlain_tile_get_state (tile) == CHAMPLAIN_STATE_DONE)
+ champlain_map_source_fill_tile (priv->map_source, tile);
+ }
+}
+
+static void
tile_state_notify (GObject *gobject,
GParamSpec *pspec,
gpointer data)
@@ -2449,6 +2510,9 @@ champlain_view_set_map_source (ChamplainView *view,
g_idle_add (marker_reposition, view);
view_tiles_reposition (view);
champlain_view_center_on (view, priv->latitude, priv->longitude);
+
+ g_signal_connect (priv->map_source, "reload-tiles",
+ G_CALLBACK (view_reload_tiles_cb), view);
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]