Add NodeJS API for Approaches param.
Signed-off-by: FILLAU Jean-Maxime <jean-maxime.fillau@mapotempo.com>
This commit is contained in:
parent
f65299d665
commit
17a73e3979
@ -4,6 +4,7 @@
|
||||
#include "nodejs/json_v8_renderer.hpp"
|
||||
|
||||
#include "osrm/bearing.hpp"
|
||||
#include "osrm/approach.hpp"
|
||||
#include "osrm/coordinate.hpp"
|
||||
#include "osrm/engine_config.hpp"
|
||||
#include "osrm/json_container.hpp"
|
||||
@ -297,6 +298,63 @@ inline bool argumentsToParameter(const Nan::FunctionCallbackInfo<v8::Value> &arg
|
||||
return false;
|
||||
}
|
||||
|
||||
if (obj->Has(Nan::New("approaches").ToLocalChecked()))
|
||||
{
|
||||
v8::Local<v8::Value> approaches = obj->Get(Nan::New("approaches").ToLocalChecked());
|
||||
if (approaches.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (!approaches->IsArray())
|
||||
{
|
||||
Nan::ThrowError("Approaches must be an array of arrays of numbers");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto approaches_array = v8::Local<v8::Array>::Cast(approaches);
|
||||
|
||||
if (approaches_array->Length() != params->coordinates.size())
|
||||
{
|
||||
Nan::ThrowError("Approaches array must have the same length as coordinates array");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < approaches_array->Length(); ++i)
|
||||
{
|
||||
v8::Local<v8::Value> approach_raw = approaches_array->Get(i);
|
||||
if (approach_raw.IsEmpty())
|
||||
return false;
|
||||
|
||||
if (approach_raw->IsNull())
|
||||
{
|
||||
params->bearings.emplace_back();
|
||||
}
|
||||
else if (approach_raw->IsString())
|
||||
{
|
||||
const Nan::Utf8String approach_utf8str(approach_raw);
|
||||
std::string approach_str{*approach_utf8str,
|
||||
*approach_utf8str + approach_utf8str.length()};
|
||||
if (approach_str == "curb")
|
||||
{
|
||||
params->approaches.push_back(osrm::Approach::CURB);
|
||||
}
|
||||
else if (approach_str == "unrestricted")
|
||||
{
|
||||
params->approaches.push_back(osrm::Approach::UNRESTRICTED);
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("'approach' param must be one of [curb, unrestricted]");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Nan::ThrowError("Approach must be a string: [curb, unrestricted] or null");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (obj->Has(Nan::New("bearings").ToLocalChecked()))
|
||||
{
|
||||
v8::Local<v8::Value> bearings = obj->Get(Nan::New("bearings").ToLocalChecked());
|
||||
|
38
include/osrm/approach.hpp
Normal file
38
include/osrm/approach.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
|
||||
Copyright (c) 2016, Project OSRM contributors
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list
|
||||
of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef OSRM_APPROACH_HPP
|
||||
#define OSRM_APPROACH_HPP
|
||||
|
||||
#include "engine/approach.hpp"
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
using engine::Approach;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user