]> Pileus Git - grits/blobdiff - src/plugins/map.c
Convert GisWms to use GisHttp
[grits] / src / plugins / map.c
index d8ff6c2458ee9d0defa3793ded3d6aae744d669b..27261f147d64cbec54ad3f587c34cf1854694ec7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
+ * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #define TILE_WIDTH     1024
 #define TILE_HEIGHT    512
 
+const guchar colormap[][2][4] = {
+       {{0x73, 0x91, 0xad}, {0x73, 0x91, 0xad, 0x20}}, // Oceans
+       {{0xf6, 0xee, 0xee}, {0xf6, 0xee, 0xee, 0x00}}, // Ground
+       {{0xff, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xff}}, // Borders
+       {{0x73, 0x93, 0xad}, {0x73, 0x93, 0xad, 0x40}}, // Lakes
+       {{0xff, 0xe1, 0x80}, {0xff, 0xe1, 0x80, 0x60}}, // Cities
+};
+
 struct _LoadTileData {
        GisPluginMap *self;
-       GisTile       *tile;
-       GdkPixbuf     *pixbuf;
+       GisTile      *tile;
+       GdkPixbuf    *pixbuf;
 };
+#include <stdlib.h>
 static gboolean _load_tile_cb(gpointer _data)
 {
        struct _LoadTileData *data = _data;
        GisPluginMap *self   = data->self;
-       GisTile       *tile   = data->tile;
-       GdkPixbuf     *pixbuf = data->pixbuf;
+       GisTile      *tile   = data->tile;
+       GdkPixbuf    *pixbuf = data->pixbuf;
        g_free(data);
 
        /* Create Texture */
@@ -47,6 +56,20 @@ static gboolean _load_tile_cb(gpointer _data)
        gint      width  = gdk_pixbuf_get_width(pixbuf);
        gint      height = gdk_pixbuf_get_height(pixbuf);
 
+       for (int i = 0; i < width*height; i++) {
+               for (int j = 0; j < G_N_ELEMENTS(colormap); j++) {
+                       if (pixels[i*4+0] == colormap[j][0][0] &&
+                           pixels[i*4+1] == colormap[j][0][1] &&
+                           pixels[i*4+2] == colormap[j][0][2]) {
+                               pixels[i*4+0] = colormap[j][1][0];
+                               pixels[i*4+1] = colormap[j][1][1];
+                               pixels[i*4+2] = colormap[j][1][2];
+                               pixels[i*4+3] = colormap[j][1][3];
+                               break;
+                       }
+               }
+       }
+
        guint *tex = g_new0(guint, 1);
        gis_viewer_begin(self->viewer);
        glGenTextures(1, tex);
@@ -56,8 +79,8 @@ static gboolean _load_tile_cb(gpointer _data)
        glPixelStorei(GL_PACK_ALIGNMENT, 1);
        glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0,
                        (alpha ? GL_RGBA : GL_RGB), GL_UNSIGNED_BYTE, pixels);
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+       glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
        glFlush();
@@ -73,7 +96,7 @@ static void _load_tile(GisTile *tile, gpointer _self)
 {
        GisPluginMap *self = _self;
        g_debug("GisPluginMap: _load_tile start %p", g_thread_self());
-       char *path = gis_wms_make_local(self->wms, tile);
+       char *path = gis_wms_fetch(self->wms, tile, GIS_ONCE, NULL, NULL);
        struct _LoadTileData *data = g_new0(struct _LoadTileData, 1);
        data->self   = self;
        data->tile   = tile;
@@ -127,15 +150,6 @@ static void _on_location_changed(GisViewer *viewer,
        g_thread_create(_update_tiles, self, FALSE, NULL);
 }
 
-static gpointer _expose(GisCallback *callback, gpointer _self)
-{
-       GisPluginMap *self = GIS_PLUGIN_MAP(_self);
-       g_debug("GisPluginMap: expose viewer=%p tiles=%p,%p",
-                       self->viewer, self->tiles, self->tiles->data);
-       gis_viewer_render_tiles(self->viewer, self->tiles);
-       return NULL;
-}
-
 /***********
  * Methods *
  ***********/
@@ -154,8 +168,7 @@ GisPluginMap *gis_plugin_map_new(GisViewer *viewer)
                        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);
+       gis_viewer_add(viewer, GIS_OBJECT(self->tiles), GIS_LEVEL_OVERLAY, 0);
 
        return self;
 }