don't use geom collection, instead diff geom per feature
This commit is contained in:
parent
20e7340699
commit
568d3cbf41
1 changed files with 24 additions and 18 deletions
|
@ -11,7 +11,10 @@ hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string
|
||||||
: box_(box),
|
: box_(box),
|
||||||
feature_id_(1),
|
feature_id_(1),
|
||||||
tr_(new mapnik::transcoder(encoding)),
|
tr_(new mapnik::transcoder(encoding)),
|
||||||
ctx_(std::make_shared<mapnik::context_type>()) { }
|
ctx_(std::make_shared<mapnik::context_type>()) {
|
||||||
|
// add known field names to attributes schema
|
||||||
|
ctx_->push("key");
|
||||||
|
}
|
||||||
|
|
||||||
hello_featureset::~hello_featureset() { }
|
hello_featureset::~hello_featureset() { }
|
||||||
|
|
||||||
|
@ -19,33 +22,38 @@ mapnik::feature_ptr hello_featureset::next()
|
||||||
{
|
{
|
||||||
if (feature_id_ == 1)
|
if (feature_id_ == 1)
|
||||||
{
|
{
|
||||||
// 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);
|
|
||||||
|
|
||||||
// create a new feature
|
// create a new feature
|
||||||
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
|
||||||
|
|
||||||
// increment the count so that we only return one feature
|
// increment the count
|
||||||
++feature_id_;
|
++feature_id_;
|
||||||
|
|
||||||
// create an attribute pair of key:value
|
// create an attribute pair of key:value
|
||||||
mapnik::value_unicode_string ustr = tr_->transcode("hello world!");
|
feature->put("key",tr_->transcode("hello world point!"));
|
||||||
feature->put(attribute,ustr);
|
|
||||||
|
|
||||||
// we need a geometry to display so just for fun here
|
// take the center of the bbox that was used to query
|
||||||
// we take the center of the bbox that was used to query
|
// to dynamically generate a fake point
|
||||||
// since we don't actually have any data to pull from...
|
|
||||||
mapnik::coord2d center = box_.center();
|
mapnik::coord2d center = box_.center();
|
||||||
|
|
||||||
// create a new point geometry
|
// create a new point geometry
|
||||||
feature->set_geometry(mapnik::new_geometry::point(center.x,center.y));
|
feature->set_geometry(mapnik::new_geometry::point(center.x,center.y));
|
||||||
|
|
||||||
// A feature usually will have just one geometry of a given type
|
// return the feature!
|
||||||
// but mapnik supports many geometries per feature of any type
|
return feature;
|
||||||
// so here we draw a line around the point
|
}
|
||||||
|
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
|
||||||
mapnik::new_geometry::line_string line;
|
mapnik::new_geometry::line_string line;
|
||||||
line.reserve(4);
|
line.reserve(4);
|
||||||
line.add_coord(box_.minx(),box_.maxy());
|
line.add_coord(box_.minx(),box_.maxy());
|
||||||
|
@ -53,8 +61,6 @@ mapnik::feature_ptr hello_featureset::next()
|
||||||
line.add_coord(box_.maxx(),box_.miny());
|
line.add_coord(box_.maxx(),box_.miny());
|
||||||
line.add_coord(box_.minx(),box_.miny());
|
line.add_coord(box_.minx(),box_.miny());
|
||||||
feature->set_geometry(std::move(line));
|
feature->set_geometry(std::move(line));
|
||||||
|
|
||||||
// return the feature!
|
|
||||||
return feature;
|
return feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue