+ implement Map::styles method returning StyleRange object

```
  import mapnik
  m = mapnik.Map(256,256)
  ...
  for style in m.styles:
      print style
  ```
This commit is contained in:
artemp 2013-02-04 18:00:08 +00:00
parent 69e2174524
commit 16ce1f5bdd

View file

@ -24,6 +24,8 @@
#include <boost/python.hpp>
#include <boost/python/detail/api_placeholder.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <boost/python/iterator.hpp>
#include <boost/iterator/transform_iterator.hpp>
// mapnik
#include <mapnik/rule.hpp>
@ -112,6 +114,25 @@ void set_maximum_extent(mapnik::Map & m, boost::optional<mapnik::box2d<double> >
}
}
struct extract_style
{
typedef mapnik::feature_type_style result_type;
result_type operator() (std::map<std::string, mapnik::feature_type_style>::value_type const& val) const
{
return val.second;
}
};
typedef boost::transform_iterator<extract_style, Map::const_style_iterator> style_extract_iterator;
typedef std::pair<style_extract_iterator,style_extract_iterator> style_range;
style_range _styles_ (mapnik::Map const& m)
{
return style_range(
boost::make_transform_iterator<extract_style>(m.begin_styles(), extract_style()),
boost::make_transform_iterator<extract_style>(m.end_styles(), extract_style()));
}
void export_map()
{
using namespace boost::python;
@ -132,6 +153,11 @@ void export_map()
.def(vector_indexing_suite<std::vector<layer> >())
;
class_<style_range>("StyleRange")
.def("__iter__",
range(&style_range::first, &style_range::second))
;
class_<Map>("Map","The map object.",init<int,int,optional<std::string const&> >(
( arg("width"),arg("height"),arg("srs") ),
"Create a Map with a width and height as integers and, optionally,\n"
@ -215,6 +241,8 @@ void export_map()
"<mapnik._mapnik.Style object at 0x654f0>\n"
)
.add_property("styles", _styles_)
.def("pan",&Map::pan,
(arg("x"),arg("y")),
"Set the Map center at a given x,y location\n"