+ add style pickling support to mapnik::Map, fix tabs, and only un-pickle background color if exists (closes 233)
This commit is contained in:
parent
e68d934eff
commit
771e76f637
1 changed files with 50 additions and 23 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <mapnik/layer.hpp>
|
||||
#include <mapnik/map.hpp>
|
||||
#include <mapnik/feature_type_style.hpp>
|
||||
|
||||
#include "python_optional.hpp"
|
||||
|
||||
|
@ -42,41 +43,67 @@ struct map_pickle_suite : boost::python::pickle_suite
|
|||
static boost::python::tuple
|
||||
getinitargs(const Map& m)
|
||||
{
|
||||
return boost::python::make_tuple(m.getWidth(),m.getHeight(),m.srs());
|
||||
return boost::python::make_tuple(m.getWidth(),m.getHeight(),m.srs());
|
||||
}
|
||||
|
||||
static boost::python::tuple
|
||||
getstate(const Map& m)
|
||||
{
|
||||
boost::python::list l;
|
||||
for (unsigned i=0;i<m.layerCount();++i)
|
||||
{
|
||||
l.append(m.getLayer(i));
|
||||
}
|
||||
return boost::python::make_tuple(m.getCurrentExtent(),m.background(),l);
|
||||
boost::python::list l;
|
||||
for (unsigned i=0;i<m.layerCount();++i)
|
||||
{
|
||||
l.append(m.getLayer(i));
|
||||
}
|
||||
|
||||
boost::python::list s;
|
||||
Map::const_style_iterator it = m.styles().begin();
|
||||
Map::const_style_iterator end = m.styles().end();
|
||||
for (; it != end; ++it)
|
||||
{
|
||||
const std::string & name = it->first;
|
||||
const mapnik::feature_type_style & style = it->second;
|
||||
boost::python::tuple style_pair = boost::python::make_tuple(name,style);
|
||||
s.append(style_pair);
|
||||
}
|
||||
|
||||
return boost::python::make_tuple(m.getCurrentExtent(),m.background(),l,s);
|
||||
}
|
||||
|
||||
static void
|
||||
setstate (Map& m, boost::python::tuple state)
|
||||
{
|
||||
using namespace boost::python;
|
||||
if (len(state) != 3)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
("expected 3-item tuple in call to __setstate__; got %s"
|
||||
using namespace boost::python;
|
||||
if (len(state) != 4)
|
||||
{
|
||||
PyErr_SetObject(PyExc_ValueError,
|
||||
("expected 4-item tuple in call to __setstate__; got %s"
|
||||
% state).ptr()
|
||||
);
|
||||
throw_error_already_set();
|
||||
}
|
||||
Envelope<double> ext = extract<Envelope<double> >(state[0]);
|
||||
color bg = extract<color>(state[1]);
|
||||
m.zoomToBox(ext);
|
||||
m.set_background(bg);
|
||||
boost::python::list l=extract<boost::python::list>(state[2]);
|
||||
for (int i=0;i<len(l);++i)
|
||||
{
|
||||
m.addLayer(extract<Layer>(l[i]));
|
||||
}
|
||||
throw_error_already_set();
|
||||
}
|
||||
|
||||
Envelope<double> ext = extract<Envelope<double> >(state[0]);
|
||||
m.zoomToBox(ext);
|
||||
if (state[1])
|
||||
{
|
||||
color bg = extract<color>(state[1]);
|
||||
m.set_background(bg);
|
||||
}
|
||||
|
||||
boost::python::list l=extract<boost::python::list>(state[2]);
|
||||
for (int i=0;i<len(l);++i)
|
||||
{
|
||||
m.addLayer(extract<Layer>(l[i]));
|
||||
}
|
||||
|
||||
boost::python::list s=extract<boost::python::list>(state[3]);
|
||||
for (int i=0;i<len(s);++i)
|
||||
{
|
||||
boost::python::tuple style_pair=extract<boost::python::tuple>(s[i]);
|
||||
std::string name = extract<std::string>(style_pair[0]);
|
||||
mapnik::feature_type_style style = extract<mapnik::feature_type_style>(style_pair[1]);
|
||||
m.insert_style(name, style);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue