Expose Map Matching gaps and tidy parameters in Node.js bindings #4021

This commit is contained in:
Stepan Kuzmin 2017-06-11 14:46:41 +03:00 committed by Patrick Niklaus
parent afbcb3d38c
commit 5ee3c4de9f
2 changed files with 47 additions and 0 deletions

View File

@ -194,6 +194,8 @@ if they can not be matched successfully.
- `options.overview` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Add overview geometry either `full`, `simplified` according to highest zoom level it could be display on, or not at all (`false`). (optional, default `simplified`)
- `options.timestamps` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)>?** Timestamp of the input location (integers, UNIX-like timestamp).
- `options.radiuses` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy. Can be `null` for default value `5` meters or `double >= 0`.
- `options.gaps` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Allows the input track splitting based on huge timestamp gaps between points. Either `split` or `ignore`. (optional, default `split`)
- `options.tidy` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Allows the input track modification to obtain better matching quality for noisy tracks. (optional, default `false`)
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
**Examples**

View File

@ -1070,6 +1070,51 @@ argumentsToMatchParameter(const Nan::FunctionCallbackInfo<v8::Value> &args,
}
}
if (obj->Has(Nan::New("gaps").ToLocalChecked()))
{
v8::Local<v8::Value> gaps = obj->Get(Nan::New("gaps").ToLocalChecked());
if (gaps.IsEmpty())
return match_parameters_ptr();
if (!gaps->IsString())
{
Nan::ThrowError("Gaps must be a string: [split, ignore]");
return match_parameters_ptr();
}
const Nan::Utf8String gaps_utf8str(gaps);
std::string gaps_str{*gaps_utf8str, *gaps_utf8str + gaps_utf8str.length()};
if (gaps_str == "split")
{
params->gaps = osrm::MatchParameters::GapsType::Split;
}
else if (gaps_str == "ignore")
{
params->gaps = osrm::MatchParameters::GapsType::Ignore;
}
else
{
Nan::ThrowError("'gaps' param must be one of [split, ignore]");
return match_parameters_ptr();
}
}
if (obj->Has(Nan::New("tidy").ToLocalChecked()))
{
v8::Local<v8::Value> tidy = obj->Get(Nan::New("tidy").ToLocalChecked());
if (tidy.IsEmpty())
return match_parameters_ptr();
if (!tidy->IsBoolean())
{
Nan::ThrowError("tidy must be of type Boolean");
return match_parameters_ptr();
}
params->tidy = tidy->BooleanValue();
}
bool parsedSuccessfully = parseCommonParameters(obj, params);
if (!parsedSuccessfully)
{