#include "vikmapslayer.h"
-#if !GLIB_CHECK_VERSION(2,26,0)
-typedef struct stat GStatBuf;
-#endif
-
struct _VikMapnikLayerClass
{
VikLayerClass object_class;
(VikLayerFuncDraw) mapnik_layer_draw,
(VikLayerFuncChangeCoordMode) NULL,
+ (VikLayerFuncGetTimestamp) NULL,
+
(VikLayerFuncSetMenuItemsSelection) NULL,
(VikLayerFuncGetMenuItemsSelection) NULL,
#else
if ( g_file_test ( "/usr/lib/mapnik/input", G_FILE_TEST_EXISTS ) )
data.s = g_strdup ( "/usr/lib/mapnik/input" );
+ // Current Debian locations
+ else if ( g_file_test ( "/usr/lib/mapnik/3.0/input", G_FILE_TEST_EXISTS ) )
+ data.s = g_strdup ( "/usr/lib/mapnik/3.0/input" );
else if ( g_file_test ( "/usr/lib/mapnik/2.2/input", G_FILE_TEST_EXISTS ) )
- // Current Debian location
data.s = g_strdup ( "/usr/lib/mapnik/2.2/input" );
else
data.s = g_strdup ( "" );
/**
* vik_mapnik_layer_init:
*
- * Mostly to initialize preferences
+ * Just initialize preferences
*/
void vik_mapnik_layer_init (void)
{
tmp.s = "carto";
a_preferences_register(&prefs[i++], tmp, MAPNIK_PREFS_GROUP_KEY);
+}
+/**
+ * vik_mapnik_layer_post_init:
+ *
+ * Initialize data structures - now that reading preferences is OK to perform
+ */
+void vik_mapnik_layer_post_init (void)
+{
tp_mutex = vik_mutex_new();
// Just storing keys only
// NB Only performed once per program run
static void mapnik_layer_class_init ( VikMapnikLayerClass *klass )
{
- mapnik_interface_initialize ( a_preferences_get (MAPNIK_PREFS_NAMESPACE"plugins_directory")->s,
- a_preferences_get (MAPNIK_PREFS_NAMESPACE"fonts_directory")->s,
- a_preferences_get (MAPNIK_PREFS_NAMESPACE"recurse_fonts_directory")->b );
+ VikLayerParamData *pd = a_preferences_get (MAPNIK_PREFS_NAMESPACE"plugins_directory");
+ VikLayerParamData *fd = a_preferences_get (MAPNIK_PREFS_NAMESPACE"fonts_directory");
+ VikLayerParamData *rfd = a_preferences_get (MAPNIK_PREFS_NAMESPACE"recurse_fonts_directory");
+
+ if ( pd && fd && rfd )
+ mapnik_interface_initialize ( pd->s, fd->s, rfd->b );
+ else
+ g_critical ( "Unable to initialize mapnik interface from preferences" );
}
GType vik_mapnik_layer_get_type ()
if ( !g_strcmp0 ( vml->filename_xml, vml->filename_css ) ) {
vml->filename_xml = g_strconcat ( vml->filename_css, ".xml", NULL );
}
+ g_regex_unref ( regex );
}
if ( !g_file_set_contents (vml->filename_xml, mystdout, -1, &error) ) {
g_warning ("%s: %s", __FUNCTION__, error->message );
gchar *dir = g_path_get_dirname ( filename );
if ( !g_file_test ( filename, G_FILE_TEST_EXISTS ) )
- g_mkdir_with_parents ( dir , 0777 );
+ if ( g_mkdir_with_parents ( dir , 0777 ) != 0 )
+ g_warning ("%s: Failed to mkdir %s", __FUNCTION__, dir );
g_free ( dir );
if ( !gdk_pixbuf_save (pixbuf, filename, "png", &error, NULL ) ) {
// NB Mapnik can apply alpha, but use our own function for now
if ( vml->alpha < 255 )
- pixbuf = ui_pixbuf_set_alpha ( pixbuf, vml->alpha );
+ pixbuf = ui_pixbuf_scale_alpha ( pixbuf, vml->alpha );
a_mapcache_add ( pixbuf, (mapcache_extra_t){ tt }, ulm->x, ulm->y, ulm->z, MAP_ID_MAPNIK_RENDER, ulm->scale, vml->alpha, 0.0, 0.0, vml->filename_xml );
+ g_object_unref(pixbuf);
}
static void render_info_free ( RenderInfo *data )
/**
* Thread
*/
-void thread_add (VikMapnikLayer *vml, MapCoord *mul, VikCoord *ul, VikCoord *br, gint x, gint y, gint z, gint zoom, const gchar* name )
+static void thread_add (VikMapnikLayer *vml, MapCoord *mul, VikCoord *ul, VikCoord *br, gint x, gint y, gint z, gint zoom, const gchar* name )
{
// Create request
guint nn = name ? g_str_hash ( name ) : 0;
/**
* load_pixbuf:
+ *
+ * If function returns GdkPixbuf properly, reference counter to this
+ * buffer has to be decreased, when buffer is no longer needed.
*/
static GdkPixbuf *load_pixbuf ( VikMapnikLayer *vml, MapCoord *ulm, MapCoord *brm, gboolean *rerender )
{
}
/**
- *
+ * Caller has to decrease reference counter of returned
+ * GdkPixbuf, when buffer is no longer needed.
*/
static GdkPixbuf *get_pixbuf ( VikMapnikLayer *vml, MapCoord *ulm, MapCoord *brm )
{
return;
}
+ if ( vml->mi ) {
+ gchar *copyright = mapnik_interface_get_copyright ( vml->mi );
+ if ( copyright ) {
+ vik_viewport_add_copyright ( vvp, copyright );
+ }
+ }
+
VikCoord ul, br;
ul.mode = VIK_COORD_LATLON;
br.mode = VIK_COORD_LATLON;
map_utils_iTMS_to_vikcoord ( &ulm, &coord );
vik_viewport_coord_to_screen ( vvp, &coord, &xx, &yy );
vik_viewport_draw_pixbuf ( vvp, pixbuf, 0, 0, xx, yy, vml->tile_size_x, vml->tile_size_x );
+ g_object_unref(pixbuf);
}
}
}
mapnik_layer_draw ( vml, vvp );
}
+/**
+ * Show Mapnik configuration parameters
+ */
+static void mapnik_layer_information ( menu_array_values values )
+{
+ VikMapnikLayer *vml = values[MA_VML];
+ if ( !vml->mi )
+ return;
+ GArray *array = mapnik_interface_get_parameters( vml->mi );
+ if ( array->len ) {
+ a_dialog_list ( VIK_GTK_WINDOW_FROM_LAYER(vml), _("Mapnik Information"), array, 1 );
+ // Free the copied strings
+ for ( int i = 0; i < array->len; i++ )
+ g_free ( g_array_index(array,gchar*,i) );
+ }
+ g_array_free ( array, FALSE );
+}
+
/**
*
*/
gtk_widget_show ( item );
}
+ item = gtk_image_menu_item_new_from_stock ( GTK_STOCK_INFO, NULL );
+ g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(mapnik_layer_information), values );
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show ( item );
+
item = gtk_image_menu_item_new_from_stock ( GTK_STOCK_ABOUT, NULL );
g_signal_connect_swapped ( G_OBJECT(item), "activate", G_CALLBACK(mapnik_layer_about), values );
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
if ( g_file_test ( filename, G_FILE_TEST_EXISTS ) ) {
filemsg = g_strconcat ( "Tile File: ", filename, NULL );
// Get some timestamp information of the tile
- struct stat stat_buf;
+ GStatBuf stat_buf;
if ( g_stat ( filename, &stat_buf ) == 0 ) {
gchar time_buf[64];
strftime ( time_buf, sizeof(time_buf), "%c", gmtime((const time_t *)&stat_buf.st_mtime) );