X-Git-Url: http://pileus.org/git/?p=grits;a=blobdiff_plain;f=src%2Fplugins%2Fmap.c;h=d93e33633f73fe5862752ae00ccfdf0abd43f330;hp=7edc1ce64cc951d7b3ab909486bfb21c11e79a96;hb=4d9d0eb76317c97b94f44a745ffecde29de0454d;hpb=bd716715f1d13a8df514fcfa53fd82aebdfda770 diff --git a/src/plugins/map.c b/src/plugins/map.c index 7edc1ce..d93e336 100644 --- a/src/plugins/map.c +++ b/src/plugins/map.c @@ -15,7 +15,16 @@ * along with this program. If not, see . */ +/** + * SECTION:map + * @short_description: Map plugin + * + * #GisPluginMap provides map overlays. Much of this data is obtained from the + * OpenStreetMap project. + */ + #include +#include #include #include @@ -27,7 +36,7 @@ #define TILE_WIDTH 1024 #define TILE_HEIGHT 512 -const guchar colormap[][2][4] = { +static 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 @@ -38,19 +47,28 @@ const guchar colormap[][2][4] = { struct _LoadTileData { GisPluginMap *map; GisTile *tile; - GdkPixbuf *pixbuf; + gchar *path; }; -#include static gboolean _load_tile_cb(gpointer _data) { struct _LoadTileData *data = _data; - GisPluginMap *map = data->map; - GisTile *tile = data->tile; - GdkPixbuf *pixbuf = data->pixbuf; + GisPluginMap *map = data->map; + GisTile *tile = data->tile; + gchar *path = data->path; g_free(data); - /* Create Texture */ + /* Load pixbuf */ g_debug("GisPluginMap: _load_tile_cb start"); + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, NULL); + if (!pixbuf) { + g_warning("GisPluginMap: _load_tile - Error loading pixbuf %s", path); + g_remove(path); + g_free(path); + return FALSE; + } + g_free(path); + + /* Create Texture */ guchar *pixels = gdk_pixbuf_get_pixels(pixbuf); gboolean alpha = gdk_pixbuf_get_has_alpha(pixbuf); gint width = gdk_pixbuf_get_width(pixbuf); @@ -80,8 +98,8 @@ static gboolean _load_tile_cb(gpointer _data) (alpha ? GL_RGBA : GL_RGB), GL_UNSIGNED_BYTE, pixels); 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); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glFlush(); tile->data = tex; @@ -94,18 +112,11 @@ static void _load_tile(GisTile *tile, gpointer _map) { GisPluginMap *map = _map; g_debug("GisPluginMap: _load_tile start %p", g_thread_self()); - char *path = gis_wms_fetch(map->wms, tile, GIS_ONCE, NULL, NULL); struct _LoadTileData *data = g_new0(struct _LoadTileData, 1); - data->map = map; - data->tile = tile; - data->pixbuf = gdk_pixbuf_new_from_file(path, NULL); - if (data->pixbuf) { - g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL); - } else { - g_warning("GisPluginMap: _load_tile - Error loading pixbuf %s", path); - g_remove(path); - } - g_free(path); + data->map = map; + data->tile = tile; + data->path = gis_wms_fetch(map->wms, tile, GIS_ONCE, NULL, NULL); + g_idle_add_full(G_PRIORITY_LOW, _load_tile_cb, data, NULL); g_debug("GisPluginMap: _load_tile end %p", g_thread_self()); } @@ -117,21 +128,21 @@ static gboolean _free_tile_cb(gpointer data) } static void _free_tile(GisTile *tile, gpointer _map) { - GisPluginMap *map = _map; g_debug("GisPluginMap: _free_tile: %p", tile->data); - g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL); + if (tile->data) + g_idle_add_full(G_PRIORITY_LOW, _free_tile_cb, tile->data, NULL); } static gpointer _update_tiles(gpointer _map) { g_debug("GisPluginMap: _update_tiles"); GisPluginMap *map = _map; - g_mutex_lock(map->mutex); - gdouble lat, lon, elev; - gis_viewer_get_location(map->viewer, &lat, &lon, &elev); - gis_tile_update(map->tiles, + if (!g_mutex_trylock(map->mutex)) + return NULL; + GisPoint eye; + gis_viewer_get_location(map->viewer, &eye.lat, &eye.lon, &eye.elev); + gis_tile_update(map->tiles, &eye, MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH, - lat, lon, elev, _load_tile, map); gis_tile_gc(map->tiles, time(NULL)-10, _free_tile, map); @@ -148,9 +159,24 @@ static void _on_location_changed(GisViewer *viewer, g_thread_create(_update_tiles, map, FALSE, NULL); } +static gpointer _threaded_init(GisPluginMap *map) +{ + _load_tile(map->tiles, map); + _update_tiles(map); + return NULL; +} + /*********** * Methods * ***********/ +/** + * gis_plugin_map_new: + * @viewer: the #GisViewer to use for drawing + * + * Create a new instance of the map plugin. + * + * Returns: the new #GisPluginMap + */ GisPluginMap *gis_plugin_map_new(GisViewer *viewer) { g_debug("GisPluginMap: new"); @@ -158,15 +184,14 @@ GisPluginMap *gis_plugin_map_new(GisViewer *viewer) map->viewer = g_object_ref(viewer); /* Load initial tiles */ - _load_tile(map->tiles, map); - g_thread_create(_update_tiles, map, FALSE, NULL); + g_thread_create((GThreadFunc)_threaded_init, map, FALSE, NULL); /* Connect signals */ map->sigid = g_signal_connect(map->viewer, "location-changed", G_CALLBACK(_on_location_changed), map); /* Add renderers */ - gis_viewer_add(viewer, GIS_OBJECT(map->tiles), GIS_LEVEL_OVERLAY, 0); + gis_viewer_add(viewer, GIS_OBJECT(map->tiles), GIS_LEVEL_OVERLAY-1, 0); return map; }