Skip to content

Commit

Permalink
Ported to NAN 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoopa committed Jun 12, 2014
1 parent bb6b58e commit 203fb38
Show file tree
Hide file tree
Showing 45 changed files with 3,415 additions and 3,227 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ compiler:

env:
matrix:
- NODE_NVM_VERSION="0.11"
- NODE_NVM_VERSION="0.10"
- NODE_NVM_VERSION="0.8"
global:
Expand Down
5 changes: 3 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@
'include_dirs': [
'./node_modules/mapnik-vector-tile/src/',
'<(SHARED_INTERMEDIATE_DIR)/',
'./src'
'./src',
"<!(node -e \"require('nan')\")"
],
'conditions': [
['OS=="win"', {
Expand Down Expand Up @@ -173,4 +174,4 @@
]
}
]
}
}
89 changes: 46 additions & 43 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,58 +1,61 @@
{
"name" : "mapnik",
"description" : "Tile rendering library for node",
"url" : "http://github.com/mapnik/node-mapnik",
"homepage" : "http://mapnik.org",
"author" : "Dane Springmeyer <dane@dbsgeo.com> (mapnik.org)",
"version" : "1.4.3",
"main" : "./lib/mapnik.js",
"name": "mapnik",
"description": "Tile rendering library for node",
"url": "http://github.com/mapnik/node-mapnik",
"homepage": "http://mapnik.org",
"author": "Dane Springmeyer <dane@dbsgeo.com> (mapnik.org)",
"version": "1.4.3",
"main": "./lib/mapnik.js",
"binary": {
"module_name": "mapnik",
"module_path": "./lib/binding/",
"remote_path": "v{version}",
"host": "https://node-mapnik.s3-us-west-1.amazonaws.com"
"module_name": "mapnik",
"module_path": "./lib/binding/",
"remote_path": "v{version}",
"host": "https://node-mapnik.s3-us-west-1.amazonaws.com"
},
"bugs" : {
"email" : "dane@dbsgeo.com",
"url" : "http://github.com/mapnik/node-mapnik/issues"
"bugs": {
"email": "dane@dbsgeo.com",
"url": "http://github.com/mapnik/node-mapnik/issues"
},
"keywords" : [
"map",
"graphics",
"canvas",
"tile",
"mapnik",
"carto"
"keywords": [
"map",
"graphics",
"canvas",
"tile",
"mapnik",
"carto"
],
"repository" : {
"type" : "git",
"url" : "git://github.com/mapnik/node-mapnik.git"
"repository": {
"type": "git",
"url": "git://github.com/mapnik/node-mapnik.git"
},
"contributors" : ["Konstantin Käfer"],
"licenses" : [
{
"type": "BSD",
"url": "https://github.com/mapnik/node-mapnik/blob/master/LICENSE.txt"
}
"contributors": [
"Konstantin Käfer"
],
"dependencies" : {
"mapnik-vector-tile": "0.4.2",
"node-pre-gyp":"~0.5.0"
"licenses": [
{
"type": "BSD",
"url": "https://github.com/mapnik/node-mapnik/blob/master/LICENSE.txt"
}
],
"dependencies": {
"mapnik-vector-tile": "0.4.2",
"nan": "~1.2.0",
"node-pre-gyp": "~0.5.0"
},
"bundledDependencies": [
"mapnik-vector-tile",
"node-pre-gyp"
"mapnik-vector-tile",
"node-pre-gyp"
],
"bin" : {
"mapnik-inspect.js" : "./bin/mapnik-inspect.js",
"mapnik-render.js" : "./bin/mapnik-render.js"
"bin": {
"mapnik-inspect.js": "./bin/mapnik-inspect.js",
"mapnik-render.js": "./bin/mapnik-render.js"
},
"engines" : {
"node": ">= 0.8.0 < 0.11.4"
"engines": {
"node": ">= 0.8.0 < 0.11.4"
},
"scripts" : {
"test" : "mocha",
"install": "node-pre-gyp install --fallback-to-build"
"scripts": {
"test": "mocha",
"install": "node-pre-gyp install --fallback-to-build"
},
"devDependencies": {
"sphericalmercator": "~1.0.2",
Expand Down
49 changes: 22 additions & 27 deletions src/ds_emitter.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __NODE_MAPNIK_DS_EMITTER_H__
#define __NODE_MAPNIK_DS_EMITTER_H__

// v8
#include <v8.h>

#include "utils.hpp"

// mapnik
Expand All @@ -21,25 +18,26 @@ namespace node_mapnik {

static void describe_datasource(Local<Object> description, mapnik::datasource_ptr ds)
{
NanScope();
try
{
// type
if (ds->type() == mapnik::datasource::Raster)
{
description->Set(String::NewSymbol("type"), String::New("raster"));
description->Set(NanNew("type"), NanNew<String>("raster"));
}
else
{
description->Set(String::NewSymbol("type"), String::New("vector"));
description->Set(NanNew("type"), NanNew<String>("vector"));
}

mapnik::layer_descriptor ld = ds->get_descriptor();

// encoding
description->Set(String::NewSymbol("encoding"), String::New(ld.get_encoding().c_str()));
description->Set(NanNew("encoding"), NanNew<String>(ld.get_encoding().c_str()));

// field names and types
Local<Object> fields = Object::New();
Local<Object> fields = NanNew<Object>();
std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
std::vector<mapnik::attribute_descriptor>::const_iterator itr = desc.begin();
std::vector<mapnik::attribute_descriptor>::const_iterator end = desc.end();
Expand All @@ -55,15 +53,16 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
else if (field_type == mapnik::Geometry) type = "Geometry";
else if (field_type == mapnik::Object) type = "Object";
else type = "Unknown";
fields->Set(String::NewSymbol(itr->get_name().c_str()),String::New(type.c_str()));
fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
++itr;
}
description->Set(String::NewSymbol("fields"), fields);
description->Set(NanNew("fields"), fields);

Local<String> js_type = String::New("unknown");
Local<String> js_type = NanNew<String>("unknown");
if (ds->type() == mapnik::datasource::Raster)
{
js_type = String::New("raster");
js_type = NanNew<String>("raster");
}
else
{
Expand All @@ -76,22 +75,22 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
{
case mapnik::datasource::Point:
{
js_type = String::New("point");
js_type = NanNew<String>("point");
break;
}
case mapnik::datasource::LineString:
{
js_type = String::New("linestring");
js_type = NanNew<String>("linestring");
break;
}
case mapnik::datasource::Polygon:
{
js_type = String::New("polygon");
js_type = NanNew<String>("polygon");
break;
}
case mapnik::datasource::Collection:
{
js_type = String::New("collection");
js_type = NanNew<String>("collection");
break;
}
default:
Expand All @@ -102,24 +101,22 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
}
#endif
}
description->Set(String::NewSymbol("geometry_type"), js_type);
description->Set(NanNew("geometry_type"), js_type);
}
catch (std::exception const& ex)
{
ThrowException(Exception::Error(
String::New(ex.what())));
NanThrowError(ex.what());
}
catch (...)
{
ThrowException(Exception::Error(
String::New("unknown exception happened when calling describe_datasource, please file bug")));
NanThrowError("unknown exception happened when calling describe_datasource, please file bug");
}
}


static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsigned first, unsigned last)
{

NanScope();
try
{
mapnik::query q(ds->envelope());
Expand All @@ -141,7 +138,7 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
while ((fp = fs->next()))
{
if ((idx >= first) && (idx <= last || last == 0)) {
Local<Object> feat = Object::New();
Local<Object> feat = NanNew<Object>();
#if MAPNIK_VERSION >= 200100
mapnik::feature_impl::iterator f_itr = fp->begin();
mapnik::feature_impl::iterator f_end = fp->end();
Expand All @@ -165,7 +162,7 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
}
#endif
// add feature id
feat->Set(String::NewSymbol("__id__"), Number::New(fp->id()));
feat->Set(NanNew("__id__"), NanNew<Number>(fp->id()));

a->Set(idx, feat);
}
Expand All @@ -175,13 +172,11 @@ static void datasource_features(Local<Array> a, mapnik::datasource_ptr ds, unsig
}
catch (std::exception const& ex)
{
ThrowException(Exception::Error(
String::New(ex.what())));
NanThrowError(ex.what());
}
catch (...)
{
ThrowException(Exception::Error(
String::New("unknown exception happened when calling datasource_features, please file bug")));
NanThrowError("unknown exception happened when calling datasource_features, please file bug");
}

}
Expand Down
23 changes: 12 additions & 11 deletions src/js_grid_utils.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __NODE_MAPNIK_GRID_UTILS_H__
#define __NODE_MAPNIK_GRID_UTILS_H__

// v8
#include <v8.h>

// mapnik
#include <mapnik/feature.hpp> // for feature_impl, etc
#include <mapnik/grid/grid.hpp> // for grid
Expand Down Expand Up @@ -155,6 +152,7 @@ static void write_features(T const& grid_type,
Local<Object>& feature_data,
std::vector<typename T::lookup_type> const& key_order)
{
NanScope();
typename T::feature_type const& g_features = grid_type.get_grid_features();
if (g_features.size() <= 0)
{
Expand All @@ -176,27 +174,27 @@ static void write_features(T const& grid_type,
}

bool found = false;
Local<Object> feat = Object::New();
Local<Object> feat = NanNew<Object>();
mapnik::feature_ptr feature = feat_itr->second;
BOOST_FOREACH ( std::string const& attr, attributes )
{
if (attr == "__id__")
{
feat->Set(String::NewSymbol(attr.c_str()),Integer::New(feature->id()));
feat->Set(NanNew(attr.c_str()), NanNew<Integer>(feature->id()));
}
else if (feature->has_key(attr))
{
found = true;
mapnik::feature_impl::value_type const& attr_val = feature->get(attr);
feat->Set(String::NewSymbol(attr.c_str()),
feat->Set(NanNew(attr.c_str()),
boost::apply_visitor(node_mapnik::value_converter(),
attr_val.base()));
}
}

if (found)
{
feature_data->Set(String::NewSymbol(feat_itr->first.c_str()), feat);
feature_data->Set(NanNew(feat_itr->first.c_str()), feat);
}
}
}
Expand All @@ -210,6 +208,7 @@ static void grid2utf(T const& grid_type,
Local<Array>& l,
std::vector<typename T::lookup_type>& key_order)
{
NanScope();
typedef std::map< typename T::lookup_type, typename T::value_type> keys_type;
typedef typename keys_type::const_iterator keys_iterator;

Expand Down Expand Up @@ -254,7 +253,7 @@ static void grid2utf(T const& grid_type,
}
// else, shouldn't get here...
}
l->Set(row_idx, String::New(line.get(),array_size));
l->Set(row_idx, NanNew<String>(line.get(),array_size));
++row_idx;
}
}
Expand All @@ -267,6 +266,7 @@ static void grid2utf(T const& grid_type,
std::vector<typename T::lookup_type>& key_order,
unsigned int resolution)
{
NanScope();
typedef std::map< typename T::lookup_type, typename T::value_type> keys_type;
typedef typename keys_type::const_iterator keys_iterator;

Expand Down Expand Up @@ -311,7 +311,7 @@ static void grid2utf(T const& grid_type,
}
// else, shouldn't get here...
}
l->Set(row_idx, String::New(line.get(),array_size));
l->Set(row_idx, NanNew<String>(line.get(),array_size));
++row_idx;
}
}
Expand All @@ -322,6 +322,7 @@ static void write_features(T const& grid_type,
Local<Object>& feature_data,
std::vector<typename T::lookup_type> const& key_order)
{
NanScope();
std::string const& key = grid_type.get_key();
std::set<std::string> const& attributes = grid_type.property_names();
typename T::feature_type const& g_features = grid_type.get_grid_features();
Expand All @@ -340,7 +341,7 @@ static void write_features(T const& grid_type,
// only serialize features visible in the grid
if(std::find(key_order.begin(), key_order.end(), join_value) != key_order.end())
{
Local<Object> feat = Object::New();
Local<Object> feat = NanNew<Object>();
std::map<std::string,mapnik::value>::const_iterator it = props.begin();
std::map<std::string,mapnik::value>::const_iterator end = props.end();
bool found = false;
Expand All @@ -358,7 +359,7 @@ static void write_features(T const& grid_type,

if (found)
{
feature_data->Set(String::NewSymbol(feat_itr->first.c_str()), feat);
feature_data->Set(NanNew(feat_itr->first.c_str()), feat);
}
}
}
Expand Down
Loading

0 comments on commit 203fb38

Please sign in to comment.