From: Pierre-Luc Beaudoin Date: Thu, 13 Nov 2008 02:28:04 +0000 (-0500) Subject: Fix Bug 558026 – zoom in + center_on != center_on + zoom in X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=928c02a05f382910cbca45a27ed2f7078a1bdd73;p=libchamplain Fix Bug 558026 – zoom in + center_on != center_on + zoom in By introducting keeping the precise (lat, lon) value, I work around the rounding errors --- diff --git a/champlain/champlainview.c b/champlain/champlainview.c index 4ede337..6774bea 100644 --- a/champlain/champlainview.c +++ b/champlain/champlainview.c @@ -65,8 +65,10 @@ struct _ChamplainViewPrivate ChamplainMapSource map_source; gint zoom_level; // only used when the zoom-level property is set before map is created - gdouble longitude; // only used when the center_on is called before map is created - gdouble latitude; // only used when the center_on is called before map is created + + // Represents the (lat, lon) at the center of the viewport + gdouble longitude; + gdouble latitude; ClutterActor *map_layer; ClutterActor *viewport; @@ -364,16 +366,12 @@ champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, { case PROP_LONGITUDE: { - gdouble lon = g_value_get_double(value); - gdouble lat = viewport_get_current_latitude(priv); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on (view, priv->latitude, g_value_get_double (value)); break; } case PROP_LATITUDE: { - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = g_value_get_double(value); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on (view, g_value_get_double (value), priv->longitude); break; } case PROP_ZOOM_LEVEL: @@ -384,14 +382,12 @@ champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, if (level != priv->map->current_level->level) { ClutterActor *group = priv->map->current_level->group; - gdouble lat = viewport_get_current_latitude(priv); - gdouble lon = viewport_get_current_longitude(priv); if (map_zoom_to(priv->map, level)) { resize_viewport(view); clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on(view, priv->latitude, priv->longtitude); } } } @@ -407,8 +403,6 @@ champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, if (priv->map_source != source) { priv->map_source = source; - gdouble lat = viewport_get_current_latitude(priv); - gdouble lon = viewport_get_current_longitude(priv); if (priv->map) { guint currentLevel = priv->map->current_level->level; map_free(priv->map); @@ -427,7 +421,7 @@ champlain_view_set_property(GObject *object, guint prop_id, const GValue *value, clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); marker_reposition(view); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on(view, priv->latitude, priv->longitude); } } break; @@ -621,15 +615,12 @@ champlain_view_set_size (ChamplainView *view, guint width, guint height) ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = viewport_get_current_latitude(priv); - priv->viewport_size.width = width; priv->viewport_size.height = height; resize_viewport(view); if (priv->keep_center_on_resize) - champlain_view_center_on(view, lat, lon); + champlain_view_center_on(view, priv->latitude, priv->longitude); else map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); } @@ -763,13 +754,11 @@ champlain_view_center_on (ChamplainView *view, gdouble latitude, gdouble longitu ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); + priv->longitude = longitude; + priv->latitude = latitude; + if(!priv->map) - { - // keep until the viewport is created - priv->longitude = longitude; - priv->latitude = latitude; - return; - } + return; gdouble x, y; x = priv->map->longitude_to_x(priv->map, longitude, priv->map->current_level->level); @@ -815,7 +804,7 @@ champlain_view_center_on (ChamplainView *view, gdouble latitude, gdouble longitu g_object_notify(G_OBJECT(view), "latitude"); map_load_visible_tiles (priv->map, priv->viewport_size, priv->offline); - marker_reposition(view); + marker_reposition (view); } /** @@ -833,15 +822,13 @@ champlain_view_zoom_in (ChamplainView *view) ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); ClutterActor *group = priv->map->current_level->group; - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = viewport_get_current_latitude(priv); if(map_zoom_in(priv->map)) { resize_viewport(view); clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on(view, priv->latitude, priv->longitude); g_object_notify(G_OBJECT(view), "zoom-level"); } @@ -862,15 +849,13 @@ champlain_view_zoom_out (ChamplainView *view) ChamplainViewPrivate *priv = CHAMPLAIN_VIEW_GET_PRIVATE (view); ClutterActor *group = priv->map->current_level->group; - gdouble lon = viewport_get_current_longitude(priv); - gdouble lat = viewport_get_current_latitude(priv); if(map_zoom_out(priv->map)) { resize_viewport(view); clutter_container_remove_actor (CLUTTER_CONTAINER (priv->map_layer), group); clutter_container_add_actor (CLUTTER_CONTAINER (priv->map_layer), priv->map->current_level->group); - champlain_view_center_on(view, lat, lon); + champlain_view_center_on(view, priv->latitude, priv->longitude); g_object_notify(G_OBJECT(view), "zoom-level"); } diff --git a/demos/launcher.c b/demos/launcher.c index 958c80b..7b00f33 100644 --- a/demos/launcher.c +++ b/demos/launcher.c @@ -23,13 +23,15 @@ static gboolean montreal_click (ClutterActor *actor, ClutterEvent *event, - gpointer user_data) -{ g_print("Montreal was clicked!\n"); - return TRUE; + ChamplainView *view) +{ + g_print("Montreal was clicked!\n"); + champlain_view_center_on(CHAMPLAIN_VIEW(view), 45.466, -73.75); + return TRUE; } static ClutterActor* -create_marker_layer () +create_marker_layer (ChamplainView *view) { ClutterActor *layer, *marker; @@ -44,7 +46,7 @@ create_marker_layer () g_signal_connect_after (marker, "button-release-event", G_CALLBACK (montreal_click), - NULL); + view); marker = champlain_marker_new_with_label("New York", "Sans 25", &white, NULL); champlain_marker_set_position(CHAMPLAIN_MARKER(marker), 40.77, -73.98); @@ -74,7 +76,7 @@ main (int argc, char *argv[]) champlain_view_set_size (CHAMPLAIN_VIEW (actor), 800, 600); g_object_set(G_OBJECT(actor), "zoom-level", 5, NULL); - layer = create_marker_layer(); + layer = create_marker_layer(actor); champlain_view_add_layer(CHAMPLAIN_VIEW (actor), layer); clutter_container_add_actor (CLUTTER_CONTAINER (stage), actor);