#endif
#include "viking.h"
-#include "vikutils.h"
#include <glib.h>
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include "vikmapslayer.h"
-#if !GLIB_CHECK_VERSION(2,26,0)
-typedef struct stat GStatBuf;
-#endif
-
struct _VikMapnikLayerClass
{
VikLayerClass object_class;
static VikToolInterface mapnik_tools[] = {
// Layer Info
// Zoom All?
- { { "MapnikFeatures", GTK_STOCK_INFO, N_("_Mapnik Features"), NULL, N_("Mapnik Features"), 0 },
+ { NULL,
+ { "MapnikFeatures", GTK_STOCK_INFO, N_("_Mapnik Features"), NULL, N_("Mapnik Features"), 0 },
(VikToolConstructorFunc) mapnik_feature_create,
NULL,
NULL,
(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)
{
- a_preferences_register_group ( MAPNIK_PREFS_GROUP_KEY, "Mapnik" );
+ a_preferences_register_group ( MAPNIK_PREFS_GROUP_KEY, _("Mapnik") );
guint i = 0;
VikLayerParamData tmp = plugins_default();
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 ()
gchar *msg = g_strdup_printf ( "%s: %s", _("Running"), command );
vik_window_statusbar_update ( vw, msg, VIK_STATUSBAR_INFO );
vik_window_set_busy_cursor ( vw );
+ g_free ( msg );
}
gint64 tt1 = 0;
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 )
{
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);
}
}
}
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) );