diff options
author | Mike Morris <michael.patrick.morris@gmail.com> | 2015-11-04 18:18:08 -0500 |
---|---|---|
committer | Mike Morris <michael.patrick.morris@gmail.com> | 2015-11-04 18:18:08 -0500 |
commit | 5e58070decb7ee5e1538a120e6b8261a0574d334 (patch) | |
tree | 00108695a53e84161fce5ecc927c30f6000f58a1 | |
parent | 3528002b580f9e5ae19ef4df7543e913c5d27ab4 (diff) | |
download | qtlocation-mapboxgl-5e58070decb7ee5e1538a120e6b8261a0574d334.tar.gz |
[node] make ratio optional, default to 1.0
-rw-r--r-- | platform/node/CHANGELOG.md | 4 | ||||
-rw-r--r-- | platform/node/README.md | 13 | ||||
-rw-r--r-- | platform/node/src/node_map.cpp | 13 | ||||
-rw-r--r-- | platform/node/test/js/map.test.js | 29 |
4 files changed, 39 insertions, 20 deletions
diff --git a/platform/node/CHANGELOG.md b/platform/node/CHANGELOG.md index 70ad3486ee..6fde0229c4 100644 --- a/platform/node/CHANGELOG.md +++ b/platform/node/CHANGELOG.md @@ -10,8 +10,8 @@ drops `mbgl.FileSource`. ([mapbox/node-mapbox-gl-native#143](https://github.com/mapbox/node-mapbox-gl-native/pull/143)) - Changes `request` semantics to pass a second, callback argument instead of needing to call `req.respond`. ([#2299](https://github.com/mapbox/mapbox-gl-native/pull/2299)) -- Requires numerical `ratio` in `mbgl.Map` options argument. - Map pixel ratio is now immutable and can no longer be set with +- Accepts optional `ratio` (defaults to `1.0`) in `mbgl.Map` options + argument. Map pixel ratio is now immutable and can no longer be set with render options. ([`a8d9b92`](https://github.com/mapbox/mapbox-gl-native/commit/a8d9b921d71a91d7f8eff82e5a584aaab8b7d1c6), [#1799](https://github.com/mapbox/mapbox-gl-native/pull/1799)) - Swaps array order in render options `center` argument to `[lng, lat]` for consistency with GeoJSON and mapbox-gl-js. - Adds render option `pitch` ([#2702](https://github.com/mapbox/mapbox-gl-native/pull/2702)) diff --git a/platform/node/README.md b/platform/node/README.md index 36a5d5b36f..2d10736826 100644 --- a/platform/node/README.md +++ b/platform/node/README.md @@ -53,7 +53,7 @@ npm test ## Implementing a file source -When creating a `Map`, you must pass an options object (with a required `ratio`, required `request` and optional `cancel` method) as the first parameter. +When creating a `Map`, you must pass an options object (with a required `request` method, optional `cancel` method and optional 'ratio' number) as the first parameter. ```js var map = new mbgl.Map({ @@ -63,7 +63,7 @@ var map = new mbgl.Map({ cancel: function(req) { // TODO }, - ratio: 1.0 + ratio: 2.0 }); ``` @@ -102,8 +102,7 @@ var map = new mbgl.Map({ fs.readFile(path.join('base/path', req.url), function(err, data) { callback(err, { data: data }); }); - }, - ratio: 1.0 + } }); ``` @@ -147,8 +146,7 @@ var map = new mbgl.Map({ callback(new Error(JSON.parse(body).message)); } }); - }, - ratio: 1.0 + } }); ``` @@ -192,8 +190,7 @@ var map = new mbgl.Map({ callback(new Error(JSON.parse(body).message)); } }); - }, - ratio: 1.0 + } }); // includes a datasource with a reference to something like `mapbox://mapbox.mapbox-streets-v6` diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index 8b2b5fc53d..6e9230287e 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -107,20 +107,21 @@ NAN_METHOD(NodeMap::New) { auto options = info[0]->ToObject(); - // Check that 'request', 'cancel' and 'ratio' are defined. + // Check that 'request' is set. If 'cancel' is set it must be a + // function and if 'ratio' is set it must be a number. if (!Nan::Has(options, Nan::New("request").ToLocalChecked()).FromJust() || !Nan::Get(options, Nan::New("request").ToLocalChecked()).ToLocalChecked()->IsFunction()) { return Nan::ThrowError("Options object must have a 'request' method"); } - if ( Nan::Has(options, Nan::New("cancel").ToLocalChecked()).FromJust() + if (Nan::Has(options, Nan::New("cancel").ToLocalChecked()).FromJust() && !Nan::Get(options, Nan::New("cancel").ToLocalChecked()).ToLocalChecked()->IsFunction()) { return Nan::ThrowError("Options object 'cancel' property must be a function"); } - if (!Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() - || !Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->IsNumber()) { - return Nan::ThrowError("Options object must have a numerical 'ratio' property"); + if (Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() + && !Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->IsNumber()) { + return Nan::ThrowError("Options object 'ratio' property must be a number"); } try { @@ -424,7 +425,7 @@ NAN_METHOD(NodeMap::DumpDebugLogs) { NodeMap::NodeMap(v8::Local<v8::Object> options) : view(sharedDisplay(), [&] { Nan::HandleScope scope; - return Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue(); + return Nan::Has(options, Nan::New("ratio").ToLocalChecked()).FromJust() ? Nan::Get(options, Nan::New("ratio").ToLocalChecked()).ToLocalChecked()->NumberValue() : 1.0; }()), fs(options), map(std::make_unique<mbgl::Map>(view, fs, mbgl::MapMode::Still)), diff --git a/platform/node/test/js/map.test.js b/platform/node/test/js/map.test.js index a87f4aac1a..0ccaa4b55e 100644 --- a/platform/node/test/js/map.test.js +++ b/platform/node/test/js/map.test.js @@ -27,7 +27,7 @@ test('Map', function(t) { t.end(); }); - t.test('requires request and ratio options', function(t) { + t.test('requires request property', function(t) { var options = {}; t.throws(function() { @@ -40,20 +40,41 @@ test('Map', function(t) { }, /Options object must have a 'request' method/); options.request = function() {}; + t.doesNotThrow(function() { + new mbgl.Map(options); + }); + + t.end(); + }); + + t.test('optional cancel property must be a function', function(t) { + var options = { + request: function() {} + }; + options.cancel = 'test'; t.throws(function() { new mbgl.Map(options); }, /Options object 'cancel' property must be a function/); options.cancel = function() {}; - t.throws(function() { + t.doesNotThrow(function() { new mbgl.Map(options); - }, /Options object must have a numerical 'ratio' property/); + }); + + t.end(); + }); + + + t.test('optional ratio property must be a number', function(t) { + var options = { + request: function() {} + }; options.ratio = 'test'; t.throws(function() { new mbgl.Map(options); - }, /Options object must have a numerical 'ratio' property/); + }, /Options object 'ratio' property must be a number/); options.ratio = 1.0; t.doesNotThrow(function() { |