Skip to content

Commit

Permalink
adapt to evolving feature interface upstream in mapnik master
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Feb 1, 2012
1 parent 0345b66 commit 9e1ae94
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -49,7 +49,7 @@ For more sample code see 'examples/README.md'
## Depends

* Node >= v0.6.0
* Mapnik 2.1 (current master): (at least [e8541e1685](https://github.com/mapnik/mapnik/commit/e8541e168514ce1175bc6fe8e85db258e6f20c15) / January 9, 2012)
* Mapnik 2.1-dev (current master): (at least [30bef5c955e](https://github.com/mapnik/mapnik/commit/30bef5c955e54290f7b45073a8bdff45e87dff26) / February 1, 2012)


## Installation
Expand Down
14 changes: 7 additions & 7 deletions src/ds_emitter.hpp
Expand Up @@ -11,6 +11,7 @@
#include <mapnik/layer.hpp>
#include <mapnik/params.hpp>
#include <mapnik/feature_layer_desc.hpp>
#include <mapnik/feature_kv_iterator.hpp>

using namespace v8;
using namespace node;
Expand Down Expand Up @@ -177,17 +178,16 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
unsigned idx = 0;
while ((fp = fs->next()))
{
if ((idx >= first) && (idx <= last || last == 0)) {
std::map<std::string,mapnik::value> const& fprops = fp->props();
if ((idx >= first) && (idx <= last || last == 0)) {
Local<Object> feat = Object::New();
std::map<std::string,mapnik::value>::const_iterator it = fprops.begin();
std::map<std::string,mapnik::value>::const_iterator end = fprops.end();
for (; it != end; ++it)
mapnik::feature_kv_iterator itr = fp->begin();
mapnik::feature_kv_iterator end = fp->end();
for ( ;itr!=end; ++itr)
{
node_mapnik::params_to_object serializer( feat , it->first);
node_mapnik::params_to_object serializer( feat , boost::get<0>(*itr));
// need to call base() since this is a mapnik::value
// not a mapnik::value_holder
boost::apply_visitor( serializer, it->second.base() );
boost::apply_visitor( serializer, boost::get<1>(*itr).base() );
}

// add feature id
Expand Down
29 changes: 18 additions & 11 deletions src/mapnik_feature.cpp
Expand Up @@ -5,6 +5,7 @@
// mapnik
#include <mapnik/unicode.hpp>
#include <mapnik/feature_factory.hpp>
#include <mapnik/feature_kv_iterator.hpp>

// boost
#include <boost/scoped_ptr.hpp>
Expand Down Expand Up @@ -36,8 +37,12 @@ Feature::Feature(mapnik::feature_ptr f) :

Feature::Feature(int id) :
ObjectWrap(),
this_(mapnik::feature_factory::create(id)) {}

this_() {
// TODO - accept/require context object to reused
ctx_ = boost::make_shared<mapnik::context_type>();
this_ = mapnik::feature_factory::create(ctx_,id);
}

Feature::~Feature()
{
}
Expand All @@ -57,6 +62,8 @@ Handle<Value> Feature::New(const Arguments& args)
f->Wrap(args.This());
return args.This();
}

// TODO - expose mapnik.Context

if (!args.Length() == 1 || !args[0]->IsNumber()) {
return ThrowException(Exception::TypeError(
Expand Down Expand Up @@ -110,13 +117,13 @@ Handle<Value> Feature::attributes(const Arguments& args)

Local<Object> feat = Object::New();

std::map<std::string,mapnik::value> const& fprops = fp->get()->props();
std::map<std::string,mapnik::value>::const_iterator it = fprops.begin();
std::map<std::string,mapnik::value>::const_iterator end = fprops.end();
for (; it != end; ++it)
mapnik::feature_ptr feature = fp->get();
mapnik::feature_kv_iterator itr = feature->begin();
mapnik::feature_kv_iterator end = feature->end();
for ( ;itr!=end; ++itr)
{
node_mapnik::params_to_object serializer( feat , it->first);
boost::apply_visitor( serializer, it->second.base() );
node_mapnik::params_to_object serializer( feat , boost::get<0>(*itr));
boost::apply_visitor( serializer, boost::get<1>(*itr).base() );
}

return scope.Close(feat);
Expand Down Expand Up @@ -195,16 +202,16 @@ Handle<Value> Feature::addAttributes(const Arguments& args)
Local<Value> value = attr->Get(name);
if (value->IsString()) {
UnicodeString ustr = tr->transcode(TOSTR(value));
boost::put(*fp->get(),TOSTR(name),ustr);
fp->get()->put_new(TOSTR(name),ustr);
} else if (value->IsNumber()) {
double num = value->NumberValue();
// todo - round
if (num == value->IntegerValue()) {
int integer = value->IntegerValue();
boost::put(*fp->get(),TOSTR(name),integer);
fp->get()->put_new(TOSTR(name),integer);
} else {
double dub_val = value->NumberValue();
boost::put(*fp->get(),TOSTR(name),dub_val);
fp->get()->put_new(TOSTR(name),dub_val);
}
} else {
std::clog << "unhandled type for property: " << TOSTR(name) << "\n";
Expand Down
1 change: 1 addition & 0 deletions src/mapnik_feature.hpp
Expand Up @@ -40,6 +40,7 @@ class Feature: public node::ObjectWrap {
private:
~Feature();
mapnik::feature_ptr this_;
mapnik::context_ptr ctx_;
};

#endif
9 changes: 5 additions & 4 deletions src/mapnik_memory_datasource.cpp
Expand Up @@ -241,7 +241,8 @@ Handle<Value> MemoryDatasource::add(const Arguments& args)
{
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
pt->move_to(x->NumberValue(),y->NumberValue());
mapnik::feature_ptr feature(mapnik::feature_factory::create(d->feature_id_));
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,d->feature_id_));
++(d->feature_id_);
feature->add_geometry(pt);
if (obj->Has(String::New("properties")))
Expand All @@ -260,16 +261,16 @@ Handle<Value> MemoryDatasource::add(const Arguments& args)
Local<Value> value = p_obj->Get(name);
if (value->IsString()) {
UnicodeString ustr = d->tr_->transcode(TOSTR(value));
boost::put(*feature,TOSTR(name),ustr);
feature->put_new(TOSTR(name),ustr);
} else if (value->IsNumber()) {
double num = value->NumberValue();
// todo - round
if (num == value->IntegerValue()) {
int integer = value->IntegerValue();
boost::put(*feature,TOSTR(name),integer);
feature->put_new(TOSTR(name),integer);
} else {
double dub_val = value->NumberValue();
boost::put(*feature,TOSTR(name),dub_val);
feature->put_new(TOSTR(name),dub_val);
}
} else {
std::clog << "unhandled type for property: " << TOSTR(name) << "\n";
Expand Down
9 changes: 5 additions & 4 deletions src/mem_datasource.hpp
Expand Up @@ -139,7 +139,8 @@ class js_featureset : public mapnik::Featureset, private boost::noncopyable
{
mapnik::geometry_type * pt = new mapnik::geometry_type(mapnik::Point);
pt->move_to(x->NumberValue(),y->NumberValue());
mapnik::feature_ptr feature(mapnik::feature_factory::create(feature_id_));
mapnik::context_ptr ctx = boost::make_shared<mapnik::context_type>();
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,feature_id_));
++feature_id_;
feature->add_geometry(pt);
if (obj->Has(String::New("properties")))
Expand All @@ -158,16 +159,16 @@ class js_featureset : public mapnik::Featureset, private boost::noncopyable
Local<Value> value = p_obj->Get(name);
if (value->IsString()) {
UnicodeString ustr = tr_->transcode(TOSTR(value));
boost::put(*feature,TOSTR(name),ustr);
feature->put_new(TOSTR(name),ustr);
} else if (value->IsNumber()) {
double num = value->NumberValue();
// todo - round
if (num == value->IntegerValue()) {
int integer = value->IntegerValue();
boost::put(*feature,TOSTR(name),integer);
feature->put_new(TOSTR(name),integer);
} else {
double dub_val = value->NumberValue();
boost::put(*feature,TOSTR(name),dub_val);
feature->put_new(TOSTR(name),dub_val);
}
}
i++;
Expand Down

0 comments on commit 9e1ae94

Please sign in to comment.