Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add a SCons build script for the c++ rundemo sample program, and touc…

…hup code and readme, closes #197
  • Loading branch information...
commit a79714f6e2c311afa3ff8f5b76697e62733ecd72 1 parent ea2e39b
@springmeyer springmeyer authored
Showing with 75 additions and 15 deletions.
  1. +52 −0 demo/c++/SConscript
  2. +10 −5 demo/c++/readme.txt
  3. +13 −10 demo/c++/rundemo.cpp
View
52 demo/c++/SConscript
@@ -0,0 +1,52 @@
+#
+# This file is part of Mapnik (c++ mapping toolkit)
+#
+# Copyright (C) 2009 Artem Pavlenko, Dane Springmeyer
+#
+# Mapnik is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# $Id$
+
+Import ('env')
+
+prefix = env['PREFIX']
+install_prefix = env['DESTDIR'] + '/' + prefix
+
+source = Split(
+ """
+ rundemo.cpp
+ """
+ )
+
+headers = env['CPPPATH']
+
+boost_thread = 'boost_thread%s' % env['BOOST_APPEND']
+
+libraries = [boost_thread]
+
+if env['CAIRO']:
+ libraries.append('cairo')
+
+if env['PLATFORM'] == 'Darwin':
+ libraries.append('mapnik')
+ libraries.append('icuuc')
+ libraries.append('icudata')
+
+rundemo = env.Program('rundemo', source, CPPPATH=headers, LIBS=libraries)
+
+# we don't install this app because the datasource paths are relative
+# and we're not going to install the sample data.
+#env.Install(install_prefix + '/bin', rundemo)
+#env.Alias('install', install_prefix + '/bin')
View
15 demo/c++/readme.txt
@@ -1,13 +1,18 @@
-This directory contains a simple c++ program demonstrating Mapnik API. It mimics python example with couple exceptions.
+This directory contains a simple c++ program demonstrating the Mapnik C++ API. It mimics the python 'rundemo.py' example with a couple exceptions.
-To build (using GCC/G++ toolkit):
+To build it re-configure SCons with DEMO=True then rebuild::
-g++ -O3 -I/usr/local/include/mapnik -I/opt/boost/include/boost-1_33_1 -I/usr/include/freetype2 -I../../agg/include -L/usr/local/lib -lmapnik rundemo.cpp -o rundemo
+ $ python scons/scons.py configure DEMO=True
+ $ python scons/scons.py
-To run:
+The sample program will be compiled (but not installed).
-./rundemo
+
+To run::
+
+ $ cd demo/c++
+ $ ./rundemo /usr/local/lib/mapnik
For more detailed comments have a look in demo/python/rundemo.py
View
23 demo/c++/rundemo.cpp
@@ -21,9 +21,6 @@
*****************************************************************************/
// $Id$
-// define before any includes
-#define BOOST_SPIRIT_THREADSAFE
-
#include <mapnik/map.hpp>
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
@@ -33,9 +30,11 @@
#include <mapnik/image_util.hpp>
#include <mapnik/config_error.hpp>
+#if defined(HAVE_CAIRO)
// cairo
#include <mapnik/cairo_renderer.hpp>
#include <cairomm/surface.h>
+#endif
#include <iostream>
@@ -44,7 +43,8 @@ int main ( int argc , char** argv)
{
if (argc != 2)
{
- std::cout << "usage: ./rundemo <mapnik_install_dir>\n";
+ std::cout << "usage: ./rundemo <mapnik_install_dir>\nUsually /usr/local/lib/mapnik\n";
+ std::cout << "Warning: ./rundemo looks for data in ../data/,\nTherefore must be run from within the demo/c++ folder.\n";
return EXIT_SUCCESS;
}
@@ -52,8 +52,10 @@ int main ( int argc , char** argv)
try {
std::cout << " running demo ... \n";
std::string mapnik_dir(argv[1]);
- datasource_cache::instance()->register_datasources(mapnik_dir + "/plugins/input/shape");
- freetype_engine::register_font(mapnik_dir + "/fonts/dejavu-ttf-2.14/DejaVuSans.ttf");
+ std::cout << " looking for 'shape.input' plugin in... " << mapnik_dir << "/input/" << "\n";
+ datasource_cache::instance()->register_datasources(mapnik_dir + "/input/");
+ std::cout << " looking for DejaVuSans font in... " << mapnik_dir << "/fonts/DejaVuSans.ttf" << "\n";
+ freetype_engine::register_font(mapnik_dir + "/fonts/DejaVuSans.ttf");
Map m(800,600);
m.set_background(color_factory::from_string("white"));
@@ -69,7 +71,7 @@ int main ( int argc , char** argv)
provpoly_style.add_rule(provpoly_rule_on);
rule_type provpoly_rule_qc;
- provpoly_rule_qc.set_filter(create_filter("[NAME_EN] = 'Quebec'"));
+ provpoly_rule_qc.set_filter(create_filter("[NOM_FR] = 'Québec'"));
provpoly_rule_qc.append(polygon_symbolizer(color(217, 235, 203)));
provpoly_style.add_rule(provpoly_rule_qc);
@@ -257,7 +259,7 @@ int main ( int argc , char** argv)
"- demo256.png\n"
"Have a look!\n";
-
+ #if defined(HAVE_CAIRO)
Cairo::RefPtr<Cairo::ImageSurface> image_surface;
image_surface = Cairo::ImageSurface::create(Cairo::FORMAT_ARGB32, m.getWidth(),m.getHeight());
@@ -283,16 +285,17 @@ int main ( int argc , char** argv)
"- cairo-demo.pdf\n"
"- cairo-demo.svg\n"
"Have a look!\n";
+ #endif
}
catch ( const mapnik::config_error & ex )
{
- std::cerr << "### Configuration error: " << ex.what();
+ std::cerr << "### Configuration error: " << ex.what() << std::endl;
return EXIT_FAILURE;
}
catch ( const std::exception & ex )
{
- std::cerr << "### std::exception: " << ex.what();
+ std::cerr << "### std::exception: " << ex.what() << std::endl;
return EXIT_FAILURE;
}
catch ( ... )
Please sign in to comment.
Something went wrong with that request. Please try again.