[libchamplain] Use bounding box where appropriate
- From: Jiří Techet <jiritechet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libchamplain] Use bounding box where appropriate
- Date: Wed, 9 Feb 2011 08:39:55 +0000 (UTC)
commit 3bd11b193933fcafd445e2938e93bb31fef1b6a7
Author: JiÅ?Ã Techet <techet gmail com>
Date: Thu Feb 3 22:23:56 2011 +0100
Use bounding box where appropriate
champlain/champlain-defines.h | 5 ++
champlain/champlain-marker-layer.c | 48 ++++++++--------
champlain/champlain-marker-layer.h | 5 +-
champlain/champlain-network-bbox-tile-source.c | 20 ++----
champlain/champlain-network-bbox-tile-source.h | 6 +-
champlain/champlain-view.c | 72 +++++------------------
champlain/champlain-view.h | 6 +-
demos/local-rendering.c | 9 ++-
8 files changed, 64 insertions(+), 107 deletions(-)
---
diff --git a/champlain/champlain-defines.h b/champlain/champlain-defines.h
index 56ba8f2..c2e4514 100644
--- a/champlain/champlain-defines.h
+++ b/champlain/champlain-defines.h
@@ -25,6 +25,11 @@
#define CHAMPLAIN_API __attribute__((visibility ("default")))
+#define CHAMPLAIN_MIN_LATITUDE -90
+#define CHAMPLAIN_MAX_LATITUDE 90
+#define CHAMPLAIN_MIN_LONGITUDE -180
+#define CHAMPLAIN_MAX_LONGITUDE 180
+
typedef struct _ChamplainView ChamplainView;
typedef struct _ChamplainViewClass ChamplainViewClass;
diff --git a/champlain/champlain-marker-layer.c b/champlain/champlain-marker-layer.c
index e8e6aa0..33c0b50 100644
--- a/champlain/champlain-marker-layer.c
+++ b/champlain/champlain-marker-layer.c
@@ -972,43 +972,41 @@ set_view (ChamplainLayer *layer,
*
* Since: 0.4
*/
-/*void
-champlain_view_ensure_markers_visible (ChamplainView *view,
- ChamplainMarker *markers[],
- gboolean animate)
+ChamplainBoundingBox *
+champlain_marker_layer_get_bounding_box (ChamplainMarkerLayer *layer)
{
- DEBUG_LOG ()
-
- gdouble min_lat, min_lon, max_lat, max_lon;
- ChamplainMarker *marker = NULL;
gint i = 0;
+ ChamplainBoundingBox *bbox;
+
+ bbox = champlain_bounding_box_new ();
+ bbox->left = CHAMPLAIN_MAX_LONGITUDE;
+ bbox->right = CHAMPLAIN_MIN_LONGITUDE;
+ bbox->bottom = CHAMPLAIN_MAX_LATITUDE;
+ bbox->top = CHAMPLAIN_MIN_LATITUDE;
- min_lat = min_lon = 200;
- max_lat = max_lon = -200;
-
- marker = markers[i];
- while (marker != NULL)
+ for (i = 1; i < clutter_group_get_n_children (CLUTTER_GROUP (layer)); i++)
{
+ ChamplainMarker *marker = CHAMPLAIN_MARKER (clutter_group_get_nth_child (CLUTTER_GROUP (layer), i));
gdouble lat, lon;
+
g_object_get (G_OBJECT (marker), "latitude", &lat, "longitude", &lon,
NULL);
- if (lon < min_lon)
- min_lon = lon;
-
- if (lat < min_lat)
- min_lat = lat;
+ if (lon < bbox->left)
+ bbox->left = lon;
- if (lon > max_lon)
- max_lon = lon;
+ if (lat < bbox->bottom)
+ bbox->bottom = lat;
- if (lat > max_lat)
- max_lat = lat;
+ if (lon > bbox->right)
+ bbox->right = lon;
- marker = markers[i++];
+ if (lat > bbox->top)
+ bbox->top = lat;
}
- champlain_view_ensure_visible (view, min_lat, min_lon, max_lat, max_lon, animate);
-}*/
+
+ return bbox;
+}
/**
diff --git a/champlain/champlain-marker-layer.h b/champlain/champlain-marker-layer.h
index 78940b9..fe8e397 100644
--- a/champlain/champlain-marker-layer.h
+++ b/champlain/champlain-marker-layer.h
@@ -26,6 +26,7 @@
#include <champlain/champlain-defines.h>
#include <champlain/champlain-marker.h>
#include <champlain/champlain-layer.h>
+#include <champlain/champlain-bounding-box.h>
#include <glib-object.h>
#include <clutter/clutter.h>
@@ -107,9 +108,7 @@ void champlain_marker_layer_set_selection_mode (ChamplainMarkerLayer *layer,
ChamplainSelectionMode mode);
ChamplainSelectionMode champlain_marker_layer_get_selection_mode (
ChamplainMarkerLayer *layer);
-//void champlain_view_ensure_markers_visible (ChamplainView *view,
-// ChamplainMarker *markers[],
-// gboolean animate);
+ChamplainBoundingBox *champlain_marker_layer_get_bounding_box (ChamplainMarkerLayer *layer);
ClutterColor *champlain_marker_layer_get_path_fill_color (ChamplainMarkerLayer *layer);
void champlain_marker_layer_set_path_fill_color (ChamplainMarkerLayer *layer,
diff --git a/champlain/champlain-network-bbox-tile-source.c b/champlain/champlain-network-bbox-tile-source.c
index f5168c9..dc458c4 100644
--- a/champlain/champlain-network-bbox-tile-source.c
+++ b/champlain/champlain-network-bbox-tile-source.c
@@ -327,11 +327,8 @@ load_map_data_cb (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg,
/**
* champlain_network_bbox_tile_source_load_map_data:
* @map_data_source: a #ChamplainNetworkBboxTileSource
- * @bound_left: the left bound in degree
- * @bound_bottom: the lower bound in degree
- * @bound_right: the right bound in degree
- * @bound_top: the upper bound in degree
- *
+ * @bbox: bounding box of the requested area
+ *
* Asynchronously loads map data within a bounding box from the server.
* The box must not exceed an edge size of 0.25 degree. There are also
* limitations on the maximum number of nodes that can be requested.
@@ -340,20 +337,17 @@ load_map_data_cb (G_GNUC_UNUSED SoupSession *session, SoupMessage *msg,
* url="http://api.openstreetmap.org/api/capabilities">
* http://api.openstreetmap.org/api/capabilities</ulink>
*
- * Since: 0.8
+ * Since: 0.10
*/
void
champlain_network_bbox_tile_source_load_map_data (
ChamplainNetworkBboxTileSource *self,
- gdouble bound_left,
- gdouble bound_bottom,
- gdouble bound_right,
- gdouble bound_top)
+ ChamplainBoundingBox *bbox)
{
g_return_if_fail (CHAMPLAIN_IS_NETWORK_BBOX_TILE_SOURCE (self));
- g_return_if_fail (bound_right - bound_left < 0.25 &&
- bound_top - bound_bottom < 0.25);
+ g_return_if_fail (bbox->right - bbox->left < 0.25 &&
+ bbox->top - bbox->bottom < 0.25);
ChamplainNetworkBboxTileSourcePrivate *priv = self->priv;
SoupMessage *msg;
@@ -361,7 +355,7 @@ champlain_network_bbox_tile_source_load_map_data (
url = g_strdup_printf (
"http://api.openstreetmap.org/api/0.6/map?bbox=%f,%f,%f,%f",
- bound_left, bound_bottom, bound_right, bound_top);
+ bbox->left, bbox->bottom, bbox->right, bbox->top);
msg = soup_message_new ("GET", url);
DEBUG ("Request BBox data: '%s'", url);
diff --git a/champlain/champlain-network-bbox-tile-source.h b/champlain/champlain-network-bbox-tile-source.h
index c026d6b..de8f971 100644
--- a/champlain/champlain-network-bbox-tile-source.h
+++ b/champlain/champlain-network-bbox-tile-source.h
@@ -23,6 +23,7 @@
#include <glib-object.h>
#include <champlain/champlain-tile-source.h>
+#include <champlain/champlain-bounding-box.h>
G_BEGIN_DECLS
@@ -74,10 +75,7 @@ ChamplainNetworkBboxTileSource *champlain_network_bbox_tile_source_new_full (con
void champlain_network_bbox_tile_source_load_map_data (
ChamplainNetworkBboxTileSource *map_data_source,
- gdouble bound_left,
- gdouble bound_bottom,
- gdouble bound_right,
- gdouble bound_top);
+ ChamplainBoundingBox *bbox);
const gchar *champlain_network_bbox_tile_source_get_api_uri (
ChamplainNetworkBboxTileSource *map_data_source);
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index 484dccf..e171f76 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -113,11 +113,6 @@ static guint signals[LAST_SIGNAL] = { 0, };
level < champlain_map_source_get_min_zoom_level (priv->map_source) || \
level > champlain_map_source_get_max_zoom_level (priv->map_source))
-#define CHAMPLAIN_MIN_LAT -90
-#define CHAMPLAIN_MAX_LAT 90
-#define CHAMPLAIN_MIN_LONG -180
-#define CHAMPLAIN_MAX_LONG 180
-
/* Between state values for go_to */
typedef struct
{
@@ -378,12 +373,12 @@ champlain_view_get_property (GObject *object,
{
case PROP_LONGITUDE:
g_value_set_double (value,
- CLAMP (priv->longitude, CHAMPLAIN_MIN_LONG, CHAMPLAIN_MAX_LONG));
+ CLAMP (priv->longitude, CHAMPLAIN_MIN_LONGITUDE, CHAMPLAIN_MAX_LONGITUDE));
break;
case PROP_LATITUDE:
g_value_set_double (value,
- CLAMP (priv->latitude, CHAMPLAIN_MIN_LAT, CHAMPLAIN_MAX_LAT));
+ CLAMP (priv->latitude, CHAMPLAIN_MIN_LATITUDE, CHAMPLAIN_MAX_LATITUDE));
break;
case PROP_ZOOM_LEVEL:
@@ -1300,8 +1295,8 @@ champlain_view_center_on (ChamplainView *view,
gint x, y;
ChamplainViewPrivate *priv = view->priv;
- priv->longitude = CLAMP (longitude, CHAMPLAIN_MIN_LONG, CHAMPLAIN_MAX_LONG);
- priv->latitude = CLAMP (latitude, CHAMPLAIN_MIN_LAT, CHAMPLAIN_MAX_LAT);
+ priv->longitude = CLAMP (longitude, CHAMPLAIN_MIN_LONGITUDE, CHAMPLAIN_MAX_LONGITUDE);
+ priv->latitude = CLAMP (latitude, CHAMPLAIN_MIN_LATITUDE, CHAMPLAIN_MAX_LATITUDE);
x = champlain_map_source_get_x (priv->map_source, priv->zoom_level, longitude);
y = champlain_map_source_get_y (priv->map_source, priv->zoom_level, latitude);
@@ -2120,10 +2115,6 @@ champlain_view_set_zoom_on_double_click (ChamplainView *view,
/**
* champlain_view_ensure_visible:
* @view: a #ChamplainView
- * @lat1: the latitude of position 1
- * @lon1: the longitude of position 1
- * @lat2: the latitude of position 2
- * @lon2: the longitude of position 2
* @animate: a #gboolean
*
* Changes the map's zoom level and center to make sure the two given
@@ -2133,57 +2124,27 @@ champlain_view_set_zoom_on_double_click (ChamplainView *view,
*/
void
champlain_view_ensure_visible (ChamplainView *view,
- gdouble lat1,
- gdouble lon1,
- gdouble lat2,
- gdouble lon2,
+ ChamplainBoundingBox *bbox,
gboolean animate)
{
DEBUG_LOG ()
ChamplainViewPrivate *priv = view->priv;
guint zoom_level = priv->zoom_level;
- gdouble width, height;
- gdouble min_lat, min_lon, max_lat, max_lon;
gboolean good_size = FALSE;
+ gdouble lat, lon;
- /*We first sort the lat,lon in order to have min and max */
- if (lat1 < lat2)
- {
- min_lat = lat1;
- max_lat = lat2;
- }
- else
- {
- max_lat = lat1;
- min_lat = lat2;
- }
-
- if (lon1 < lon2)
- {
- min_lon = lon1;
- max_lon = lon2;
- }
- else
- {
- max_lon = lon1;
- min_lon = lon2;
- }
-
- width = max_lon - min_lon;
- height = max_lat - min_lat;
- width *= 1.1;
- height *= 1.1;
+ champlain_bounding_box_get_center (bbox, &lat, &lon);
- DEBUG ("Zone to expose (%f, %f) to (%f, %f)", min_lat, min_lon, max_lat, max_lon);
+ DEBUG ("Zone to expose (%f, %f) to (%f, %f)", bbox->bottom, bbox->left, bbox->top, bbox->right);
do
{
gint min_x, min_y, max_x, max_y;
- min_x = champlain_map_source_get_x (priv->map_source, zoom_level, min_lon);
- min_y = champlain_map_source_get_y (priv->map_source, zoom_level, min_lat);
-
- max_x = champlain_map_source_get_x (priv->map_source, zoom_level, max_lon);
- max_y = champlain_map_source_get_y (priv->map_source, zoom_level, max_lat);
+
+ min_x = champlain_map_source_get_x (priv->map_source, zoom_level, bbox->left);
+ min_y = champlain_map_source_get_y (priv->map_source, zoom_level, bbox->bottom);
+ max_x = champlain_map_source_get_x (priv->map_source, zoom_level, bbox->right);
+ max_y = champlain_map_source_get_y (priv->map_source, zoom_level, bbox->top);
if (min_y - max_y <= priv->viewport_height &&
max_x - min_x <= priv->viewport_width)
@@ -2194,17 +2155,16 @@ champlain_view_ensure_visible (ChamplainView *view,
if (zoom_level <= priv->min_zoom_level)
{
zoom_level = priv->min_zoom_level;
- min_lat = min_lon = width = height = 0;
- break;
+ good_size = TRUE;
}
} while (!good_size);
DEBUG ("Ideal zoom level is %d", zoom_level);
champlain_view_set_zoom_level (view, zoom_level);
if (animate)
- champlain_view_go_to (view, min_lat + height / 2.0, min_lon + width / 2.0);
+ champlain_view_go_to (view, lat, lon);
else
- champlain_view_center_on (view, min_lat + height / 2.0, min_lon + width / 2.0);
+ champlain_view_center_on (view, lat, lon);
}
diff --git a/champlain/champlain-view.h b/champlain/champlain-view.h
index 953caae..9de0e12 100644
--- a/champlain/champlain-view.h
+++ b/champlain/champlain-view.h
@@ -28,6 +28,7 @@
#include <champlain/champlain-layer.h>
#include <champlain/champlain-map-source.h>
#include <champlain/champlain-license.h>
+#include <champlain/champlain-bounding-box.h>
#include <glib.h>
#include <glib-object.h>
@@ -102,10 +103,7 @@ void champlain_view_set_max_zoom_level (ChamplainView *view,
guint zoom_level);
void champlain_view_ensure_visible (ChamplainView *view,
- gdouble lat1,
- gdouble lon1,
- gdouble lat2,
- gdouble lon2,
+ ChamplainBoundingBox *bbox,
gboolean animate);
void champlain_view_set_map_source (ChamplainView *view,
diff --git a/demos/local-rendering.c b/demos/local-rendering.c
index 43ad2ad..7e8e00f 100644
--- a/demos/local-rendering.c
+++ b/demos/local-rendering.c
@@ -119,14 +119,19 @@ static void
load_network_map_data (ChamplainNetworkBboxTileSource *source, ChamplainView *view)
{
gdouble lat, lon;
+ ChamplainBoundingBox *bbox = champlain_bounding_box_new ();
g_signal_connect (source, "notify::state", G_CALLBACK (data_source_state_changed),
map_data_state_img);
g_object_get (G_OBJECT (view), "latitude", &lat, "longitude", &lon, NULL);
- champlain_network_bbox_tile_source_load_map_data (source,
- lon - 0.008, lat - 0.008, lon + 0.008, lat + 0.008);
+ bbox->left = lon - 0.008;
+ bbox->right = lon + 0.008;
+ bbox->bottom = lat - 0.008;
+ bbox->top = lat + 0.008;
+ champlain_network_bbox_tile_source_load_map_data (source, bbox);
+ champlain_bounding_box_free (bbox);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]