From f1e10e31a5029b1efa8aeb5f81bfe274cad0fc3b Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 16 Nov 2016 11:10:16 -0800 Subject: [PATCH] [node] Revert semantics of Map#render --- platform/node/src/node_map.cpp | 56 +++++++++++----------- platform/node/test/suite_implementation.js | 14 +++++- 2 files changed, 40 insertions(+), 30 deletions(-) diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index c58a45029..43a278687 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 zoom; - mbgl::optional bearing; - mbgl::optional pitch; - mbgl::optional latitude; - mbgl::optional 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> classes; - mbgl::optional debugOptions; + std::vector classes; + mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug; }; Nan::Persistent NodeMap::constructor; @@ -266,40 +266,37 @@ NodeMap::RenderOptions NodeMap::ParseOptions(v8::Local obj) { if (Nan::Has(obj, Nan::New("classes").ToLocalChecked()).FromJust()) { auto classes = Nan::To(Nan::Get(obj, Nan::New("classes").ToLocalChecked()).ToLocalChecked()).ToLocalChecked().As(); const int length = classes->Length(); - std::vector vector; - vector.reserve(length); + options.classes.reserve(length); for (int i = 0; i < length; i++) { - vector.push_back(std::string { *Nan::Utf8String(Nan::To(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) }); + options.classes.push_back(std::string { *Nan::Utf8String(Nan::To(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) }); } - options.classes = std::move(vector); } if (Nan::Has(obj, Nan::New("debug").ToLocalChecked()).FromJust()) { auto debug = Nan::To(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(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 1122b143f..6747a1415 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); }