2011-05-16 23:41:34 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/feature_factory.hpp>
|
2010-11-03 16:26:30 +00:00
|
|
|
#include <mapnik/geometry.hpp>
|
2010-10-24 08:04:16 +00:00
|
|
|
|
2011-05-16 23:41:34 +00:00
|
|
|
#include "hello_featureset.hpp"
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding)
|
2011-11-14 03:37:50 +00:00
|
|
|
: box_(box),
|
|
|
|
feature_id_(1),
|
|
|
|
tr_(new mapnik::transcoder(encoding)) { }
|
2010-10-24 08:04:16 +00:00
|
|
|
|
|
|
|
hello_featureset::~hello_featureset() { }
|
|
|
|
|
|
|
|
mapnik::feature_ptr hello_featureset::next()
|
|
|
|
{
|
2011-04-29 20:00:45 +00:00
|
|
|
if (feature_id_ == 1)
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
|
|
|
// create a new feature
|
2011-05-16 23:41:34 +00:00
|
|
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(feature_id_));
|
2011-04-29 20:04:36 +00:00
|
|
|
|
|
|
|
// increment the count so that we only return one feature
|
2011-04-29 20:00:45 +00:00
|
|
|
++feature_id_;
|
2010-10-24 08:04:16 +00:00
|
|
|
|
|
|
|
// create an attribute pair of key:value
|
|
|
|
UnicodeString ustr = tr_->transcode("hello world!");
|
|
|
|
boost::put(*feature,"key",ustr);
|
|
|
|
|
|
|
|
// we need a geometry to display so just for fun here
|
|
|
|
// we take the center of the bbox that was used to query
|
|
|
|
// since we don't actually have any data to pull from...
|
|
|
|
mapnik::coord2d center = box_.center();
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-11-03 16:26:30 +00:00
|
|
|
// create a new point geometry
|
|
|
|
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// we use path type geometries in Mapnik to fit nicely with AGG and Cairo
|
2010-11-03 16:26:30 +00:00
|
|
|
// here we stick an x,y pair into the geometry using move_to()
|
|
|
|
pt->move_to(center.x,center.y);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// add the geometry to the feature
|
2010-11-03 16:26:30 +00:00
|
|
|
feature->add_geometry(pt);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-01-25 02:07:36 +00:00
|
|
|
// A feature usually will have just one geometry of a given type
|
|
|
|
// but mapnik does support many geometries per feature of any type
|
|
|
|
// so here we draw a line around the point
|
|
|
|
mapnik::geometry_type * line = new mapnik::geometry_type(mapnik::LineString);
|
|
|
|
line->move_to(box_.minx(),box_.miny());
|
|
|
|
line->line_to(box_.minx(),box_.maxy());
|
|
|
|
line->line_to(box_.maxx(),box_.maxy());
|
|
|
|
line->line_to(box_.maxx(),box_.miny());
|
|
|
|
line->line_to(box_.minx(),box_.miny());
|
|
|
|
feature->add_geometry(line);
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// return the feature!
|
|
|
|
return feature;
|
|
|
|
}
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2011-01-13 18:51:20 +00:00
|
|
|
// otherwise return an empty feature
|
2010-10-24 08:04:16 +00:00
|
|
|
return mapnik::feature_ptr();
|
|
|
|
}
|
|
|
|
|