Skip to content

Commit

Permalink
Enable displaying of Mapnik configuration extra parameters.
Browse files Browse the repository at this point in the history
Extend the sample configuration with some such parameters.
  • Loading branch information
rnorris committed Feb 10, 2015
1 parent a8374fc commit 581feee
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/mapnik_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,29 @@ GdkPixbuf* mapnik_interface_render ( MapnikInterface* mi, double lat_tl, double
return pixbuf;
}

/**
* 'Parameter' information about the Map configuration
*
* Free every string element and the returned GArray itself after use
*/
GArray* mapnik_interface_get_parameters ( MapnikInterface* mi )
{
GArray *array = g_array_new (FALSE, TRUE, sizeof(gchar*));

mapnik::parameters pmts = mi->myMap->get_extra_parameters();
for (mapnik::parameters::const_iterator ii = pmts.begin(); ii != pmts.end(); ii++) {
// Dodgy hacking to avoid using boost or mapnik::utils visitor stuff (not available in mapnik 2.2)
// Simply want the strings of each parameter so we can display something...
std::stringstream ss;
ss << ii->first << ": " << ii->second;
// Copy - otherwise ss goes output scope and junk memory would be referenced.
gchar *str2 = g_strdup ( (gchar*)ss.str().c_str() );
g_array_append_val ( array, str2 );
}

return array;
}

/**
* General information about Mapnik
*
Expand Down
3 changes: 3 additions & 0 deletions src/mapnik_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
extern "C" {
#endif

#include <glib.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

typedef struct _MapnikInterface MapnikInterface;
Expand All @@ -42,6 +43,8 @@ gchar* mapnik_interface_load_map_file ( MapnikInterface* mi,

GdkPixbuf* mapnik_interface_render ( MapnikInterface* mi, double lat_tl, double lon_tl, double lat_br, double lon_br );

GArray* mapnik_interface_get_parameters ( MapnikInterface* mi );

gchar * mapnik_interface_about ( void );

#ifdef __cplusplus
Expand Down
23 changes: 23 additions & 0 deletions src/vikmapniklayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,24 @@ static void mapnik_layer_carto ( menu_array_values values )
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 );
}

/**
*
*/
Expand Down Expand Up @@ -1000,6 +1018,11 @@ static void mapnik_layer_add_menu_items ( VikMapnikLayer *vml, GtkMenu *menu, gp
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);
Expand Down
6 changes: 6 additions & 0 deletions test/Mapnik-ne_110m_admin_0_countries.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<Map background-color="steelblue" srs="+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs">

<Parameters>
<Parameter name="name"><![CDATA[Admin Countries]]></Parameter>
<Parameter name="description"><![CDATA[Simple country boundaries]]></Parameter>
<Parameter name="attribution"><![CDATA[Natural Earth]]></Parameter>
</Parameters>

<Style name="My Style">
<Rule>
<PolygonSymbolizer fill="#f2eff9" />
Expand Down

0 comments on commit 581feee

Please sign in to comment.