[node] Don't needlessly reset map state

This commit is contained in:
John Firebaugh
2016-11-09 17:15:51 -08:00
parent 31047b6cb5
commit a5e712d28b

View File

@@ -21,15 +21,15 @@
namespace node_mbgl {
struct NodeMap::RenderOptions {
double zoom = 0;
double bearing = 0;
double pitch = 0;
double latitude = 0;
double longitude = 0;
mbgl::optional<double> zoom;
mbgl::optional<double> bearing;
mbgl::optional<double> pitch;
mbgl::optional<double> latitude;
mbgl::optional<double> longitude;
unsigned int width = 512;
unsigned int height = 512;
std::vector<std::string> classes;
mbgl::MapDebugOptions debugOptions = mbgl::MapDebugOptions::NoDebug;
mbgl::optional<std::vector<std::string>> classes;
mbgl::optional<mbgl::MapDebugOptions> debugOptions;
};
Nan::Persistent<v8::Function> NodeMap::constructor;
@@ -266,37 +266,40 @@ 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();
options.classes.reserve(length);
std::vector<std::string> vector;
vector.reserve(length);
for (int i = 0; i < length; i++) {
options.classes.push_back(std::string { *Nan::Utf8String(Nan::To<v8::String>(Nan::Get(classes, i).ToLocalChecked()).ToLocalChecked()) });
vector.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;
}
}
}
@@ -364,11 +367,30 @@ void NodeMap::startRender(NodeMap::RenderOptions options) {
view.reset();
view = std::make_unique<mbgl::OffscreenView>(backend.getContext(), fbSize);
}
map->setClasses(options.classes);
map->setLatLngZoom(mbgl::LatLng(options.latitude, options.longitude), options.zoom);
map->setBearing(options.bearing);
map->setPitch(options.pitch);
map->setDebug(options.debugOptions);
if (options.classes) {
map->setClasses(*options.classes);
}
if (options.latitude && options.longitude) {
map->setLatLng(mbgl::LatLng(*options.latitude, *options.longitude));
}
if (options.zoom) {
map->setZoom(*options.zoom);
}
if (options.bearing) {
map->setBearing(*options.bearing);
}
if (options.pitch) {
map->setPitch(*options.pitch);
}
if (options.debugOptions) {
map->setDebug(*options.debugOptions);
}
map->renderStill(*view, [this](const std::exception_ptr eptr) {
if (eptr) {