summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-11-16 11:10:16 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-17 13:48:00 -0800
commitf1e10e31a5029b1efa8aeb5f81bfe274cad0fc3b (patch)
tree594b7a76250d1566289aafd78fe085a1b8c79eae
parent5f010b0979b18d20b793186b2e1e44fc25d81fa7 (diff)
downloadqtlocation-mapboxgl-f1e10e31a5029b1efa8aeb5f81bfe274cad0fc3b.tar.gz
[node] Revert semantics of Map#render
-rw-r--r--platform/node/src/node_map.cpp56
-rw-r--r--platform/node/test/suite_implementation.js14
2 files changed, 40 insertions, 30 deletions
diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp
index c58a450295..43a278687a 100644
--- a/platform/node/src/node_map.cpp
+++ b/platform/node/src/node_map.cpp
@@ -21,15 +21,15 @@
namespace node_mbgl {
struct NodeMap::RenderOptions {
- mbgl::optional<double> zoom;
- mbgl::optional<double> bearing;
- mbgl::optional<double> pitch;
- mbgl::optional<double> latitude;
- mbgl::optional<double> longitude;
+ double zoom = 0;
+ double bearing = 0;
+ double pitch = 0;
+ double latitude = 0;
+ double longitude = 0;
unsigned int width = 512;
unsigned int height = 512;
- mbgl::optional<std::vector<std::string>> classes;
- mbgl::optional<mbgl::MapDebugOptions> debugOptions;
+ std::vector<std::string> classes;
+ mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug;
};
Nan::Persistent<v8::Function> NodeMap::constructor;
@@ -266,40 +266,37 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local<v8::Object> obj) {
if (Nan::Has(obj, Nan::New("classes").ToLocalChecked()).FromJust()) {
auto classes = Nan::To<v8::Object>(Nan::Get(obj, Nan::New("classes").ToLocalChecked()).ToLocalChecked()).ToLocalChecked().As<v8::Array>();
const int length = classes->Length();
- std::vector<std::string> vector;
- vector.reserve(length);
+ options.classes.reserve(length);
for (int i = 0; i < length; i++) {
- vector.push_back(std::string { *Nan::Utf8String(Nan::To<v8::String>(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) });
+ options.classes.push_back(std::string { *Nan::Utf8String(Nan::To<v8::String>(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) });
}
- options.classes = std::move(vector);
}
if (Nan::Has(obj, Nan::New("debug").ToLocalChecked()).FromJust()) {
auto debug = Nan::To<v8::Object>(Nan::Get(obj, Nan::New("debug").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
- options.debugOptions = mbgl::MapDebugOptions::NoDebug;
if (Nan::Has(debug, Nan::New("tileBorders").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("tileBorders").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
- *options.debugOptions = *options.debugOptions | mbgl::MapDebugOptions::TileBorders;
+ options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::TileBorders;
}
}
if (Nan::Has(debug, Nan::New("parseStatus").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("parseStatus").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
- *options.debugOptions = *options.debugOptions | mbgl::MapDebugOptions::ParseStatus;
+ options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::ParseStatus;
}
}
if (Nan::Has(debug, Nan::New("timestamps").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("timestamps").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
- *options.debugOptions = *options.debugOptions | mbgl::MapDebugOptions::Timestamps;
+ options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::Timestamps;
}
}
if (Nan::Has(debug, Nan::New("collision").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("collision").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
- *options.debugOptions = *options.debugOptions | mbgl::MapDebugOptions::Collision;
+ options.debugOptions = options.debugOptions | mbgl::MapDebugOptions::Collision;
}
}
if (Nan::Has(debug, Nan::New("overdraw").ToLocalChecked()).FromJust()) {
if (Nan::Get(debug, Nan::New("overdraw").ToLocalChecked()).ToLocalChecked()->BooleanValue()) {
- *options.debugOptions = mbgl::MapDebugOptions::Overdraw;
+ options.debugOptions = mbgl::MapDebugOptions::Overdraw;
}
}
}
@@ -368,28 +365,29 @@ void NodeMap::startRender(NodeMap::RenderOptions options) {
view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize);
}
- if (options.classes) {
- map->setClasses(*options.classes);
+ if (map->getClasses() != options.classes) {
+ map->setClasses(options.classes);
}
- if (options.latitude && options.longitude) {
- map->setLatLng(mbgl::LatLng(*options.latitude, *options.longitude));
+ mbgl::LatLng latLng(options.latitude, options.longitude);
+ if (map->getLatLng() != latLng) {
+ map->setLatLng(latLng);
}
- if (options.zoom) {
- map->setZoom(*options.zoom);
+ if (map->getZoom() != options.zoom) {
+ map->setZoom(options.zoom);
}
- if (options.bearing) {
- map->setBearing(*options.bearing);
+ if (map->getBearing() != options.bearing) {
+ map->setBearing(options.bearing);
}
- if (options.pitch) {
- map->setPitch(*options.pitch);
+ if (map->getPitch() != options.pitch) {
+ map->setPitch(options.pitch);
}
- if (options.debugOptions) {
- map->setDebug(*options.debugOptions);
+ if (map->getDebug() != options.debugOptions) {
+ map->setDebug(options.debugOptions);
}
map->renderStill(*view, [this](const std::exception_ptr eptr) {
diff --git a/platform/node/test/suite_implementation.js b/platform/node/test/suite_implementation.js
index 1122b143f9..6747a14151 100644
--- a/platform/node/test/suite_implementation.js
+++ b/platform/node/test/suite_implementation.js
@@ -36,6 +36,11 @@ module.exports = function (style, options, callback) {
overdraw: options.showOverdrawInspector,
};
+ options.center = style.center || [0, 0];
+ options.zoom = style.zoom || 0;
+ options.bearing = style.bearing || 0;
+ options.pitch = style.pitch || 0;
+
map.load(style);
applyOperations(options.operations, function() {
@@ -56,7 +61,7 @@ module.exports = function (style, options, callback) {
callback();
} else if (operation[0] === 'wait') {
- var wait = function() {
+ var wait = function () {
if (map.loaded()) {
applyOperations(operations.slice(1), callback);
} else {
@@ -66,6 +71,13 @@ module.exports = function (style, options, callback) {
wait();
} else {
+ // Ensure that the next `map.render(options)` does not overwrite this change.
+ if (operation[0] === 'setCenter') {
+ options.center = operations[1];
+ } else if (operation[0] === 'setBearing') {
+ options.bearing = operations[1];
+ }
+
map[operation[0]].apply(map, operation.slice(1));
applyOperations(operations.slice(1), callback);
}