2011-05-17 01:41:34 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/feature_factory.hpp>
|
2010-11-03 17:26:30 +01:00
|
|
|
#include <mapnik/geometry.hpp>
|
2013-08-14 00:52:04 +02:00
|
|
|
#include <mapnik/value_types.hpp>
|
2010-10-24 10:04:16 +02:00
|
|
|
|
2013-01-04 18:23:06 +01:00
|
|
|
// boost
|
|
|
|
|
2011-05-17 01:41:34 +02:00
|
|
|
#include "hello_featureset.hpp"
|
|
|
|
|
2010-10-24 10:04:16 +02:00
|
|
|
hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding)
|
2011-11-14 04:37:50 +01:00
|
|
|
: box_(box),
|
|
|
|
feature_id_(1),
|
2012-01-17 23:47:27 +01:00
|
|
|
tr_(new mapnik::transcoder(encoding)),
|
2013-09-20 15:00:11 +02:00
|
|
|
ctx_(std::make_shared<mapnik::context_type>()) { }
|
2010-10-24 10:04:16 +02:00
|
|
|
|
|
|
|
hello_featureset::~hello_featureset() { }
|
|
|
|
|
|
|
|
mapnik::feature_ptr hello_featureset::next()
|
|
|
|
{
|
2011-04-29 22:00:45 +02:00
|
|
|
if (feature_id_ == 1)
|
2010-10-24 10:04:16 +02:00
|
|
|
{
|
2012-07-10 23:51:13 +02:00
|
|
|
// let us pretend it just has one column/attribute name
|
|
|
|
std::string attribute("key");
|
|
|
|
|
|
|
|
// the featureset context needs to know the field schema
|
|
|
|
ctx_->push(attribute);
|
|
|
|
|
2010-10-24 10:04:16 +02:00
|
|
|
// create a new feature
|
2012-01-17 23:47:27 +01:00
|
|
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
2011-04-29 22:04:36 +02:00
|
|
|
|
|
|
|
// increment the count so that we only return one feature
|
2011-04-29 22:00:45 +02:00
|
|
|
++feature_id_;
|
2010-10-24 10:04:16 +02:00
|
|
|
|
|
|
|
// create an attribute pair of key:value
|
2013-08-14 00:52:04 +02:00
|
|
|
mapnik::value_unicode_string ustr = tr_->transcode("hello world!");
|
2012-07-10 23:51:13 +02:00
|
|
|
feature->put(attribute,ustr);
|
2010-10-24 10:04:16 +02:00
|
|
|
|
|
|
|
// 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 04:37:50 +01:00
|
|
|
|
2010-11-03 17:26:30 +01:00
|
|
|
// create a new point geometry
|
2015-02-23 19:36:48 +01:00
|
|
|
feature->set_geometry(mapnik::new_geometry::point(center.x,center.y));
|
2011-11-14 04:37:50 +01:00
|
|
|
|
2011-01-25 03:07:36 +01:00
|
|
|
// A feature usually will have just one geometry of a given type
|
2015-02-23 19:36:48 +01:00
|
|
|
// but mapnik supports many geometries per feature of any type
|
2011-01-25 03:07:36 +01:00
|
|
|
// so here we draw a line around the point
|
2015-02-23 19:36:48 +01:00
|
|
|
mapnik::new_geometry::line_string line;
|
|
|
|
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));
|
2011-11-14 04:37:50 +01:00
|
|
|
|
2010-10-24 10:04:16 +02:00
|
|
|
// return the feature!
|
|
|
|
return feature;
|
|
|
|
}
|
2011-11-14 04:37:50 +01:00
|
|
|
|
2011-01-13 19:51:20 +01:00
|
|
|
// otherwise return an empty feature
|
2010-10-24 10:04:16 +02:00
|
|
|
return mapnik::feature_ptr();
|
|
|
|
}
|