require 'ratio' in mbgl.Map options, mbgl::Update::Dimensions in main thread

This commit is contained in:
Mike Morris
2015-08-20 16:41:05 -04:00
parent 783b6de305
commit a8d9b921d7
6 changed files with 25 additions and 5 deletions

View File

@@ -66,7 +66,7 @@ NAN_METHOD(NodeMap::New) {
auto options = args[0]->ToObject();
// Check that request() and cancel() are defined.
// Check that 'request', 'cancel' and 'ratio' are defined.
if (!options->Has(NanNew("request")) || !options->Get(NanNew("request"))->IsFunction()) {
return NanThrowError("Options object must have a 'request' method");
}
@@ -74,6 +74,10 @@ NAN_METHOD(NodeMap::New) {
return NanThrowError("Options object 'cancel' property must be a function");
}
if (!options->Has(NanNew("ratio")) || !options->Get(NanNew("ratio"))->IsNumber()) {
return NanThrowError("Options object must have a numerical 'ratio' property");
}
try {
auto nodeMap = new NodeMap(options);
nodeMap->Wrap(args.This());
@@ -193,6 +197,7 @@ NAN_METHOD(NodeMap::Render) {
void NodeMap::startRender(std::unique_ptr<NodeMap::RenderOptions> options) {
view.resize(options->width, options->height);
map->update(mbgl::Update::Dimensions);
map->setClasses(options->classes);
map->setLatLngZoom(mbgl::LatLng(options->latitude, options->longitude), options->zoom);
map->setBearing(options->bearing);
@@ -319,7 +324,7 @@ void NodeMap::release() {
// Instance
NodeMap::NodeMap(v8::Handle<v8::Object> options) :
view(sharedDisplay(), 1.0),
view(sharedDisplay(), options->Get(NanNew("ratio"))->NumberValue()),
fs(options),
map(std::make_unique<mbgl::Map>(view, fs, mbgl::MapMode::Still)),
async(new uv_async_t) {

View File

@@ -24,6 +24,7 @@ function renderTest(style, info, dir, key) {
});
};
options.cancel = function() {};
options.ratio = 1.0;
var map = new mbgl.Map(options);
map.load(style);
@@ -50,7 +51,7 @@ function rewriteLocalSchema(uri) {
return uri.replace(/^local:\/\//, '');
}
test('Concurrency', function(t) {
test('Consecutive', function(t) {
var dir = 'line-join';
var k = 'round';

View File

@@ -50,7 +50,8 @@ function getOptions(gzip, t) {
response.data = res.body;
req.respond(null, response);
});
}
},
ratio: 1.0
};
}

View File

@@ -65,6 +65,16 @@ test('Map', function(t) {
}, /Options object 'cancel' property must be a function/);
options.cancel = function() {};
t.throws(function() {
new mbgl.Map(options);
}, /Options object must have a numerical 'ratio' property/);
options.ratio = 'test';
t.throws(function() {
new mbgl.Map(options);
}, /Options object must have a numerical 'ratio' property/);
options.ratio = 1.0;
t.doesNotThrow(function() {
new mbgl.Map(options);
});
@@ -79,6 +89,7 @@ test('Map', function(t) {
var options = {};
options.request = function() {};
options.cancel = function() {};
options.ratio = 1.0;
t.test('requires a string or object as the first parameter', function(t) {
t.test('requires a map style as first argument', function(t) {
@@ -159,6 +170,7 @@ test('Map', function(t) {
});
};
options.cancel = function() {};
options.ratio = 1.0;
t.test('requires an object as the first parameter', function(t) {
setup(options, function(map) {

View File

@@ -47,6 +47,7 @@ function renderTest(style, info, base, key) {
});
};
options.cancel = function() {};
options.ratio = 1.0;
var map = new mbgl.Map(options);
map.load(style);

2
vendor/mbgl vendored