2010-10-24 08:04:16 +00:00
|
|
|
// file plugin
|
|
|
|
#include "hello_datasource.hpp"
|
|
|
|
#include "hello_featureset.hpp"
|
|
|
|
|
2011-05-16 23:41:34 +00:00
|
|
|
// boost
|
|
|
|
#include <boost/make_shared.hpp>
|
|
|
|
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
using mapnik::datasource;
|
|
|
|
using mapnik::parameters;
|
|
|
|
|
|
|
|
DATASOURCE_PLUGIN(hello_datasource)
|
|
|
|
|
2012-03-09 15:33:36 +00:00
|
|
|
hello_datasource::hello_datasource(parameters const& params, bool bind)
|
2011-11-14 03:37:50 +00:00
|
|
|
: datasource(params),
|
2012-03-09 15:33:36 +00:00
|
|
|
desc_(*params_.get<std::string>("type"), *params_.get<std::string>("encoding","utf-8")),
|
2011-11-14 03:37:50 +00:00
|
|
|
extent_()
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (bind)
|
|
|
|
{
|
|
|
|
this->bind();
|
|
|
|
}
|
2010-10-24 08:04:16 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 15:33:36 +00:00
|
|
|
void hello_datasource::bind() const
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (is_bound_) return;
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// every datasource must have some way of reporting its extent
|
|
|
|
// in this case we are not actually reading from any data so for fun
|
|
|
|
// let's just create a world extent in Mapnik's default srs:
|
|
|
|
// '+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs' (equivalent to +init=epsg:4326)
|
|
|
|
// see http://spatialreference.org/ref/epsg/4326/ for more details
|
|
|
|
extent_.init(-180,-90,180,90);
|
2012-03-09 15:33:36 +00:00
|
|
|
|
|
|
|
is_bound_ = true;
|
2010-10-24 08:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hello_datasource::~hello_datasource() { }
|
|
|
|
|
|
|
|
// This name must match the plugin filename, eg 'hello.input'
|
2012-07-21 01:34:41 +00:00
|
|
|
const char * hello_datasource::name()
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
2012-07-21 01:34:41 +00:00
|
|
|
return "hello";
|
2010-10-24 08:04:16 +00:00
|
|
|
}
|
|
|
|
|
2012-01-17 06:09:46 +00:00
|
|
|
mapnik::datasource::datasource_t hello_datasource::type() const
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
2012-01-17 06:09:46 +00:00
|
|
|
return datasource::Vector;
|
2010-10-24 08:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mapnik::box2d<double> hello_datasource::envelope() const
|
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (!is_bound_) bind();
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
return extent_;
|
|
|
|
}
|
|
|
|
|
2012-01-17 06:09:46 +00:00
|
|
|
boost::optional<mapnik::datasource::geometry_t> hello_datasource::get_geometry_type() const
|
|
|
|
{
|
2012-01-17 22:47:27 +00:00
|
|
|
return mapnik::datasource::Point;
|
2012-01-17 06:09:46 +00:00
|
|
|
}
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
mapnik::layer_descriptor hello_datasource::get_descriptor() const
|
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (!is_bound_) bind();
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
return desc_;
|
|
|
|
}
|
|
|
|
|
|
|
|
mapnik::featureset_ptr hello_datasource::features(mapnik::query const& q) const
|
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (!is_bound_) bind();
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// if the query box intersects our world extent then query for features
|
|
|
|
if (extent_.intersects(q.get_bbox()))
|
|
|
|
{
|
2011-05-16 23:41:34 +00:00
|
|
|
return boost::make_shared<hello_featureset>(q.get_bbox(),desc_.get_encoding());
|
2010-10-24 08:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise return an empty featureset pointer
|
|
|
|
return mapnik::featureset_ptr();
|
|
|
|
}
|
|
|
|
|
2012-09-28 13:12:10 +00:00
|
|
|
mapnik::featureset_ptr hello_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
2010-10-24 08:04:16 +00:00
|
|
|
{
|
2012-03-09 15:33:36 +00:00
|
|
|
if (!is_bound_) bind();
|
|
|
|
|
2010-10-24 08:04:16 +00:00
|
|
|
// features_at_point is rarely used - only by custom applications,
|
|
|
|
// so for this sample plugin let's do nothing...
|
|
|
|
return mapnik::featureset_ptr();
|
|
|
|
}
|