From 6d5c6210baea0a5f8238f7da97507b39fe7a14b1 Mon Sep 17 00:00:00 2001 From: Pierre-Luc Beaudoin Date: Sat, 23 Aug 2008 18:52:22 -0400 Subject: [PATCH] Add new map sources --- champlain/Makefile.am | 9 +- champlain/champlainview.h | 7 +- champlain/map.c | 40 +++++-- champlain/map.h | 4 +- champlain/sources/google_map.c | 107 ++++++++++++++++++ champlain/sources/google_map.h | 27 +++++ champlain/sources/google_sat.c | 107 ++++++++++++++++++ champlain/sources/google_sat.h | 27 +++++ champlain/sources/google_terrain.c | 107 ++++++++++++++++++ champlain/sources/google_terrain.h | 27 +++++ champlain/sources/mff_relief.c | 105 +++++++++++++++++ champlain/sources/mff_relief.h | 27 +++++ champlain/sources/oam.c | 102 +++++++++++++++++ champlain/sources/{openstreetmap.h => oam.h} | 6 +- .../sources/{openstreetmap.c => osm_mapnik.c} | 54 ++++----- champlain/sources/osm_mapnik.h | 27 +++++ champlain/tile.c | 10 +- 17 files changed, 746 insertions(+), 47 deletions(-) create mode 100644 champlain/sources/google_map.c create mode 100644 champlain/sources/google_map.h create mode 100644 champlain/sources/google_sat.c create mode 100644 champlain/sources/google_sat.h create mode 100644 champlain/sources/google_terrain.c create mode 100644 champlain/sources/google_terrain.h create mode 100644 champlain/sources/mff_relief.c create mode 100644 champlain/sources/mff_relief.h create mode 100644 champlain/sources/oam.c rename champlain/sources/{openstreetmap.h => oam.h} (92%) rename champlain/sources/{openstreetmap.c => osm_mapnik.c} (55%) create mode 100644 champlain/sources/osm_mapnik.h diff --git a/champlain/Makefile.am b/champlain/Makefile.am index ee18e57..a0c3cca 100644 --- a/champlain/Makefile.am +++ b/champlain/Makefile.am @@ -16,8 +16,13 @@ libchamplain_1_0_la_SOURCES = $(CHAMPLAIN_MARSHAL_LIST) \ map.c \ zoomlevel.c \ tile.c \ - sources/openstreetmap.c \ - sources/debugmap.c + sources/oam.c \ + sources/osm_mapnik.c \ + sources/mff_relief.c \ + sources/google_map.c \ + sources/google_sat.c \ + sources/google_terrain.c \ + sources/debugmap.c libchamplain_1_0_la_LIBADD = $(DEPS_LIBS) ../tidy/libtidy-1.0.la diff --git a/champlain/champlainview.h b/champlain/champlainview.h index 3ddebb5..1680d2a 100644 --- a/champlain/champlainview.h +++ b/champlain/champlainview.h @@ -29,7 +29,12 @@ typedef enum { CHAMPLAIN_MAP_SOURCE_DEBUG, CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP, - CHAMPLAIN_MAP_SOURCE_GOOGLE + CHAMPLAIN_MAP_SOURCE_OPENARIALMAP, + //CHAMPLAIN_MAP_SOURCE_GOOGLE_MAP, + //CHAMPLAIN_MAP_SOURCE_GOOGLE_TERRAIN, + //CHAMPLAIN_MAP_SOURCE_GOOGLE_SATELITE + CHAMPLAIN_MAP_SOURCE_MAPSFORFREE_RELIEF, + CHAMPLAIN_MAP_SOURCE_COUNT } ChamplainMapSource; #define CHAMPLAIN_TYPE_VIEW (champlain_view_get_type()) diff --git a/champlain/map.c b/champlain/map.c index a997745..e273412 100644 --- a/champlain/map.c +++ b/champlain/map.c @@ -19,6 +19,11 @@ #include "map.h" #include "zoomlevel.h" +#include "sources/osm_mapnik.h" +#include "sources/mff_relief.h" +#include "sources/google_sat.h" +#include "sources/google_map.h" +#include "sources/google_terrain.h" #include Map* @@ -32,7 +37,13 @@ map_new (ChamplainMapSource source) debugmap_init(map); break; case CHAMPLAIN_MAP_SOURCE_OPENSTREETMAP: - osm_init(map); + osm_mapnik_init(map); + break; + case CHAMPLAIN_MAP_SOURCE_OPENARIALMAP: + oam_init(map); + break; + case CHAMPLAIN_MAP_SOURCE_MAPSFORFREE_RELIEF: + mff_relief_init(map); break; } @@ -93,10 +104,26 @@ map_load_visible_tiles (Map* map, GdkRectangle viewport) gboolean map_zoom_in (Map* map) { - if(map->current_level->level + 1 <= map->zoom_levels && - map->current_level->level + 1 <= 7) //FIXME Due to a ClutterUnit limitation (the x, y will have to be rethinked) + gint new_level = map->current_level->level + 1; + if(new_level + 1 <= map->zoom_levels && + new_level + 1 <= 8) //FIXME Due to a ClutterUnit limitation (the x, y will have to be rethinked) { - map_load_level(map, map->current_level->level + 1); + gboolean exist = FALSE; + int i; + for (i = 0; i < map->levels->len && !exist; i++) + { + ZoomLevel* level = g_ptr_array_index(map->levels, i); + if (level && level->level == new_level) + { + exist = TRUE; + map->current_level = level; + } + } + + if(!exist) + { + map_load_level(map, map->current_level->level + 1); + } return TRUE; } return FALSE; @@ -110,14 +137,13 @@ map_zoom_out (Map* map) { gboolean exist = FALSE; int i; - for (i = 0; i < map->current_level->tiles->len && !exist; i++) + for (i = 0; i < map->levels->len && !exist; i++) { ZoomLevel* level = g_ptr_array_index(map->levels, i); - if ( level->level == new_level) + if (level && level->level == new_level) { exist = TRUE; map->current_level = level; - g_print("Found!"); } } diff --git a/champlain/map.h b/champlain/map.h index 0cd5148..24fe399 100644 --- a/champlain/map.h +++ b/champlain/map.h @@ -46,8 +46,8 @@ struct _Map gdouble (* x_to_longitude) (Map* map, gint x, guint zoom_level); gdouble (* y_to_latitude) (Map* map, gint y, guint zoom_level); - gchar* (* get_tile_filename) (Tile* tile); - gchar* (* get_tile_uri) (Tile* tile); + gchar* (* get_tile_filename) (Map* map, Tile* tile); + gchar* (* get_tile_uri) (Map* map, Tile* tile); }; diff --git a/champlain/sources/google_map.c b/champlain/sources/google_map.c new file mode 100644 index 0000000..3c79c0a --- /dev/null +++ b/champlain/sources/google_map.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* + * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. + * The current code isn't working because the web server is returning Forbiden error message. + */ + +#include "sources/google_map.h" +#include "map.h" +#include +#include + +guint google_map_row_count(Map* map, guint zoom_level); +guint google_map_column_count(Map* map, guint zoom_level); +Tile* google_map_get_tile (Map* map, guint zoom_level, guint x, guint y); + +gint google_map_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint google_map_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble google_map_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble google_map_y_to_latitude (Map* map, gint y, guint zoom_level); + +gchar* google_map_get_tile_filename(Map* map, Tile* tile); +gchar* google_map_get_tile_uri(Map* map, Tile* tile); + +void +google_map_init(Map* map) +{ + map->name = "Google Map"; + map->zoom_levels = 15; + map->tile_size = 256; + + map->get_row_count = google_map_row_count; + map->get_column_count = google_map_column_count; + + map->longitude_to_x = google_map_longitude_to_x; + map->latitude_to_y = google_map_latitude_to_y; + map->x_to_longitude = google_map_x_to_longitude; + map->y_to_latitude = google_map_y_to_latitude; + + map->get_tile_filename = google_map_get_tile_filename; + map->get_tile_uri = google_map_get_tile_uri; +} + +guint google_map_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint +google_map_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +gint +google_map_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +{ + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gint +google_map_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +{ + return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gdouble +google_map_x_to_longitude (Map* map, gint x, guint zoom_level) +{ + gdouble dx = (float)x / map->tile_size; + return dx / pow(2.0, zoom_level) * 360.0 - 180; +} + +gdouble +google_map_y_to_latitude (Map* map, gint y, guint zoom_level) +{ + gdouble dy = (float)y / map->tile_size; + double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); + return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); +} + +gchar* google_map_get_tile_filename(Map* map, Tile* tile) +{ + return g_build_filename (g_strdup_printf("%d_%d_%d.png", map->zoom_levels + 1 - tile->level, tile->y, tile->x), NULL); +} + +gchar* google_map_get_tile_uri(Map* map, Tile* tile) +{ + return g_strdup_printf("http://mt.google.com/mt?n=404&v=w2.99&x=%d&y=%d&zoom=%d", tile->x, tile->y, map->zoom_levels + 1 - tile->level, NULL); +} diff --git a/champlain/sources/google_map.h b/champlain/sources/google_map.h new file mode 100644 index 0000000..d9bf7c3 --- /dev/null +++ b/champlain/sources/google_map.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GOOGLE_MAP_H +#define GOOGLE_MAP_H + +#include + +void google_map_init(Map* map); + +#endif diff --git a/champlain/sources/google_sat.c b/champlain/sources/google_sat.c new file mode 100644 index 0000000..630f2d8 --- /dev/null +++ b/champlain/sources/google_sat.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* + * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. + * The current code isn't working because the web server is returning Forbiden error message. + */ + +#include "sources/google_sat.h" +#include "map.h" +#include +#include + +guint google_sat_row_count(Map* map, guint zoom_level); +guint google_sat_column_count(Map* map, guint zoom_level); +Tile* google_sat_get_tile (Map* map, guint zoom_level, guint x, guint y); + +gint google_sat_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint google_sat_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble google_sat_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble google_sat_y_to_latitude (Map* map, gint y, guint zoom_level); + +gchar* google_sat_get_tile_filename(Map* map, Tile* tile); +gchar* google_sat_get_tile_uri(Map* map, Tile* tile); + +void +google_sat_init(Map* map) +{ + map->name = "OpenStreetMap"; + map->zoom_levels = 17; + map->tile_size = 256; + + map->get_row_count = google_sat_row_count; + map->get_column_count = google_sat_column_count; + + map->longitude_to_x = google_sat_longitude_to_x; + map->latitude_to_y = google_sat_latitude_to_y; + map->x_to_longitude = google_sat_x_to_longitude; + map->y_to_latitude = google_sat_y_to_latitude; + + map->get_tile_filename = google_sat_get_tile_filename; + map->get_tile_uri = google_sat_get_tile_uri; +} + +guint google_sat_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint +google_sat_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +gint +google_sat_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +{ + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gint +google_sat_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +{ + return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gdouble +google_sat_x_to_longitude (Map* map, gint x, guint zoom_level) +{ + gdouble dx = (float)x / map->tile_size; + return dx / pow(2.0, zoom_level) * 360.0 - 180; +} + +gdouble +google_sat_y_to_latitude (Map* map, gint y, guint zoom_level) +{ + gdouble dy = (float)y / map->tile_size; + double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); + return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); +} + +gchar* google_sat_get_tile_filename(Map* map, Tile* tile) +{ + return g_build_filename (g_strdup_printf("%d_%d_%d.png", map->zoom_levels + 1 - tile->level, tile->y, tile->x), NULL); +} + +gchar* google_sat_get_tile_uri(Map* map, Tile* tile) +{ + return g_strdup_printf("http://mt.google.com/mt?n=404&v=w2.99&x=%d&y=%d&zoom=%d", tile->x, tile->y, map->zoom_levels + 1 - tile->level, NULL); +} diff --git a/champlain/sources/google_sat.h b/champlain/sources/google_sat.h new file mode 100644 index 0000000..bc69231 --- /dev/null +++ b/champlain/sources/google_sat.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GOOGLE_SAT_H +#define GOOGLE_SAT_H + +#include + +void google_sat_init(Map* map); + +#endif diff --git a/champlain/sources/google_terrain.c b/champlain/sources/google_terrain.c new file mode 100644 index 0000000..3bf40f3 --- /dev/null +++ b/champlain/sources/google_terrain.c @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +/* + * WARNING: Using the Google Map Tiles is in viloation of the Terms of Service. + * The current code isn't working because the web server is returning Forbiden error message. + */ + +#include "sources/google_terrain.h" +#include "map.h" +#include +#include + +guint google_terrain_row_count(Map* map, guint zoom_level); +guint google_terrain_column_count(Map* map, guint zoom_level); +Tile* google_terrain_get_tile (Map* map, guint zoom_level, guint x, guint y); + +gint google_terrain_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint google_terrain_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble google_terrain_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble google_terrain_y_to_latitude (Map* map, gint y, guint zoom_level); + +gchar* google_terrain_get_tile_filename(Map* map, Tile* tile); +gchar* google_terrain_get_tile_uri(Map* map, Tile* tile); + +void +google_terrain_init(Map* map) +{ + map->name = "OpenStreetMap"; + map->zoom_levels = 17; + map->tile_size = 256; + + map->get_row_count = google_terrain_row_count; + map->get_column_count = google_terrain_column_count; + + map->longitude_to_x = google_terrain_longitude_to_x; + map->latitude_to_y = google_terrain_latitude_to_y; + map->x_to_longitude = google_terrain_x_to_longitude; + map->y_to_latitude = google_terrain_y_to_latitude; + + map->get_tile_filename = google_terrain_get_tile_filename; + map->get_tile_uri = google_terrain_get_tile_uri; +} + +guint google_terrain_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint +google_terrain_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +gint +google_terrain_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +{ + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gint +google_terrain_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +{ + return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gdouble +google_terrain_x_to_longitude (Map* map, gint x, guint zoom_level) +{ + gdouble dx = (float)x / map->tile_size; + return dx / pow(2.0, zoom_level) * 360.0 - 180; +} + +gdouble +google_terrain_y_to_latitude (Map* map, gint y, guint zoom_level) +{ + gdouble dy = (float)y / map->tile_size; + double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); + return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); +} + +gchar* google_terrain_get_tile_filename(Map* map, Tile* tile) +{ + return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); +} + +gchar* google_terrain_get_tile_uri(Map* map, Tile* tile) +{ + return g_strdup_printf("http://tile.openstreetmap.org/%d/%d/%d.png", tile->level, tile->x, tile->y, NULL); +} diff --git a/champlain/sources/google_terrain.h b/champlain/sources/google_terrain.h new file mode 100644 index 0000000..5061032 --- /dev/null +++ b/champlain/sources/google_terrain.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef GOOGLE_TERRAIN_H +#define GOOGLE_TERRAIN_H + +#include + +void google_terrain_init(Map* map); + +#endif diff --git a/champlain/sources/mff_relief.c b/champlain/sources/mff_relief.c new file mode 100644 index 0000000..c346d86 --- /dev/null +++ b/champlain/sources/mff_relief.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "sources/mff_relief.h" +#include "map.h" +#include +#include + + +//http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#C.2FC.2B.2B + +guint mff_relief_row_count(Map* map, guint zoom_level); +guint mff_relief_column_count(Map* map, guint zoom_level); +Tile* mff_relief_get_tile (Map* map, guint zoom_level, guint x, guint y); + +gint mff_relief_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint mff_relief_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble mff_relief_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble mff_relief_y_to_latitude (Map* map, gint y, guint zoom_level); + +gchar* mff_relief_get_tile_filename(Map* map, Tile* tile); +gchar* mff_relief_get_tile_uri(Map* map, Tile* tile); + +void +mff_relief_init(Map* map) +{ + map->name = "Maps For Free Relief"; + map->zoom_levels = 11; + map->tile_size = 256; + + map->get_row_count = mff_relief_row_count; + map->get_column_count = mff_relief_column_count; + + map->longitude_to_x = mff_relief_longitude_to_x; + map->latitude_to_y = mff_relief_latitude_to_y; + map->x_to_longitude = mff_relief_x_to_longitude; + map->y_to_latitude = mff_relief_y_to_latitude; + + map->get_tile_filename = mff_relief_get_tile_filename; + map->get_tile_uri = mff_relief_get_tile_uri; +} + +guint mff_relief_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint +mff_relief_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +gint +mff_relief_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +{ + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gint +mff_relief_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +{ + return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gdouble +mff_relief_x_to_longitude (Map* map, gint x, guint zoom_level) +{ + gdouble dx = (float)x / map->tile_size; + return dx / pow(2.0, zoom_level) * 360.0 - 180; +} + +gdouble +mff_relief_y_to_latitude (Map* map, gint y, guint zoom_level) +{ + gdouble dy = (float)y / map->tile_size; + double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); + return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); +} + +gchar* mff_relief_get_tile_filename(Map* map, Tile* tile) +{ + return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); +} + +gchar* mff_relief_get_tile_uri(Map* map, Tile* tile) +{ + return g_strdup_printf("http://maps-for-free.com/layer/relief/z%d/row%d/%d_%d-%d.jpg", tile->level, tile->y, tile->level, tile->x, tile->y, NULL); +} diff --git a/champlain/sources/mff_relief.h b/champlain/sources/mff_relief.h new file mode 100644 index 0000000..46ca6eb --- /dev/null +++ b/champlain/sources/mff_relief.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef MFF_RELIEF_H +#define MFF_RELIEF_H + +#include + +void mff_relief_init(Map* map); + +#endif diff --git a/champlain/sources/oam.c b/champlain/sources/oam.c new file mode 100644 index 0000000..3a9d1a4 --- /dev/null +++ b/champlain/sources/oam.c @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "sources/oam.h" +#include "map.h" +#include +#include + +guint oam_row_count(Map* map, guint zoom_level); +guint oam_column_count(Map* map, guint zoom_level); +Tile* oam_get_tile (Map* map, guint zoom_level, guint x, guint y); + +gint oam_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint oam_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble oam_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble oam_y_to_latitude (Map* map, gint y, guint zoom_level); + +gchar* oam_get_tile_filename(Map* map, Tile* tile); +gchar* oam_get_tile_uri(Map* map, Tile* tile); + +void +oam_init(Map* map) +{ + map->name = "OpenArialMap"; + map->zoom_levels = 17; + map->tile_size = 256; + + map->get_row_count = oam_row_count; + map->get_column_count = oam_column_count; + + map->longitude_to_x = oam_longitude_to_x; + map->latitude_to_y = oam_latitude_to_y; + map->x_to_longitude = oam_x_to_longitude; + map->y_to_latitude = oam_y_to_latitude; + + map->get_tile_filename = oam_get_tile_filename; + map->get_tile_uri = oam_get_tile_uri; +} + +guint oam_row_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +guint +oam_column_count(Map* map, guint zoom_level) +{ + return pow (2, zoom_level); +} + +gint +oam_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +{ + return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gint +oam_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +{ + return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; +} + +gdouble +oam_x_to_longitude (Map* map, gint x, guint zoom_level) +{ + gdouble dx = (float)x / map->tile_size; + return dx / pow(2.0, zoom_level) * 360.0 - 180; +} + +gdouble +oam_y_to_latitude (Map* map, gint y, guint zoom_level) +{ + gdouble dy = (float)y / map->tile_size; + double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); + return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); +} + +gchar* oam_get_tile_filename(Map* map, Tile* tile) +{ + return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); +} + +gchar* oam_get_tile_uri(Map* map, Tile* tile) +{ + return g_strdup_printf("http://tile.openaerialmap.org/tiles/1.0.0/openaerialmap-900913/%d/%d/%d.jpg", tile->level, tile->x, tile->y, NULL); +} diff --git a/champlain/sources/openstreetmap.h b/champlain/sources/oam.h similarity index 92% rename from champlain/sources/openstreetmap.h rename to champlain/sources/oam.h index e8c26ba..39fd36d 100644 --- a/champlain/sources/openstreetmap.h +++ b/champlain/sources/oam.h @@ -17,11 +17,11 @@ * Boston, MA 02110-1301, USA. */ -#ifndef OPENSTREETMAP_H -#define OPENSTREETMAP_H +#ifndef OAM_H +#define OAM_H #include -void osm_init(Map* map); +void oam_init(Map* map); #endif diff --git a/champlain/sources/openstreetmap.c b/champlain/sources/osm_mapnik.c similarity index 55% rename from champlain/sources/openstreetmap.c rename to champlain/sources/osm_mapnik.c index 6d0b8dc..d857940 100644 --- a/champlain/sources/openstreetmap.c +++ b/champlain/sources/osm_mapnik.c @@ -17,7 +17,7 @@ * Boston, MA 02110-1301, USA. */ -#include "sources/openstreetmap.h" +#include "sources/osm_mapnik.h" #include "map.h" #include #include @@ -25,81 +25,81 @@ //http://wiki.openstreetmap.org/index.php/Slippy_map_tilenames#C.2FC.2B.2B -guint osm_row_count(Map* map, guint zoom_level); -guint osm_column_count(Map* map, guint zoom_level); -Tile* osm_get_tile (Map* map, guint zoom_level, guint x, guint y); +guint osm_mapnik_row_count(Map* map, guint zoom_level); +guint osm_mapnik_column_count(Map* map, guint zoom_level); +Tile* osm_mapnik_get_tile (Map* map, guint zoom_level, guint x, guint y); -gint osm_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); -gint osm_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); -gdouble osm_x_to_longitude (Map* map, gint x, guint zoom_level); -gdouble osm_y_to_latitude (Map* map, gint y, guint zoom_level); +gint osm_mapnik_longitude_to_x (Map* map, gdouble longitude, guint zoom_level); +gint osm_mapnik_latitude_to_y (Map* map, gdouble latitude, guint zoom_level); +gdouble osm_mapnik_x_to_longitude (Map* map, gint x, guint zoom_level); +gdouble osm_mapnik_y_to_latitude (Map* map, gint y, guint zoom_level); -gchar* osm_get_tile_filename(Tile* tile); -gchar* osm_get_tile_uri(Tile* tile); +gchar* osm_mapnik_get_tile_filename(Map* map, Tile* tile); +gchar* osm_mapnik_get_tile_uri(Map* map, Tile* tile); void -osm_init(Map* map) +osm_mapnik_init(Map* map) { map->name = "OpenStreetMap"; map->zoom_levels = 17; map->tile_size = 256; - map->get_row_count = osm_row_count; - map->get_column_count = osm_column_count; + map->get_row_count = osm_mapnik_row_count; + map->get_column_count = osm_mapnik_column_count; - map->longitude_to_x = osm_longitude_to_x; - map->latitude_to_y = osm_latitude_to_y; - map->x_to_longitude = osm_x_to_longitude; - map->y_to_latitude = osm_y_to_latitude; + map->longitude_to_x = osm_mapnik_longitude_to_x; + map->latitude_to_y = osm_mapnik_latitude_to_y; + map->x_to_longitude = osm_mapnik_x_to_longitude; + map->y_to_latitude = osm_mapnik_y_to_latitude; - map->get_tile_filename = osm_get_tile_filename; - map->get_tile_uri = osm_get_tile_uri; + map->get_tile_filename = osm_mapnik_get_tile_filename; + map->get_tile_uri = osm_mapnik_get_tile_uri; } -guint osm_row_count(Map* map, guint zoom_level) +guint osm_mapnik_row_count(Map* map, guint zoom_level) { return pow (2, zoom_level); } guint -osm_column_count(Map* map, guint zoom_level) +osm_mapnik_column_count(Map* map, guint zoom_level) { return pow (2, zoom_level); } gint -osm_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) +osm_mapnik_longitude_to_x (Map* map, gdouble longitude, guint zoom_level) { return ((longitude + 180.0) / 360.0 * pow(2.0, zoom_level)) * map->tile_size; } gint -osm_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) +osm_mapnik_latitude_to_y (Map* map, gdouble latitude, guint zoom_level) { return ((1.0 - log( tan(latitude * M_PI/180.0) + 1.0 / cos(latitude * M_PI/180.0)) / M_PI) / 2.0 * pow(2.0, zoom_level)) * map->tile_size; } gdouble -osm_x_to_longitude (Map* map, gint x, guint zoom_level) +osm_mapnik_x_to_longitude (Map* map, gint x, guint zoom_level) { gdouble dx = (float)x / map->tile_size; return dx / pow(2.0, zoom_level) * 360.0 - 180; } gdouble -osm_y_to_latitude (Map* map, gint y, guint zoom_level) +osm_mapnik_y_to_latitude (Map* map, gint y, guint zoom_level) { gdouble dy = (float)y / map->tile_size; double n = M_PI - 2.0 * M_PI * dy / pow(2.0, zoom_level); return 180.0 / M_PI * atan(0.5 * (exp(n) - exp(-n))); } -gchar* osm_get_tile_filename(Tile* tile) +gchar* osm_mapnik_get_tile_filename(Map* map, Tile* tile) { return g_build_filename (g_strdup_printf("%d_%d_%d.png", tile->level, tile->y, tile->x), NULL); } -gchar* osm_get_tile_uri(Tile* tile) +gchar* osm_mapnik_get_tile_uri(Map* map, Tile* tile) { return g_strdup_printf("http://tile.openstreetmap.org/%d/%d/%d.png", tile->level, tile->x, tile->y, NULL); } diff --git a/champlain/sources/osm_mapnik.h b/champlain/sources/osm_mapnik.h new file mode 100644 index 0000000..671bd0f --- /dev/null +++ b/champlain/sources/osm_mapnik.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2008 Pierre-Luc Beaudoin + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#ifndef OSM_MAPNIK_H +#define OSM_MAPNIK_H + +#include + +void osm_mapnik_init(Map* map); + +#endif diff --git a/champlain/tile.c b/champlain/tile.c index 34b7e7c..53940d0 100644 --- a/champlain/tile.c +++ b/champlain/tile.c @@ -56,7 +56,7 @@ file_loaded_cb (SoupSession *session, if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) { - g_warning ("Unable to download tile %d, %d", tile->x, tile->y); + g_warning ("Unable to download tile %d, %d: %s", tile->x, tile->y, soup_status_get_phrase(msg->status_code)); return; } @@ -99,7 +99,7 @@ file_loaded_cb (SoupSession *session, } } - map_filename = map->get_tile_filename(tile); + map_filename = map->get_tile_filename(map, tile); filename = g_build_filename (g_get_user_cache_dir (), CACHE_DIR, map->name, @@ -148,7 +148,7 @@ tile_load (Map* map, guint zoom_level, guint x, guint y) ptr->tile = tile; // Try the cached version first - map_filename = map->get_tile_filename(tile); + map_filename = map->get_tile_filename(map, tile); filename = g_build_filename (g_get_user_cache_dir (), CACHE_DIR, map->name, @@ -168,8 +168,8 @@ tile_load (Map* map, guint zoom_level, guint x, guint y) SoupMessage *msg; if (!session) session = soup_session_async_new (); - - msg = soup_message_new (SOUP_METHOD_GET, g_strdup_printf("http://tile.openstreetmap.org/%d/%d/%d.png", zoom_level, x, y)); + + msg = soup_message_new (SOUP_METHOD_GET, map->get_tile_uri(map, tile)); soup_session_queue_message (session, msg, file_loaded_cb, -- 2.39.5