Skip to content

Commit

Permalink
move extent to method on datasource
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Apr 12, 2012
1 parent ed07c81 commit 9c6dba3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
9 changes: 0 additions & 9 deletions src/ds_emitter.hpp
Expand Up @@ -31,15 +31,6 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
description->Set(String::NewSymbol("type"), String::New("vector"));
}

// extent
Local<Array> a = Array::New(4);
mapnik::box2d<double> e = ds->envelope();
a->Set(0, Number::New(e.minx()));
a->Set(1, Number::New(e.miny()));
a->Set(2, Number::New(e.maxx()));
a->Set(3, Number::New(e.maxy()));
description->Set(String::NewSymbol("extent"), a);

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

// encoding
Expand Down
14 changes: 14 additions & 0 deletions src/mapnik_datasource.cpp
Expand Up @@ -24,6 +24,7 @@ void Datasource::Initialize(Handle<Object> target) {
NODE_SET_PROTOTYPE_METHOD(constructor, "describe", describe);
NODE_SET_PROTOTYPE_METHOD(constructor, "features", features);
NODE_SET_PROTOTYPE_METHOD(constructor, "featureset", featureset);
NODE_SET_PROTOTYPE_METHOD(constructor, "extent", extent);

target->Set(String::NewSymbol("Datasource"),constructor->GetFunction());
}
Expand Down Expand Up @@ -161,6 +162,19 @@ Handle<Value> Datasource::parameters(const Arguments& args)
return scope.Close(ds);
}

Handle<Value> Datasource::extent(const Arguments& args)
{
HandleScope scope;
Datasource* d = ObjectWrap::Unwrap<Datasource>(args.This());
Local<Array> a = Array::New(4);
mapnik::box2d<double> const& e = d->datasource_->envelope();
a->Set(0, Number::New(e.minx()));
a->Set(1, Number::New(e.miny()));
a->Set(2, Number::New(e.maxx()));
a->Set(3, Number::New(e.maxy()));
return scope.Close(a);
}

Handle<Value> Datasource::describe(const Arguments& args)
{
HandleScope scope;
Expand Down
3 changes: 2 additions & 1 deletion src/mapnik_datasource.hpp
Expand Up @@ -16,11 +16,12 @@ class Datasource: public node::ObjectWrap {
static void Initialize(Handle<Object> target);
static Handle<Value> New(const Arguments &args);
static Handle<Value> New(mapnik::datasource_ptr ds_ptr);

static Handle<Value> parameters(const Arguments &args);
static Handle<Value> describe(const Arguments &args);
static Handle<Value> features(const Arguments &args);

static Handle<Value> featureset(const Arguments &args);
static Handle<Value> extent(const Arguments &args);

Datasource();
inline mapnik::datasource_ptr get() { return datasource_; }
Expand Down
6 changes: 4 additions & 2 deletions test/datasource.test.js
Expand Up @@ -76,10 +76,11 @@ describe('mapnik.Datasource', function() {
}
var actual = ds.describe();
assert.deepEqual(actual['type'],expected['type']);
assert.deepEqual(actual['extent'],expected['extent']);
assert.deepEqual(actual['encoding'],expected['encoding']);
assert.deepEqual(actual['fields'],expected['fields']);
assert.deepEqual(actual['geometry_type'],expected['geometry_type']);

assert.deepEqual(ds.extent(),expected['extent']);
});

it('should validate with known geojson', function() {
Expand Down Expand Up @@ -137,9 +138,10 @@ describe('mapnik.Datasource', function() {
};
var actual = ds.describe();
assert.deepEqual(actual['type'],expected['type']);
assert.deepEqual(actual['extent'],expected['extent']);
assert.deepEqual(actual['encoding'],expected['encoding']);
assert.deepEqual(actual['fields'],expected['fields']);
assert.deepEqual(actual['geometry_type'],expected['geometry_type']);

assert.deepEqual(ds.extent(),expected['extent']);
});
});

0 comments on commit 9c6dba3

Please sign in to comment.