2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include <gdk/gdkkeysyms.h>
21 #include "grits-util.h"
22 #include "data/grits-wms.h"
23 #include "data/grits-tms.h"
24 #include "objects/grits-tile.h"
37 void chunk_callback(gsize cur, gsize total, gpointer _state)
39 struct CacheState *state = _state;
40 g_message("chunk_callback: %ld/%ld", (glong)cur, (glong)total);
42 if (state->progress == NULL) {
43 state->progress = gtk_progress_bar_new();
44 gtk_box_pack_end(GTK_BOX(state->status), state->progress, FALSE, FALSE, 0);
45 gtk_widget_show(state->progress);
49 gtk_widget_destroy(state->progress);
51 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(state->progress), (gdouble)cur/total);
54 gboolean load_callback(gpointer _data)
56 struct LoadData *data = _data;
57 gtk_image_set_from_pixbuf(GTK_IMAGE(data->image), data->pixbuf);
62 void load_image(GtkImage *image, GdkPixbuf *pixbuf)
64 struct LoadData *data = g_new0(struct LoadData, 1);
66 data->pixbuf = pixbuf;
67 g_idle_add(load_callback, data);
70 gpointer do_bmng_cache(gpointer _image)
72 GtkImage *image = _image;
73 g_message("Creating bmng tile");
74 GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
75 tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
76 tile = tile->children[0][1];
78 g_message("Fetching bmng image");
79 GritsWms *bmng_wms = grits_wms_new(
80 "http://www.nasa.network.com/wms", "bmng200406", "image/jpeg",
81 "bmng_test/", "jpg", 512, 256);
82 const char *path = grits_wms_fetch(bmng_wms, tile, GRITS_ONCE, NULL, NULL);
84 g_message("Loading bmng image: [%s]", path);
85 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
86 load_image(GTK_IMAGE(image), pixbuf);
88 g_message("Cleaning bmng up");
89 grits_wms_free(bmng_wms);
90 grits_tile_free(tile, NULL, NULL);
94 gpointer do_osm_cache(gpointer _image)
96 GtkImage *image = _image;
97 g_message("Creating osm tile");
98 GritsTile *tile = grits_tile_new(NULL, NORTH, SOUTH, EAST, WEST);
99 tile->children[0][1] = grits_tile_new(tile, NORTH, 0, 0, WEST);
100 tile = tile->children[0][1];
102 g_message("Fetching osm image");
103 GritsWms *osm_wms = grits_wms_new(
104 "http://labs.metacarta.com/wms/vmap0", "basic", "image/png",
105 "osm_test/", "png", 512, 256);
106 const char *path = grits_wms_fetch(osm_wms, tile, GRITS_ONCE, NULL, NULL);
108 g_message("Loading osm image: [%s]", path);
109 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
110 load_image(GTK_IMAGE(image), pixbuf);
112 g_message("Cleaning osm up");
113 grits_wms_free(osm_wms);
114 grits_tile_free(tile, NULL, NULL);
118 gpointer do_osm2_cache(gpointer _image)
120 GtkImage *image = _image;
121 g_message("Creating osm2 tile");
122 GritsTile *tile = grits_tile_new(NULL, 85.0511, -85.0511, EAST, WEST);
123 tile->children[0][1] = grits_tile_new(tile, 85.0511, 0, 0, WEST);
124 tile = tile->children[0][1];
126 g_message("Fetching osm2 image");
127 GritsTms *osm2_tms = grits_tms_new("http://tile.openstreetmap.org",
129 const char *path = grits_tms_fetch(osm2_tms, tile, GRITS_ONCE, NULL, NULL);
131 g_message("Loading osm2 image: [%s]", path);
132 GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL);
133 load_image(GTK_IMAGE(image), pixbuf);
135 g_message("Cleaning osm2 up");
136 grits_tms_free(osm2_tms);
137 grits_tile_free(tile, NULL, NULL);
142 gboolean key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
144 if (event->keyval == GDK_KEY_q)
149 int main(int argc, char **argv)
151 gtk_init(&argc, &argv);
153 GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
154 GtkWidget *vbox1 = gtk_vbox_new(FALSE, 0);
155 GtkWidget *vbox2 = gtk_vbox_new(FALSE, 0);
156 GtkWidget *status = gtk_statusbar_new();
157 GtkWidget *scroll = gtk_scrolled_window_new(NULL, NULL);
158 GtkWidget *bmng_image = gtk_image_new();
159 GtkWidget *srtm_image = gtk_image_new();
160 GtkWidget *osm_image = gtk_image_new();
161 GtkWidget *osm2_image = gtk_image_new();
162 gtk_container_add(GTK_CONTAINER(win), vbox1);
163 gtk_box_pack_start(GTK_BOX(vbox1), scroll, TRUE, TRUE, 0);
164 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox2);
165 gtk_box_pack_start(GTK_BOX(vbox2), bmng_image, TRUE, TRUE, 0);
166 gtk_box_pack_start(GTK_BOX(vbox2), srtm_image, TRUE, TRUE, 0);
167 gtk_box_pack_start(GTK_BOX(vbox2), osm_image, TRUE, TRUE, 0);
168 gtk_box_pack_start(GTK_BOX(vbox2), osm2_image, TRUE, TRUE, 0);
169 gtk_box_pack_start(GTK_BOX(vbox1), status, FALSE, FALSE, 0);
170 g_signal_connect(win, "key-press-event", G_CALLBACK(key_press_cb), NULL);
171 g_signal_connect(win, "destroy", gtk_main_quit, NULL);
172 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll),
173 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
175 g_thread_new("bmng-thread", do_bmng_cache, bmng_image);
176 g_thread_new("osm-thread", do_osm_cache, osm_image);
177 g_thread_new("osm2-thread", do_osm2_cache, osm2_image);
179 gtk_widget_show_all(win);