[libchamplain/libchamplain-0-4] Move distance computation in MapSource
- From: Pierre-Luc Beaudoin <plbeaudoin src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libchamplain/libchamplain-0-4] Move distance computation in MapSource
- Date: Tue, 5 Jan 2010 19:01:35 +0000 (UTC)
commit 10078a898a9e1a2ece6f09f76950f46f73636c30
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date: Tue Dec 15 10:15:29 2009 -0500
Move distance computation in MapSource
with other projection specific calculations
champlain/champlain-map-source.c | 32 ++++++++++++++++++++++++++++++++
champlain/champlain-map-source.h | 5 +++++
champlain/champlain-view.c | 23 ++++++-----------------
3 files changed, 43 insertions(+), 17 deletions(-)
---
diff --git a/champlain/champlain-map-source.c b/champlain/champlain-map-source.c
index 47a28cc..c90f43e 100644
--- a/champlain/champlain-map-source.c
+++ b/champlain/champlain-map-source.c
@@ -730,3 +730,35 @@ champlain_map_source_set_id (ChamplainMapSource *map_source,
g_object_notify (G_OBJECT (map_source), "id");
}
+#define EARTH_RADIUS 6378137 /* meters, Equatorial radius */
+
+/**
+ * champlain_map_source_get_meters_per_pixel:
+ * @map_source: a #ChamplainMapSource
+ * @zoom_level: the zoom level
+ * @latitude: a latitude
+ * @longitude: a longitude
+ *
+ * Returns: the meters per pixel at the position on the map using this map source's projection.
+ *
+ * Since: 0.4.3
+ */
+gfloat
+champlain_map_source_get_meters_per_pixel (ChamplainMapSource *map_source,
+ gint zoom_level,
+ gdouble latitude,
+ gdouble longitude)
+{
+ g_return_val_if_fail (CHAMPLAIN_IS_MAP_SOURCE (map_source), 0);
+
+ /* Width is in pixels. (1 px)
+ m/px = radius_at_latitude / width_in_pixels
+ k = radius of earth = 6 378.1 km
+ radius_at_latitude = 2Ï? * k * sin (Ï?/2-θ)
+ */
+
+ ChamplainMapSourcePrivate *priv = map_source->priv;
+ // FIXME: support other projections
+ return 2 * M_PI * EARTH_RADIUS * sin (M_PI/2 - M_PI / 180 * latitude) /
+ (priv->tile_size * champlain_map_source_get_row_count (map_source, zoom_level));
+}
diff --git a/champlain/champlain-map-source.h b/champlain/champlain-map-source.h
index 3845926..d2c9732 100644
--- a/champlain/champlain-map-source.h
+++ b/champlain/champlain-map-source.h
@@ -114,6 +114,11 @@ void champlain_map_source_set_projection (ChamplainMapSource *map_source,
ChamplainMapProjection projection);
ChamplainMapProjection champlain_map_source_get_projection (ChamplainMapSource *map_source);
+gfloat champlain_map_source_get_meters_per_pixel (ChamplainMapSource *map_source,
+ gint zoom_level,
+ gdouble latitude,
+ gdouble longitude);
+
G_END_DECLS
#endif
diff --git a/champlain/champlain-view.c b/champlain/champlain-view.c
index ca39f0a..4e9cc89 100644
--- a/champlain/champlain-view.c
+++ b/champlain/champlain-view.c
@@ -1004,37 +1004,26 @@ update_scale (ChamplainView *view)
{
ClutterActor *text;
ChamplainViewPrivate *priv = view->priv;
- ChamplainZoomLevel *level;
gfloat m_per_pixel;
+ gfloat width = SCALE_WIDTH;
gchar *label;
- ChamplainTile *tile;
-
- /* Width is in pixels.
- m/px = radius_at_latitude / width_in_pixels
- k = radius of earth = 6 378.1 km
- radius_at_latitude = 2Ï? * k * sin (Ï?/2-θ)
-
- */
if (! priv || !priv->map || !priv->map->current_level)
return;
if (priv->show_scale)
{
- clutter_actor_show(priv->scale_actor);
+ clutter_actor_show (priv->scale_actor);
}
else
{
- clutter_actor_hide(priv->scale_actor);
+ clutter_actor_hide (priv->scale_actor);
return;
}
- level = priv->map->current_level;
- tile = champlain_zoom_level_get_nth_tile(level, 0);
- m_per_pixel = 2 * M_PI * 6378100 * sin(M_PI/2 - M_PI / 180*priv->latitude) /
- (champlain_tile_get_size (tile) * champlain_zoom_level_get_width (level));
-
- label = g_strdup_printf("%.2f km", (m_per_pixel * SCALE_WIDTH) / 1000);
+ m_per_pixel = champlain_map_source_get_meters_per_pixel (priv->map_source,
+ priv->zoom_level, priv->latitude, priv->longitude) * width;
+ label = g_strdup_printf ("%.2f km", m_per_pixel / 1000);
text = clutter_container_find_child_by_name (CLUTTER_CONTAINER (priv->scale_actor), "scale-label");
clutter_text_set_text (CLUTTER_TEXT (text), label);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]