Compare commits

...

12 Commits

Author SHA1 Message Date
Patrick Niklaus
1869840f0e [publish binary] Test building node binaries with MLD 2017-03-22 00:51:07 +00:00
Patrick Niklaus
8532b5460b Disable doc builds because they are broken 2017-03-22 00:30:42 +00:00
Patrick Niklaus
1fdbaf4a39 Upgrade docbox 2017-03-22 00:04:46 +00:00
Patrick Niklaus
08527175b5 Fresh lock file 2017-03-21 23:44:08 +00:00
Patrick Niklaus
d792572ece Install yarn on OSX by hand and update lock file 2017-03-21 23:26:32 +00:00
Patrick Niklaus
2a691ac5be Integrate documentation JS and make travis file slightly more readable 2017-03-21 22:50:08 +00:00
Patrick Niklaus
2221a34529 Switch to yarn 2017-03-21 22:37:16 +00:00
Patrick Niklaus
a8fd4050a2 Integrate node-osrm docs 2017-03-21 22:29:00 +00:00
Patrick Niklaus
85ee03dfde Also copy osrm-partition and osrm-customize 2017-03-21 20:15:08 +00:00
Patrick Niklaus
694e3854d7 Test routing on CH, MLD, CoreCH via node bindings 2017-03-21 20:15:08 +00:00
Patrick Niklaus
90ed027711 Integrate MLD into node-bindings 2017-03-21 20:15:06 +00:00
Patrick Niklaus
ac0c5c27e7 First steps towards integrating MLD in node bindings 2017-03-21 20:12:56 +00:00
10 changed files with 6370 additions and 108 deletions

View File

@ -7,6 +7,9 @@ git:
sudo: required sudo: required
dist: trusty dist: trusty
nodejs:
- "4"
notifications: notifications:
email: false email: false
@ -15,6 +18,7 @@ branches:
- master - master
cache: cache:
yarn: true
ccache: true ccache: true
apt: true apt: true
directories: directories:
@ -138,11 +142,10 @@ before_install:
if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then if [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then
export JOBS=$((`sysctl -n hw.ncpu` + 1)) export JOBS=$((`sysctl -n hw.ncpu` + 1))
sudo mdutil -i off / sudo mdutil -i off /
npm install -g yarn
fi fi
- echo "Using ${JOBS} jobs" - echo "Using ${JOBS} jobs"
- source ./scripts/install_node.sh 4 - yarn install --ignore-scripts
- npm install -g "npm@>=3" # Upgrade to npm >v2 to reduce size of downloaded dependencies
- npm install --ignore-scripts
# Bootstrap cmake to be able to run mason # Bootstrap cmake to be able to run mason
- CMAKE_URL="https://mason-binaries.s3.amazonaws.com/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}.tar.gz" - CMAKE_URL="https://mason-binaries.s3.amazonaws.com/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}.tar.gz"
- CMAKE_DIR="mason_packages/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}" - CMAKE_DIR="mason_packages/${TRAVIS_OS_NAME}-x86_64/cmake/${CMAKE_VERSION}"
@ -173,7 +176,16 @@ install:
- export OSRM_BUILD_DIR="$(pwd)/build-osrm" - export OSRM_BUILD_DIR="$(pwd)/build-osrm"
- mkdir ${OSRM_BUILD_DIR} && pushd ${OSRM_BUILD_DIR} - mkdir ${OSRM_BUILD_DIR} && pushd ${OSRM_BUILD_DIR}
- export CC=${CCOMPILER} CXX=${CXXCOMPILER} - export CC=${CCOMPILER} CXX=${CXXCOMPILER}
- cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DENABLE_MASON=${ENABLE_MASON:-OFF} -DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS:-OFF} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS:-OFF} -DENABLE_COVERAGE=${ENABLE_COVERAGE:-OFF} -DENABLE_SANITIZER=${ENABLE_SANITIZER:-OFF} -DBUILD_TOOLS=ON -DENABLE_CCACHE=ON -DENABLE_NODE_BINDINGS=${ENABLE_NODE_BINDINGS:-OFF} - |
cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
-DENABLE_MASON=${ENABLE_MASON:-OFF} \
-DENABLE_ASSERTIONS=${ENABLE_ASSERTIONS:-OFF} \
-DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS:-OFF} \
-DENABLE_COVERAGE=${ENABLE_COVERAGE:-OFF} \
-DENABLE_NODE_BINDINGS=${ENABLE_NODE_BINDINGS:-OFF} \
-DENABLE_SANITIZER=${ENABLE_SANITIZER:-OFF} \
-DBUILD_TOOLS=ON \
-DENABLE_CCACHE=ON
- echo "travis_fold:start:MAKE" - echo "travis_fold:start:MAKE"
- make --jobs=${JOBS} - make --jobs=${JOBS}
- make tests --jobs=${JOBS} - make tests --jobs=${JOBS}
@ -190,7 +202,8 @@ install:
- cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE} - cmake .. -DCMAKE_BUILD_TYPE=${BUILD_TYPE}
- make --jobs=${JOBS} - make --jobs=${JOBS}
- popd - popd
- npm run build-api-docs # building docs only works with npm3+ not with yarn or npm2
#- yarn run docs
script: script:
- if [[ $TARGET_ARCH == armhf ]] ; then echo "Skip tests for $TARGET_ARCH" && exit 0 ; fi - if [[ $TARGET_ARCH == armhf ]] ; then echo "Skip tests for $TARGET_ARCH" && exit 0 ; fi
@ -205,7 +218,7 @@ script:
- ./unit_tests/server-tests - ./unit_tests/server-tests
- ./unit_tests/partition-tests - ./unit_tests/partition-tests
- popd - popd
- npm test - yarn test
after_success: after_success:
- | - |
@ -215,8 +228,6 @@ after_success:
- | - |
if [ -n "${ENABLE_NODE_BINDINGS}" ]; then if [ -n "${ENABLE_NODE_BINDINGS}" ]; then
nvm install 4
nvm use 4
source ./scripts/travis/build.sh source ./scripts/travis/build.sh
./scripts/travis/publish.sh ./scripts/travis/publish.sh
fi fi

View File

@ -117,6 +117,7 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
{ {
engine_config->storage_config = engine_config->storage_config =
osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked())); osrm::StorageConfig(*v8::String::Utf8Value(Nan::To<v8::String>(path).ToLocalChecked()));
engine_config->use_shared_memory = false;
} }
if (!shared_memory->IsUndefined()) if (!shared_memory->IsUndefined())
{ {
@ -138,6 +139,34 @@ inline engine_config_ptr argumentsToEngineConfig(const Nan::FunctionCallbackInfo
return engine_config_ptr(); return engine_config_ptr();
} }
auto algorithm = params->Get(Nan::New("algorithm").ToLocalChecked());
if (algorithm->IsString())
{
auto algorithm_str = Nan::To<v8::String>(algorithm).ToLocalChecked();
if (*v8::String::Utf8Value(algorithm_str) == std::string("CH"))
{
engine_config->algorithm = osrm::EngineConfig::Algorithm::CH;
}
else if (*v8::String::Utf8Value(algorithm_str) == std::string("CoreCH"))
{
engine_config->algorithm = osrm::EngineConfig::Algorithm::CoreCH;
}
else if (*v8::String::Utf8Value(algorithm_str) == std::string("MLD"))
{
engine_config->algorithm = osrm::EngineConfig::Algorithm::MLD;
}
else
{
Nan::ThrowError("algorithm option must be one of 'CH', 'CoreCH', or 'MLD'.");
return engine_config_ptr();
}
}
else if (!algorithm->IsUndefined())
{
Nan::ThrowError("algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'.");
return engine_config_ptr();
}
return engine_config; return engine_config;
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "osrm", "name": "osrm",
"version": "5.7.0", "version": "5.7.0-alpha.1",
"private": true, "private": true,
"description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.", "description": "The Open Source Routing Machine is a high performance routing engine written in C++14 designed to run on OpenStreetMap data.",
"dependencies": { "dependencies": {
@ -8,15 +8,14 @@
"cucumber": "^1.2.1", "cucumber": "^1.2.1",
"d3-queue": "^2.0.3", "d3-queue": "^2.0.3",
"mkdirp": "^0.5.1", "mkdirp": "^0.5.1",
"nan": "^2.1.0",
"node-cmake": "^1.2.1",
"node-pre-gyp": "^0.6.34",
"node-timeout": "0.0.4", "node-timeout": "0.0.4",
"polyline": "^0.2.0", "polyline": "^0.2.0",
"request": "^2.69.0", "request": "^2.69.0",
"rimraf": "^2.5.4", "rimraf": "^2.5.4",
"xmlbuilder": "^4.2.1", "xmlbuilder": "^4.2.1"
"nan": "^2.1.0",
"node-cmake": "^1.2.1",
"node-pre-gyp": "~0.6.30"
}, },
"bin": { "bin": {
"cucumber": "./node_modules/cucumber/bin/cucumber.js" "cucumber": "./node_modules/cucumber/bin/cucumber.js"
@ -32,17 +31,15 @@
"test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld", "test": "npm run lint && node ./node_modules/cucumber/bin/cucumber.js features/ -p verify && node ./node_modules/cucumber/bin/cucumber.js features/ -p mld",
"clean-test": "rm -rf test/cache", "clean-test": "rm -rf test/cache",
"cucumber": "./node_modules/cucumber/bin/cucumber.js", "cucumber": "./node_modules/cucumber/bin/cucumber.js",
"build-api-docs": "./scripts/build_api_docs.sh", "docs": "./scripts/build_api_docs.sh",
"preinstall": "npm install node-pre-gyp",
"install": "node-pre-gyp install --fallback-to-build=false" "install": "node-pre-gyp install --fallback-to-build=false"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/Project-OSRM/osrm-backend.git" "url": "https://github.com/Project-OSRM/osrm-backend.git"
}, },
"author": "", "author": "Project OSRM Team",
"license": "ISC", "license": "BSD 2-Clause",
"bugs": { "bugs": {
"url": "https://github.com/Project-OSRM/osrm-backend/issues" "url": "https://github.com/Project-OSRM/osrm-backend/issues"
}, },
@ -51,12 +48,16 @@
"node": ">=4.0.0" "node": ">=4.0.0"
}, },
"devDependencies": { "devDependencies": {
"docbox": "^1.0.2", "docbox": "^1.0.5",
"documentation": "^4.0.0-beta.18",
"eslint": "^2.4.0", "eslint": "^2.4.0",
"aws-sdk": "~2.0.31", "aws-sdk": "~2.0.31",
"tape": "^4.2.2" "tape": "^4.2.2"
}, },
"bundleDependencies": [
"node-pre-gyp"
],
"main": "lib/index.js", "main": "lib/index.js",
"binary": { "binary": {
"module_name": "node-osrm", "module_name": "node-osrm",

View File

@ -14,6 +14,8 @@ babel -V >/dev/null 2>&1 || { echo >&2 "Can't find babel. Add node_modules/.bin
browserify --help >/dev/null 2>&1 || { echo >&2 "Can't find browserify. Add node_modules/.bin to your path, or run via \"npm run\""; exit 1; } browserify --help >/dev/null 2>&1 || { echo >&2 "Can't find browserify. Add node_modules/.bin to your path, or run via \"npm run\""; exit 1; }
uglifyjs -V >/dev/null 2>&1 || { echo >&2 "Can't find uglifyjs. Add node_modules/.bin to your path, or run via \"npm run\""; exit 1; } uglifyjs -V >/dev/null 2>&1 || { echo >&2 "Can't find uglifyjs. Add node_modules/.bin to your path, or run via \"npm run\""; exit 1; }
#documentation build src/nodejs/node_osrm.cpp --polyglot -f md -o docs/nodejs/api.md
# Clean up previous version # Clean up previous version
rm -rf build/docs rm -rf build/docs

View File

@ -20,7 +20,7 @@ target_link_libraries(node-osrm osrm)
# node-osrm artifacts in ${BINDING_DIR} to depend targets on # node-osrm artifacts in ${BINDING_DIR} to depend targets on
set(ARTIFACTS "") set(ARTIFACTS "")
set(OSRM_BINARIES osrm-extract osrm-contract osrm-routed osrm-datastore osrm-components) set(OSRM_BINARIES osrm-extract osrm-contract osrm-routed osrm-datastore osrm-components osrm-partition osrm-customize)
foreach(binary ${OSRM_BINARIES}) foreach(binary ${OSRM_BINARIES})
add_custom_command(OUTPUT ${BINDING_DIR}/${binary} add_custom_command(OUTPUT ${BINDING_DIR}/${binary}
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${binary}> ${BINDING_DIR} COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${binary}> ${BINDING_DIR}

View File

@ -48,15 +48,14 @@ NAN_MODULE_INIT(Engine::Init)
Nan::Set(target, whoami, fn); Nan::Set(target, whoami, fn);
} }
// clang-format off
/** /**
* *
* The `OSRM` method is the main constructor for creating an OSRM instance. An OSRM instance * The `OSRM` method is the main constructor for creating an OSRM instance.
* requires a `.osrm` network, * An OSRM instance requires a `.osrm` dataset, which is prepared by the OSRM toolchain.
* which is prepared by the OSRM Backend C++ library. Once you have a complete `network.osrm` file, * The documentation on `osrm-extract` and `osrm-contract` for more information.
* you can calculate * Once you have a complete `network.osrm` file, you can calculate routes in javascript with this library using the methods below.
* networks in javascript with this library using the methods below. To create an OSRM instance with * To create an OSRM instance with your network you need to construct an instance like this:
* your network
* you need to construct an instance like this:
* *
* ```javascript * ```javascript
* var osrm = new OSRM('network.osrm'); * var osrm = new OSRM('network.osrm');
@ -78,27 +77,18 @@ NAN_MODULE_INIT(Engine::Init)
* Each OSRM method (except for `OSRM.tile()`) has set of general options as well as unique options, * Each OSRM method (except for `OSRM.tile()`) has set of general options as well as unique options,
* outlined below. * outlined below.
* *
* | Option | Values | Description * | Option | Values | Description | Format |
* | Format | * | ----------- | -----------------| ------------ | -------|
* | ----------- | ------------------------------------------------------- | * | coordinates | `array` of `coordinate` elements: `[{coordinate}, ...]` | The coordinates this request will use. | `array` with `[{lon},{lat}]` values, in decimal degrees |
* ------------------------------------------------------------------------------------------------------ * | bearings | `array` of `bearing` elements: `[{bearing}, ...]` | Limits the search to segments with given bearing in degrees towards true north in clockwise direction. | `null` or `array` with `[{value},{range}]` `integer 0 .. 360,integer 0 .. 180` |
* | ------------------------------------------------------------------------------ | * | radiuses | `array` of `radius` elements: `[{radius}, ...]` | Limits the search to given radius in meters. | `null` or `double >= 0` or `unlimited` (default) |
* | coordinates | `array` of `coordinate` elements: `[{coordinate}, ...]` | The coordinates this * | hints | `array` of `hint` elements: `[{hint}, ...]` | Hint to derive position in street network. | Base64 `string` |
* request will use. | `array` with
* `[{lon},{lat}]` values, in decimal degrees |
* | bearings | `array` of `bearing` elements: `[{bearing}, ...]` | Limits the search to
* segments with given bearing in degrees towards true north in clockwise direction. | `null` or
* `array` with `[{value},{range}]` `integer 0 .. 360,integer 0 .. 180` |
* | radiuses | `array` of `radius` elements: `[{radius}, ...]` | Limits the search to
* given radius in meters. | `null` or
* `double >= 0` or `unlimited` (default) |
* | hints | `array` of `hint` elements: `[{hint}, ...]` | Hint to derive position
* in street network. | Base64 `string`
* |
* *
* @class OSRM * @class OSRM
* *
*
*/ */
// clang-format on
NAN_METHOD(Engine::New) NAN_METHOD(Engine::New)
{ {
if (info.IsConstructCall()) if (info.IsConstructCall())
@ -195,6 +185,7 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
Nan::AsyncQueueWorker(new Worker{self->this_, std::move(params), service, callback}); Nan::AsyncQueueWorker(new Worker{self->this_, std::move(params), service, callback});
} }
// clang-format off
/** /**
* Returns the fastest route between two or more coordinates while visiting the waypoints in order. * Returns the fastest route between two or more coordinates while visiting the waypoints in order.
* *
@ -205,19 +196,14 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
* *Please note that even if an alternative route is requested, a result cannot be guaranteed.* * *Please note that even if an alternative route is requested, a result cannot be guaranteed.*
* @param {Boolean} [options.steps=false] Return route steps for each route leg. * @param {Boolean} [options.steps=false] Return route steps for each route leg.
* @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg. * @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg.
* Can be `false`, `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, * Can be `false`, `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed`.
* `datasources`, `speed`. * @param {String} [options.geometries=polyline] Returned route geometry format (influences overview and per step). Can also be `geojson`.
* @param {String} [options.geometries=polyline] Returned route geometry format (influences overview * @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified` according to highest zoom level it could be display on, or not at all (`false`).
* and per step). Can also be `geojson`. * @param {Boolean} [options.continue_straight] Forces the route to keep going straight at waypoints and don't do a uturn even if it would be faster. Default value depends on the profile.
* @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified`
* according to highest zoom level it could be display on, or not at all (`false`).
* @param {Boolean} [options.continue_straight] Forces the route to keep going straight at waypoints
* and don't do a uturn even if it would be faster. Default value depends on the profile.
* `null`/`true`/`false` * `null`/`true`/`false`
* @param {Function} callback * @param {Function} callback
* *
* @returns {Object} An array of [Waypoint](#waypoint) objects representing all waypoints in order * @returns {Object} An array of [Waypoint](#waypoint) objects representing all waypoints in order AND an array of [`Route`](#route) objects ordered by descending recommendation rank.
* AND an array of [`Route`](#route) objects ordered by descending recommendation rank.
* *
* @example * @example
* var osrm = new OSRM("berlin-latest.osrm"); * var osrm = new OSRM("berlin-latest.osrm");
@ -227,11 +213,13 @@ inline void async(const Nan::FunctionCallbackInfo<v8::Value> &info,
* console.log(result.routes); // array of Route objects ordered by descending recommendation rank * console.log(result.routes); // array of Route objects ordered by descending recommendation rank
* }); * });
*/ */
// clang-format on
NAN_METHOD(Engine::route) // NAN_METHOD(Engine::route) //
{ {
async(info, &argumentsToRouteParameter, &osrm::OSRM::Route, true); async(info, &argumentsToRouteParameter, &osrm::OSRM::Route, true);
} }
// clang-format off
/** /**
* Snaps a coordinate to the street network and returns the nearest n matches. * Snaps a coordinate to the street network and returns the nearest n matches.
* *
@ -245,11 +233,8 @@ NAN_METHOD(Engine::route) //
* @param {Function} callback * @param {Function} callback
* *
* @returns {Object} containing `waypoints`. * @returns {Object} containing `waypoints`.
* **`waypoints`**: array of [`aypoint`](#waypoint) objects sorted by distance to the input * **`waypoints`**: array of [`aypoint`](#waypoint) objects sorted by distance to the input coordinate.
* coordinate. * Each object has an additional `distance` property, which is the distance in meters to the supplied input coordinate.
* Each object has an additional `distance` property, which is the distance in meters to the
* supplied
* input coordinate.
* *
* @example * @example
* var osrm = new OSRM('network.osrm'); * var osrm = new OSRM('network.osrm');
@ -262,11 +247,13 @@ NAN_METHOD(Engine::route) //
* console.log(response.waypoints); // array of Waypoint objects * console.log(response.waypoints); // array of Waypoint objects
* }); * });
*/ */
// clang-format on
NAN_METHOD(Engine::nearest) // NAN_METHOD(Engine::nearest) //
{ {
async(info, &argumentsToNearestParameter, &osrm::OSRM::Nearest, false); async(info, &argumentsToNearestParameter, &osrm::OSRM::Nearest, false);
} }
// clang-format off
/** /**
* Computes duration tables for the given locations. Allows for both symmetric and asymmetric * Computes duration tables for the given locations. Allows for both symmetric and asymmetric
* tables. * tables.
@ -282,11 +269,10 @@ NAN_METHOD(Engine::nearest) //
* @param {Function} callback * @param {Function} callback
* *
* @returns {Object} containing `durations`, `sources`, and `destinations`. * @returns {Object} containing `durations`, `sources`, and `destinations`.
* **`durations`**: array of arrays that stores the matrix in row-major order. `durations[i][j]` * **`durations`**: array of arrays that stores the matrix in row-major order. `durations[i][j]` gives the travel time from the i-th waypoint to the j-th waypoint.
* gives the travel time from the i-th waypoint to the j-th waypoint. Values are given in seconds. * Values are given in seconds.
* **`sources`**: array of [`aypoint`](#waypoint) objects describing all sources in order. * **`sources`**: array of [`aypoint`](#waypoint) objects describing all sources in order.
* **`destinations`**: array of [`aypoint`](#waypoint) objects describing all destinations in * **`destinations`**: array of [`aypoint`](#waypoint) objects describing all destinations in order.
* order.
* *
* @example * @example
* var osrm = new OSRM('network.osrm'); * var osrm = new OSRM('network.osrm');
@ -303,11 +289,13 @@ NAN_METHOD(Engine::nearest) //
* console.log(response.destinations); // array of Waypoint objects * console.log(response.destinations); // array of Waypoint objects
* }); * });
*/ */
// clang-format on
NAN_METHOD(Engine::table) // NAN_METHOD(Engine::table) //
{ {
async(info, &argumentsToTableParameter, &osrm::OSRM::Table, true); async(info, &argumentsToTableParameter, &osrm::OSRM::Table, true);
} }
// clang-format off
/** /**
* This generates [Mapbox Vector Tiles](https://mapbox.com/vector-tiles) that can be viewed with a * This generates [Mapbox Vector Tiles](https://mapbox.com/vector-tiles) that can be viewed with a
* vector-tile capable slippy-map viewer. The tiles contain road geometries and metadata that can * vector-tile capable slippy-map viewer. The tiles contain road geometries and metadata that can
@ -318,11 +306,9 @@ NAN_METHOD(Engine::table) //
* *
* @name tile * @name tile
* @memberof OSRM * @memberof OSRM
* @param {Array} ZXY - an array consisting of `x`, `y`, and `z` values representing tile * @param {Array} ZXY - an array consisting of `x`, `y`, and `z` values representing tile coordinates like
* coordinates like
* [wiki.openstreetmap.org/wiki/Slippy_map_tilenames](https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames) * [wiki.openstreetmap.org/wiki/Slippy_map_tilenames](https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames)
* and are supported by vector tile viewers like [Mapbox GL * and are supported by vector tile viewers like [Mapbox GL JS](https://www.mapbox.com/mapbox-gl-js/api/).
* JS](https://www.mapbox.com/mapbox-gl-js/api/.
* @param {Function} callback * @param {Function} callback
* *
* @returns {Buffer} contains a Protocol Buffer encoded vector tile. * @returns {Buffer} contains a Protocol Buffer encoded vector tile.
@ -334,11 +320,13 @@ NAN_METHOD(Engine::table) //
* fs.writeFileSync('./tile.vector.pbf', response); // write the buffer to a file * fs.writeFileSync('./tile.vector.pbf', response); // write the buffer to a file
* }); * });
*/ */
// clang-format on
NAN_METHOD(Engine::tile) NAN_METHOD(Engine::tile)
{ {
async(info, &argumentsToTileParameters, &osrm::OSRM::Tile, {/*unused*/}); async(info, &argumentsToTileParameters, &osrm::OSRM::Tile, {/*unused*/});
} }
// clang-format off
/** /**
* Map matching matches given GPS points to the road network in the most plausible way. * Map matching matches given GPS points to the road network in the most plausible way.
* Please note the request might result multiple sub-traces. Large jumps in the timestamps * Please note the request might result multiple sub-traces. Large jumps in the timestamps
@ -351,31 +339,21 @@ NAN_METHOD(Engine::tile)
* @param {Object} options - Object literal containing parameters for the match query. * @param {Object} options - Object literal containing parameters for the match query.
* @param {Boolean} [options.steps=false] Return route steps for each route. * @param {Boolean} [options.steps=false] Return route steps for each route.
* @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg. * @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg.
* Can be `false`, `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, * Can be `false`, `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed`.
* `datasources`, `speed`. * @param {String} [options.geometries=polyline] Returned route geometry format (influences overview and per step). Can also be `geojson`.
* @param {String} [options.geometries=polyline] Returned route geometry format (influences overview * @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified` according to highest zoom level it could be display on, or not at all (`false`).
* and per step). Can also be `geojson`. * @param {Array<Number>} [options.timestamps] Timestamp of the input location (integers, UNIX-like timestamp).
* @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified` * @param {Array} [options.radiuses] Standard deviation of GPS precision used for map matching. If applicable use GPS accuracy (`double >= 0`, default `5m`).
* according to highest zoom level it could be display on, or not at all (`false`).
* @param {Array<Number>} [options.timestamps] Timestamp of the input location (integers, UNIX-like
* timestamp).
* @param {Array} [options.radiuses] Standard deviation of GPS precision used for map matching.
* If applicable use GPS accuracy (`double >= 0`, default `5m`).
* @param {Function} callback * @param {Function} callback
* *
* @returns {Object} containing `tracepoints` and `matchings`. * @returns {Object} containing `tracepoints` and `matchings`.
* **`tracepoints`** Array of [`aypoint`](#waypoint) objects representing all points of the trace * **`tracepoints`** Array of [`aypoint`](#waypoint) objects representing all points of the trace in order.
* in order.
* If the trace point was ommited by map matching because it is an outlier, the entry will be null. * If the trace point was ommited by map matching because it is an outlier, the entry will be null.
* Each * Each `Waypoint` object includes two additional properties, 1) `matchings_index`: Index to the
* `Waypoint` object includes two additional properties, 1) `matchings_index`: Index to the
* [`Route`](#route) object in matchings the sub-trace was matched to, 2) `waypoint_index`: Index of * [`Route`](#route) object in matchings the sub-trace was matched to, 2) `waypoint_index`: Index of
* the waypoint inside the matched route. * the waypoint inside the matched route.
* **`matchings`** is an array of [`Route`](#route) objects that * **`matchings`** is an array of [`Route`](#route) objects that assemble the trace. Each `Route` object has an additional `confidence` property,
* assemble the trace. Each `Route` object has an additional `confidence` property, which is the * which is the confidence of the matching. float value between `0` and `1`. `1` is very confident that the matching is correct.
* confidence of
* the matching. float value between `0` and `1`. `1` is very confident that the matching is
* correct.
* *
* @example * @example
* var osrm = new OSRM('network.osrm'); * var osrm = new OSRM('network.osrm');
@ -390,11 +368,13 @@ NAN_METHOD(Engine::tile)
* }); * });
* *
*/ */
// clang-format on
NAN_METHOD(Engine::match) // NAN_METHOD(Engine::match) //
{ {
async(info, &argumentsToMatchParameter, &osrm::OSRM::Match, true); async(info, &argumentsToMatchParameter, &osrm::OSRM::Match, true);
} }
// clang-format off
/** /**
* The trip plugin solves the Traveling Salesman Problem using a greedy heuristic * The trip plugin solves the Traveling Salesman Problem using a greedy heuristic
* (farthest-insertion algorithm) for 10 or * more waypoints and uses brute force for less than 10 * (farthest-insertion algorithm) for 10 or * more waypoints and uses brute force for less than 10
@ -406,11 +386,9 @@ NAN_METHOD(Engine::match) //
* @memberof OSRM * @memberof OSRM
* @param {Object} options - Object literal containing parameters for the trip query. * @param {Object} options - Object literal containing parameters for the trip query.
* @param {Boolean} [options.steps=false] Return route steps for each route. * @param {Boolean} [options.steps=false] Return route steps for each route.
* @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg. * @param {Boolean} or {Array} [options.annotations=false] Return annotations for each route leg. Can be `false`,
* Can be `false`, `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, * `true` or an array with strings of `duration`, `nodes`, `distance`, `weight`, `datasources`, `speed`.
* `datasources`, `speed`. * @param {String} [options.geometries=polyline] Returned route geometry format (influences overview and per step). Can also be `geojson`.
* @param {String} [options.geometries=polyline] Returned route geometry format (influences overview
* and per step). Can also be `geojson`.
* @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified` * @param {String} [options.overview=simplified] Add overview geometry either `full`, `simplified`
* @param {Function} callback * @param {Function} callback
* @param {Boolean} [options.roundtrip=true] Return route is a roundtrip. * @param {Boolean} [options.roundtrip=true] Return route is a roundtrip.
@ -418,11 +396,10 @@ NAN_METHOD(Engine::match) //
* @param {String} [options.destination=any] Return route ends at `any` or `last` coordinate. * @param {String} [options.destination=any] Return route ends at `any` or `last` coordinate.
* *
* @returns {Object} containing `waypoints` and `trips`. * @returns {Object} containing `waypoints` and `trips`.
* **`waypoints`**: an array of [`Waypoint`](#waypoint) objects representing all waypoints in input * **`waypoints`**: an array of [`Waypoint`](#waypoint) objects representing all waypoints in input order.
* order. * Each Waypoint object has the following additional properties,
* Each Waypoint object has the following additional properties, 1) `trips_index`: index to trips of * 1) `trips_index`: index to trips of the sub-trip the point was matched to,
* the * and 2) `waypoint_index`: index of the point in the trip.
* sub-trip the point was matched to, and 2) `waypoint_index`: index of the point in the trip.
* **`trips`**: an array of [`Route`](#route) objects that assemble the trace. * **`trips`**: an array of [`Route`](#route) objects that assemble the trace.
* *
* @example * @example
@ -439,6 +416,7 @@ NAN_METHOD(Engine::match) //
* console.log(response.trips); // array of Route objects * console.log(response.trips); // array of Route objects
* }); * });
*/ */
// clang-format on
NAN_METHOD(Engine::trip) // NAN_METHOD(Engine::trip) //
{ {
async(info, &argumentsToTripParameter, &osrm::OSRM::Trip, true); async(info, &argumentsToTripParameter, &osrm::OSRM::Trip, true);
@ -456,7 +434,7 @@ NAN_METHOD(Engine::trip) //
* @memberof Responses * @memberof Responses
* *
* @param {documentation} exteral in * @param {documentation} exteral in
* [`osrm-backend`](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#route) * [`osrm-backend`](../http.md#route)
* *
*/ */
@ -467,7 +445,7 @@ NAN_METHOD(Engine::trip) //
* @memberof Responses * @memberof Responses
* *
* @param {documentation} exteral in * @param {documentation} exteral in
* [`osrm-backend`](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#routeleg) * [`osrm-backend`](../http.md#routeleg)
* *
*/ */

View File

@ -1,6 +1,8 @@
var OSRM = require('../../'); var OSRM = require('../../');
var test = require('tape'); var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path; var berlin_path = require('./osrm-data-path').data_path;
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
test('constructor: throws if new keyword is not used', function(assert) { test('constructor: throws if new keyword is not used', function(assert) {
assert.plan(1); assert.plan(1);
@ -23,7 +25,7 @@ test('constructor: does not accept more than one parameter', function(assert) {
test('constructor: throws if necessary files do not exist', function(assert) { test('constructor: throws if necessary files do not exist', function(assert) {
assert.plan(1); assert.plan(1);
assert.throws(function() { new OSRM("missing.osrm"); }, assert.throws(function() { new OSRM("missing.osrm"); },
/Invalid file paths/); /Error opening missing.osrm.names/);
}); });
test('constructor: takes a shared memory argument', function(assert) { test('constructor: takes a shared memory argument', function(assert) {
@ -34,22 +36,52 @@ test('constructor: takes a shared memory argument', function(assert) {
test('constructor: throws if shared_memory==false with no path defined', function(assert) { test('constructor: throws if shared_memory==false with no path defined', function(assert) {
assert.plan(1); assert.plan(1);
assert.throws(function() { var osrm = new OSRM({shared_memory: false}); }, assert.throws(function() { new OSRM({shared_memory: false}); },
/Shared_memory must be enabled if no path is specified/); /Shared_memory must be enabled if no path is specified/);
}); });
test('constructor: throws if given a non-bool shared_memory option', function(assert) { test('constructor: throws if given a non-bool shared_memory option', function(assert) {
assert.plan(1); assert.plan(1);
assert.throws(function() { var osrm = new OSRM({path: berlin_path, shared_memory: "a"}); }, assert.throws(function() { new OSRM({path: berlin_path, shared_memory: 'a'}); },
/Shared_memory option must be a boolean/); /Shared_memory option must be a boolean/);
}); });
test('constructor: throws if given a non-string/obj argument', function(assert) { test('constructor: throws if given a non-string/obj argument', function(assert) {
assert.plan(1); assert.plan(1);
assert.throws(function() { var osrm = new OSRM(true); }, assert.throws(function() { new OSRM(true); },
/Parameter must be a path or options object/); /Parameter must be a path or options object/);
}); });
test('constructor: throws if given an unkown algorithm', function(assert) {
assert.plan(1);
assert.throws(function() { new OSRM({algorithm: 'Foo', shared_memory: true}); },
/algorithm option must be one of 'CH', 'CoreCH', or 'MLD'/);
});
test('constructor: throws if given an invalid algorithm', function(assert) {
assert.plan(1);
assert.throws(function() { new OSRM({algorithm: 3, shared_memory: true}); },
/algorithm option must be a string and one of 'CH', 'CoreCH', or 'MLD'/);
});
test('constructor: loads MLD if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'MLD', path: berlin_mld_path});
assert.ok(osrm);
});
test('constructor: loads CH if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'CH', path: berlin_path});
assert.ok(osrm);
});
test('constructor: loads CoreCH if given as algorithm', function(assert) {
assert.plan(1);
var osrm = new OSRM({algorithm: 'CoreCH', path: berlin_corech_path});
assert.ok(osrm);
});
require('./route.js'); require('./route.js');
require('./trip.js'); require('./trip.js');
require('./match.js'); require('./match.js');

View File

@ -2,7 +2,11 @@ var path = require('path');
if (process.env.OSRM_DATA_PATH !== undefined) { if (process.env.OSRM_DATA_PATH !== undefined) {
exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/berlin.osrm"); exports.data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "ch/berlin.osrm");
exports.mld_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "mld/berlin.osrm");
exports.corech_data_path = path.join(path.resolve(process.env.OSRM_DATA_PATH), "corech/berlin.osrm");
console.log('Setting custom data path to ' + exports.data_path); console.log('Setting custom data path to ' + exports.data_path);
} else { } else {
exports.data_path = path.resolve(path.join(__dirname, "../data/ch/berlin.osrm")); exports.data_path = path.resolve(path.join(__dirname, "../data/ch/berlin.osrm"));
exports.mld_data_path = path.resolve(path.join(__dirname, "../data/mld/berlin.osrm"));
exports.corech_data_path = path.resolve(path.join(__dirname, "../data/corech/berlin.osrm"));
} }

View File

@ -1,6 +1,8 @@
var OSRM = require('../../'); var OSRM = require('../../');
var test = require('tape'); var test = require('tape');
var berlin_path = require('./osrm-data-path').data_path; var berlin_path = require('./osrm-data-path').data_path;
var berlin_mld_path = require('./osrm-data-path').mld_data_path;
var berlin_corech_path = require('./osrm-data-path').corech_data_path;
test('route: routes Berlin', function(assert) { test('route: routes Berlin', function(assert) {
assert.plan(5); assert.plan(5);
@ -14,6 +16,30 @@ test('route: routes Berlin', function(assert) {
}); });
}); });
test('route: routes Berlin on MLD', function(assert) {
assert.plan(5);
var osrm = new OSRM({path: berlin_mld_path, algorithm: 'MLD'});
osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, route) {
assert.ifError(err);
assert.ok(route.waypoints);
assert.ok(route.routes);
assert.ok(route.routes.length);
assert.ok(route.routes[0].geometry);
});
});
test('route: routes Berlin on CoreCH', function(assert) {
assert.plan(5);
var osrm = new OSRM({path: berlin_corech_path, algorithm: 'CoreCH'});
osrm.route({coordinates: [[13.43864,52.51993],[13.415852,52.513191]]}, function(err, route) {
assert.ifError(err);
assert.ok(route.waypoints);
assert.ok(route.routes);
assert.ok(route.routes.length);
assert.ok(route.routes[0].geometry);
});
});
test('route: throws with too few or invalid args', function(assert) { test('route: throws with too few or invalid args', function(assert) {
assert.plan(3); assert.plan(3);
var osrm = new OSRM(berlin_path); var osrm = new OSRM(berlin_path);

6179
yarn.lock Normal file

File diff suppressed because it is too large Load Diff