-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhello_featureset.cpp
69 lines (55 loc) · 2.02 KB
/
hello_featureset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// mapnik
#include <mapnik/feature_factory.hpp>
#include <mapnik/value_types.hpp>
// boost
#include "hello_featureset.hpp"
hello_featureset::hello_featureset(mapnik::box2d<double> const& box, std::string const& encoding)
: box_(box),
feature_id_(1),
tr_(new mapnik::transcoder(encoding)),
ctx_(std::make_shared<mapnik::context_type>())
{
// add known field names to attributes schema
ctx_->push("key");
}
hello_featureset::~hello_featureset() { }
mapnik::feature_ptr hello_featureset::next()
{
if (feature_id_ == 1)
{
// create a new 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 point!"));
// take the center of the bbox that was used to query
// to dynamically generate a fake point
mapnik::coord2d center = box_.center();
// create a new point geometry
feature->set_geometry(mapnik::geometry::point<double>(center.x,center.y));
// 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
mapnik::geometry::line_string<double> 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));
return feature;
}
// otherwise return an empty feature
return mapnik::feature_ptr();
}