*/
#include <gtk/gtkgl.h>
+#include <glib/gstdio.h>
#include <GL/gl.h>
#include <gis.h>
#define MAX_RESOLUTION 500
#define TILE_WIDTH 1024
#define TILE_HEIGHT 512
+#define TILE_SIZE (TILE_WIDTH*TILE_HEIGHT*sizeof(guint16))
struct _TileData {
/* OpenGL has to be first to make gis_opengl_render_tiles happy */
};
static guint16 *_load_bil(gchar *path)
{
- gchar *data;
- g_file_get_contents(path, &data, NULL, NULL);
+ gsize len;
+ gchar *data = NULL;
+ g_file_get_contents(path, &data, &len, NULL);
g_debug("GisPluginElev: load_bil %p", data);
+ if (len != TILE_SIZE) {
+ g_warning("GisPluginElev: _load_bil - unexpected tile size %d, != %d",
+ len, TILE_SIZE);
+ g_free(data);
+ return NULL;
+ }
return (guint16*)data;
}
static GdkPixbuf *_load_pixbuf(guint16 *bil)
GisPluginElev *self = _self;
struct _LoadTileData *load = g_new0(struct _LoadTileData, 1);
- load->path = gis_wms_make_local(self->wms, tile);
+ load->path = gis_wms_fetch(self->wms, tile, GIS_ONCE, NULL, NULL);
g_debug("GisPluginElev: _load_tile: %s", load->path);
load->self = self;
load->tile = tile;
load->data = g_new0(struct _TileData, 1);
- if (LOAD_BIL || LOAD_OPENGL)
+ if (LOAD_BIL || LOAD_OPENGL) {
load->data->bil = _load_bil(load->path);
- if (LOAD_OPENGL)
+ if (!load->data->bil) {
+ g_remove(load->path);
+ g_free(load->data);
+ g_free(load->path);
+ g_free(load);
+ return;
+ }
+ }
+ if (LOAD_OPENGL) {
load->pixbuf = _load_pixbuf(load->data->bil);
+ }
g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, load, NULL);
}
g_thread_create(_update_tiles, self, FALSE, NULL);
}
-static gpointer _expose(GisCallback *callback, gpointer _self)
-{
- GisPluginElev *self = GIS_PLUGIN_ELEV(_self);
- g_debug("GisPluginElev: expose tiles=%p data=%p",
- self->tiles, self->tiles->data);
- if (LOAD_OPENGL)
- gis_viewer_render_tiles(self->viewer, self->tiles);
- return NULL;
-}
-
/***********
* Methods *
***********/
G_CALLBACK(_on_location_changed), self);
/* Add renderers */
- GisCallback *callback = gis_callback_new(_expose, self);
- gis_viewer_add(viewer, GIS_OBJECT(callback), GIS_LEVEL_WORLD, 0);
+ if (LOAD_OPENGL)
+ gis_viewer_add(viewer, GIS_OBJECT(self->tiles), GIS_LEVEL_WORLD, 0);
return self;
}