2011-05-16 23:41:34 +00:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/feature_factory.hpp>
|
2013-08-13 22:52:04 +00:00
|
|
|
#include <mapnik/value_types.hpp>
|
2010-10-24 08:04:16 +00:00
|
|
|
|
2013-01-04 17:23:06 +00:00
|
|
|
// boost
|
|
|
|
|
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),
|
2012-01-17 22:47:27 +00:00
|
|
|
tr_(new mapnik::transcoder(encoding)),
|
2015-02-23 19:43:32 +00:00
|
|
|
ctx_(std::make_shared<mapnik::context_type>()) {
|
|
|
|
// add known field names to attributes schema
|
|
|
|
ctx_->push("key");
|
|
|
|
}
|
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
|
2012-01-17 22:47:27 +00:00
|
|
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
2011-04-29 20:04:36 +00:00
|
|
|
|
2015-02-23 19:43:32 +00:00
|
|
|
// increment the count
|
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
|
2015-02-23 19:43:32 +00:00
|
|
|
feature->put("key",tr_->transcode("hello world point!"));
|
2010-10-24 08:04:16 +00:00
|
|
|
|
2015-02-23 19:43:32 +00:00
|
|
|
// take the center of the bbox that was used to query
|
|
|
|
// to dynamically generate a fake point
|
2010-10-24 08:04:16 +00:00
|
|
|
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
|
2015-03-24 13:21:28 +00:00
|
|
|
feature->set_geometry(mapnik::geometry::point(center.x,center.y));
|
2011-11-14 03:37:50 +00:00
|
|
|
|
2015-02-23 19:43:32 +00:00
|
|
|
// return the feature!
|
|
|
|
return feature;
|
|
|
|
}
|
|
|
|
else if (feature_id_ == 2)
|
|
|
|
{
|
|
|
|
// create a second feature
|
|
|
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
|
|
|
|
|
|
|
// increment the count
|
|
|
|
++feature_id_;
|
|
|
|
|
|
|
|
// create an attribute pair of key:value
|
|
|
|
feature->put("key",tr_->transcode("hello world line!"));
|
|
|
|
|
|
|
|
// take the outer ring of the bbox that was used to query
|
|
|
|
// to dynamically generate a fake line
|
2015-03-24 13:21:28 +00:00
|
|
|
mapnik::geometry::line_string line;
|
2015-02-23 18:36:48 +00:00
|
|
|
line.reserve(4);
|
|
|
|
line.add_coord(box_.minx(),box_.maxy());
|
|
|
|
line.add_coord(box_.maxx(),box_.maxy());
|
|
|
|
line.add_coord(box_.maxx(),box_.miny());
|
|
|
|
line.add_coord(box_.minx(),box_.miny());
|
|
|
|
feature->set_geometry(std::move(line));
|
2010-10-24 08:04:16 +00:00
|
|
|
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();
|
|
|
|
}
|