diff --git a/README.md b/README.md index 5c0c199133..30fb04df0b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/ds_emitter.hpp b/src/ds_emitter.hpp index 4b82c718ca..417980df41 100644 --- a/src/ds_emitter.hpp +++ b/src/ds_emitter.hpp @@ -11,6 +11,7 @@ #include #include #include +#include using namespace v8; using namespace node; @@ -177,17 +178,16 @@ static void datasource_features(Local a, mapnik::datasource_ptr ds, unsig unsigned idx = 0; while ((fp = fs->next())) { - if ((idx >= first) && (idx <= last || last == 0)) { - std::map const& fprops = fp->props(); + if ((idx >= first) && (idx <= last || last == 0)) { Local feat = Object::New(); - std::map::const_iterator it = fprops.begin(); - std::map::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 diff --git a/src/mapnik_feature.cpp b/src/mapnik_feature.cpp index c3c4e32394..1ecc2789c4 100644 --- a/src/mapnik_feature.cpp +++ b/src/mapnik_feature.cpp @@ -5,6 +5,7 @@ // mapnik #include #include +#include // boost #include @@ -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(); + this_ = mapnik::feature_factory::create(ctx_,id); + } + Feature::~Feature() { } @@ -57,6 +62,8 @@ Handle 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( @@ -110,13 +117,13 @@ Handle Feature::attributes(const Arguments& args) Local feat = Object::New(); - std::map const& fprops = fp->get()->props(); - std::map::const_iterator it = fprops.begin(); - std::map::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); @@ -195,16 +202,16 @@ Handle Feature::addAttributes(const Arguments& args) Local 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"; diff --git a/src/mapnik_feature.hpp b/src/mapnik_feature.hpp index 40a82f6ca9..6838fb132c 100644 --- a/src/mapnik_feature.hpp +++ b/src/mapnik_feature.hpp @@ -40,6 +40,7 @@ class Feature: public node::ObjectWrap { private: ~Feature(); mapnik::feature_ptr this_; + mapnik::context_ptr ctx_; }; #endif diff --git a/src/mapnik_memory_datasource.cpp b/src/mapnik_memory_datasource.cpp index b7a192da85..11e9c1f5e9 100644 --- a/src/mapnik_memory_datasource.cpp +++ b/src/mapnik_memory_datasource.cpp @@ -241,7 +241,8 @@ Handle 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::feature_ptr feature(mapnik::feature_factory::create(ctx,d->feature_id_)); ++(d->feature_id_); feature->add_geometry(pt); if (obj->Has(String::New("properties"))) @@ -260,16 +261,16 @@ Handle MemoryDatasource::add(const Arguments& args) Local 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"; diff --git a/src/mem_datasource.hpp b/src/mem_datasource.hpp index 96b271efdf..5283df5ebb 100644 --- a/src/mem_datasource.hpp +++ b/src/mem_datasource.hpp @@ -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::feature_ptr feature(mapnik::feature_factory::create(ctx,feature_id_)); ++feature_id_; feature->add_geometry(pt); if (obj->Has(String::New("properties"))) @@ -158,16 +159,16 @@ class js_featureset : public mapnik::Featureset, private boost::noncopyable Local 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++;