From 771e76f6376f73496f721354b23c6b0331963199 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Sun, 15 Feb 2009 19:53:48 +0000 Subject: [PATCH] + add style pickling support to mapnik::Map, fix tabs, and only un-pickle background color if exists (closes 233) --- bindings/python/mapnik_map.cpp | 73 +++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/bindings/python/mapnik_map.cpp b/bindings/python/mapnik_map.cpp index 301655c8f..0c103ed5b 100644 --- a/bindings/python/mapnik_map.cpp +++ b/bindings/python/mapnik_map.cpp @@ -28,6 +28,7 @@ #include #include +#include #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;ifirst; + 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 ext = extract >(state[0]); - color bg = extract(state[1]); - m.zoomToBox(ext); - m.set_background(bg); - boost::python::list l=extract(state[2]); - for (int i=0;i(l[i])); - } + throw_error_already_set(); + } + + Envelope ext = extract >(state[0]); + m.zoomToBox(ext); + if (state[1]) + { + color bg = extract(state[1]); + m.set_background(bg); + } + + boost::python::list l=extract(state[2]); + for (int i=0;i(l[i])); + } + + boost::python::list s=extract(state[3]); + for (int i=0;i(s[i]); + std::string name = extract(style_pair[0]); + mapnik::feature_type_style style = extract(style_pair[1]); + m.insert_style(name, style); + } } };