Skip to content

Commit

Permalink
add support for configuring with a json config file (using boost ptre…
Browse files Browse the repository at this point in the history
…e json parser), add max_extent option to limit bounds of request, refactor font/input plugins loading so that it is done through config or command line not compiled into app, added --help and --version options, and fixed successful response to propertly set reply::ok in header
  • Loading branch information
Dane Springmeyer committed Jul 28, 2010
1 parent af6cbbd commit ebe166c
Show file tree
Hide file tree
Showing 13 changed files with 454 additions and 114 deletions.
8 changes: 8 additions & 0 deletions .gitignore
@@ -0,0 +1,8 @@
.sconf_temp/
.sconsign.dblite
archive
*.o
*.os
*.pyc
.DS_Store

3 changes: 2 additions & 1 deletion README.txt
Expand Up @@ -7,7 +7,7 @@ old school wms for mapnik.
Requires
--------

* Mapnik 0.7.2 / Mapnik2
* Mapnik 0.7.2 (http://svn.mapnik.org/branches/0.7.2-dev/) / Mapnik2 (http://svn.mapnik.org/trunk)
* Boost 1.42 (for spirit2)
* Scons (for build)

Expand Down Expand Up @@ -51,6 +51,7 @@ Caveats

ToDo
----
* Modify mapnik to be able to send a query bbox different than the map extent
* Automated builds using different options (mapnik vs. mapnik2)
* Support params:
- srs ?
Expand Down
4 changes: 3 additions & 1 deletion SConstruct
Expand Up @@ -21,6 +21,8 @@ env['LIBS'] = [mapnik,'icuuc','boost_filesystem','boost_regex','boost_system','b
env['CPPPATH'] = ['/usr/local/include','/usr/local/Cellar/icu4c/4.3.1/include/']
env['LIBPATH'] = ['/usr/local/lib','/usr/local/Cellar/icu4c/4.3.1/lib/']

#env['CXX'] = 'clang++ -v'

# add freetype paths
env.ParseConfig('freetype-config --libs --cflags')

Expand Down Expand Up @@ -57,4 +59,4 @@ if not HELP_REQUESTED:
Export('env')

# Build the core library
SConscript('src/SConscript')
SConscript('src/SConscript')
31 changes: 31 additions & 0 deletions config.json
@@ -0,0 +1,31 @@
/** json configuration for paleoserver */

/** warning the format of this file is in contant flux */

{
/** required: directory to register mapnik fonts */
"fonts" : "/usr/local/lib/mapnik2/fonts/",

/** required: directory to register mapnik input plugins */
"plugins" : "/usr/local/lib/mapnik2/input/",

/** required: number of threads to support - should match roughly number of CPU + 1 */
"threads" : 2,

/** required: address to bind to */
"address" : "0.0.0.0",

/** required: port to bind to */
"port" : "8000",

/** required: document root of server */
"doc_root" : ".",

/** required: mapnik xml stylesheet to load */
"stylesheet" : "tests/demo.xml"

// optional: limit all requests to given extent (must be in request srs)
//"max_extent" : "-180,60,180,60"

/** NOTE: last option cannot end with trailing comma */
}
72 changes: 57 additions & 15 deletions src/map_utils.hpp
@@ -1,30 +1,72 @@
#ifndef PALEOSERVER_MAP_UTILS_HPP
#define PALEOSERVER_MAP_UTILS_HPP

// mapnik
#include <mapnik/datasource_cache.hpp>
#include <mapnik/font_engine_freetype.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/filesystem/operations.hpp>
// boost
//#include <boost/algorithm/string.hpp>
//#include <boost/filesystem/operations.hpp>

#include <iostream>

#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/tokenizer.hpp>
#include <boost/format.hpp>

#include <boost/optional.hpp>

#if MAPNIK_VERSION >= 800
#include <mapnik/box2d.hpp>
#define Envelope box2d
#else
#include <mapnik/envelope.hpp>
#define box2d Envelope
#endif

using namespace mapnik;

namespace http {
namespace paleoserver {
namespace map_utils {


void init_mapnik()
inline boost::optional<box2d<double> > parse_bbox_from_string(const std::string& bbox_string)
{
#if USING_MAPNIK2
std::string mapnik_dir("/usr/local/lib/mapnik2/");
#else
std::string mapnik_dir("/usr/local/lib/mapnik/");
#endif
datasource_cache::instance()->register_datasources(mapnik_dir + "input/");
freetype_engine::register_fonts(mapnik_dir + "fonts/");

boost::optional<Envelope<double> > result;
boost::char_separator<char> sep(",");
boost::tokenizer<boost::char_separator<char> > tok(bbox_string,sep);
unsigned i = 0;
bool success = false;
double d[4];
for (boost::tokenizer<boost::char_separator<char> >::iterator beg=tok.begin();
beg!=tok.end();++beg)
{
try
{
d[i] = boost::lexical_cast<double>(boost::trim_copy(*beg));
}
catch (boost::bad_lexical_cast & ex)
{
std::clog << *beg << " : " << ex.what() << "\nAre your coordinates each separated by commas?\n";
break;
}
if (i==3)
{
success = true;
break;
}
++i;
}

if (success)
{
Envelope<double> bbox(d[0],d[1],d[2],d[3]);
result.reset(bbox);
return result;
}

return result;
}

}
}

Expand Down
4 changes: 2 additions & 2 deletions src/mime_types.cpp
Expand Up @@ -20,11 +20,11 @@ struct mapping
const char* mime_type;
} mappings[] =
{
{ "png", "image/png" },
{ "jpg", "image/jpeg" },
{ "gif", "image/gif" },
{ "htm", "text/html" },
{ "html", "text/html" },
{ "jpg", "image/jpeg" },
{ "png", "image/png" },
{ 0, 0 } // Marks end of list.
};

Expand Down

0 comments on commit ebe166c

Please sign in to comment.