Skip to content

Commit

Permalink
Added GeoJSON buffer to VectorTile.addGeoJSON. Closes #457
Browse files Browse the repository at this point in the history
  • Loading branch information
flippmoke committed Jul 27, 2015
1 parent 6cc64af commit 62e03e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/mapnik_vector_tile.cpp
Expand Up @@ -2257,6 +2257,7 @@ NAN_METHOD(VectorTile::addGeoJSON)
double area_threshold = 0.1;
double simplify_distance = 0.0;
unsigned path_multiplier = 16;
int buffer_size = 8;

if (args.Length() > 2) {
// options object
Expand Down Expand Up @@ -2293,6 +2294,15 @@ NAN_METHOD(VectorTile::addGeoJSON)
}
simplify_distance = param_val->NumberValue();
}

if (options->Has(NanNew("buffer_size"))) {
Local<Value> bind_opt = options->Get(NanNew("buffer_size"));
if (!bind_opt->IsNumber()) {
NanThrowTypeError("optional arg 'buffer_size' must be a number");
NanReturnUndefined();
}
buffer_size = bind_opt->IntegerValue();
}
}

try
Expand All @@ -2306,7 +2316,7 @@ NAN_METHOD(VectorTile::addGeoJSON)
merc.xyz(d->x_,d->y_,d->z_,minx,miny,maxx,maxy);
map.zoom_to_box(mapnik::box2d<double>(minx,miny,maxx,maxy));
mapnik::request m_req(map.width(),map.height(),map.get_current_extent());
m_req.set_buffer_size(8);
m_req.set_buffer_size(buffer_size);
mapnik::parameters p;
p["type"]="geojson";
p["inline"]=geojson_string;
Expand Down
3 changes: 2 additions & 1 deletion test/vector-tile.test.js
Expand Up @@ -89,6 +89,7 @@ describe('mapnik.VectorTile ', function() {
assert.throws(function() { vtile.addGeoJSON(geo_str, "layer", {area_threshold:null}); });
assert.throws(function() { vtile.addGeoJSON(geo_str, "layer", {path_multiplier:null}); });
assert.throws(function() { vtile.addGeoJSON(geo_str, "layer", {simplify_distance:null}); });
assert.throws(function() { vtile.addGeoJSON(geo_str, "layer", {buffer_size:null}); });
});

it('should be able to create a vector tile from geojson', function(done) {
Expand All @@ -111,7 +112,7 @@ describe('mapnik.VectorTile ', function() {
}
]
};
vtile.addGeoJSON(JSON.stringify(geojson),"layer-name");
vtile.addGeoJSON(JSON.stringify(geojson),"layer-name", {buffer_size:8});
assert.equal(vtile.getData().length,58);
var out = JSON.parse(vtile.toGeoJSON(0));
assert.equal(out.type,'FeatureCollection');
Expand Down

0 comments on commit 62e03e0

Please sign in to comment.