Updated Developing Mapnik Plugins (markdown)
parent
e1f01904dc
commit
47dd8d2d8b
1 changed files with 5 additions and 5 deletions
|
@ -8,17 +8,16 @@
|
|||
|
||||
Plugins can be used from C++ to read in different kinds of files. Here's an example of C++ code that implicitly uses the _shape_ plugin to read in a ESRI Shapefile:
|
||||
|
||||
|
||||
#!C
|
||||
```c
|
||||
std::string mapnik_dir(argv[1]); // assume mapnik home directory, such as "~/src/mapnik" passed in
|
||||
std::string plugins_dir(mapnik_dir + "/plugins/input/");
|
||||
datasource_cache::instance()->register_datasources(plugins_dir + "shape"); // ESRI SHP support
|
||||
datasource_cache::instance()->register_datasources(plugins_dir + "postgis"); // PostGIS integration
|
||||
```
|
||||
|
||||
and used like so,
|
||||
|
||||
|
||||
#!C
|
||||
```c
|
||||
{
|
||||
parameters p;
|
||||
p["type"]="shape";
|
||||
|
@ -30,8 +29,9 @@ and used like so,
|
|||
lyr.add_style("elsewhere"); // this file
|
||||
m.addLayer(lyr);
|
||||
}
|
||||
```
|
||||
|
||||
Let's drill-down into what's actually going on. We constructed a [parameter object](http://trac.mapnik.org/browser/trunk/include/mapnik/params.hpp) and passed it to a factory method (datasource_cache::instance()->create(p)). It then returned a shared pointer to a datasource object, which was then passed on a new Layer object.
|
||||
Let's drill-down into what's actually going on. We constructed a [parameter object](https://github.com/mapnik/mapnik/blob/master/include/mapnik/params.hpp) and passed it to a factory method (datasource_cache::instance()->create(p)). It then returned a shared pointer to a datasource object, which was then passed on a new Layer object.
|
||||
|
||||
In C++, the parameters object is-a param_map (a std::map from string keys to "value_holder"s, where a value_holder is a [boost::variant](http://www.boost.org/doc/libs/1_36_0/doc/html/variant.html#variant.intro) that can either hold a double or a string. In other words, "parameters p" is a semi-generic parameter hash, then passed to and read by a factory method.
|
||||
|
||||
|
|
Loading…
Reference in a new issue