From 1c41efe57a74fb498856865178f564e56d36823c Mon Sep 17 00:00:00 2001 From: Siarhei Fedartsou Date: Fri, 11 Nov 2022 22:07:15 +0100 Subject: [PATCH] wip --- include/nodejs/node_osrm.hpp | 33 ----------------------------- package.json | 3 +-- src/nodejs/CMakeLists.txt | 3 ++- src/nodejs/node_osrm.cpp | 41 ++++++++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 36 deletions(-) diff --git a/include/nodejs/node_osrm.hpp b/include/nodejs/node_osrm.hpp index ddaf23dd8..513bd3704 100644 --- a/include/nodejs/node_osrm.hpp +++ b/include/nodejs/node_osrm.hpp @@ -29,37 +29,4 @@ class Engine : public Napi::ObjectWrap } // namespace node_osrm -// namespace node_osrm -// { - -// struct Engine final : public Nan::ObjectWrap -// { -// using Base = Nan::ObjectWrap; - -// static NAN_MODULE_INIT(Init); - -// static NAN_METHOD(New); - -// static NAN_METHOD(route); -// static NAN_METHOD(nearest); -// static NAN_METHOD(table); -// static NAN_METHOD(tile); -// static NAN_METHOD(match); -// static NAN_METHOD(trip); - -// Engine(osrm::EngineConfig &config); - -// // Thread-safe singleton accessor -// static Nan::Persistent &constructor(); - -// // Ref-counted OSRM alive even after shutdown until last callback is done -// std::shared_ptr this_; -// }; - -// } // namespace node_osrm - -// #pragma GCC diagnostic push -// #pragma GCC diagnostic ignored "-Wunused-parameter" -// NAN_MODULE_WORKER_ENABLED(osrm, node_osrm::Engine::Init) -// #pragma GCC diagnostic pop #endif diff --git a/package.json b/package.json index 3919ee8ff..8a3657e7a 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "browserify": "^17.0.0", "chalk": "^1.1.3", "cheap-ruler": "^3.0.2", - "cmake-js": "^7.0.0", "command-line-args": "^5.2.1", "command-line-usage": "^5.0.4", "csv-stringify": "^3.0.0", @@ -76,7 +75,7 @@ "module_path": "./lib/binding/", "host": "https://github.com", "remote_path": "./Project-OSRM/osrm-backend/releases/download/v{version}/", - "package_name": "{module_name}-v{version}-{node_abi}-{platform}-{arch}-{configuration}.tar.gz" + "package_name": "{module_name}-v{version}-{node_abi}-{napi_build_version}-{platform}-{arch}-{configuration}.tar.gz" }, "publishConfig": { "access": "public" diff --git a/src/nodejs/CMakeLists.txt b/src/nodejs/CMakeLists.txt index eb5d84689..04a2a78fd 100644 --- a/src/nodejs/CMakeLists.txt +++ b/src/nodejs/CMakeLists.txt @@ -22,6 +22,7 @@ set_target_properties(node_osrm PROPERTIES CXX_CLANG_TIDY "") target_no_warning(node_osrm suggest-destructor-override) target_no_warning(node_osrm suggest-override) +# https://github.com/cjntaylor/node-cmake/issues/53#issuecomment-842357457 execute_process(COMMAND node -p "require('node-addon-api').include" WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} OUTPUT_VARIABLE NODE_ADDON_API_DIR) string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) @@ -65,4 +66,4 @@ list(APPEND ARTIFACTS "${BINDING_DIR}/node_osrm.node") message(STATUS "node_osrm artifacts will be copied to: ${BINDING_DIR}") -add_custom_target(copy_artifacts ALL DEPENDS ${ARTIFACTS}) \ No newline at end of file +add_custom_target(copy_artifacts ALL DEPENDS ${ARTIFACTS}) diff --git a/src/nodejs/node_osrm.cpp b/src/nodejs/node_osrm.cpp index 238ed6308..cf4190061 100644 --- a/src/nodejs/node_osrm.cpp +++ b/src/nodejs/node_osrm.cpp @@ -45,6 +45,47 @@ Napi::Object Engine::Init(Napi::Env env, Napi::Object exports) return exports; } +// clang-format off +/** + * The `OSRM` method is the main constructor for creating an OSRM instance. + * An OSRM instance requires a `.osrm.*` dataset(`.osrm.*` because it contains several files), which is prepared by the OSRM toolchain. + * You can create such a `.osrm.*` dataset by running the OSRM binaries we ship in `node_modules/osrm/lib/binding/` and default + * profiles (e.g. for setting speeds and determining road types to route on) in `node_modules/osrm/profiles/`: + * + * node_modules/osrm/lib/binding/osrm-extract data.osm.pbf -p node_modules/osrm/profiles/car.lua + * node_modules/osrm/lib/binding/osrm-contract data.osrm + * + * Consult the [osrm-backend](https://github.com/Project-OSRM/osrm-backend) documentation for further details. + * + * Once you have a complete `network.osrm.*` dataset, you can calculate routes in javascript with this object. + * + * ```javascript + * var osrm = new OSRM('network.osrm'); + * ``` + * + * @param {Object|String} [options={shared_memory: true}] Options for creating an OSRM object or string to the `.osrm` file. + * @param {String} [options.algorithm] The algorithm to use for routing. Can be 'CH', 'CoreCH' or 'MLD'. Default is 'CH'. + * Make sure you prepared the dataset with the correct toolchain. + * @param {Boolean} [options.shared_memory] Connects to the persistent shared memory datastore. + * This requires you to run `osrm-datastore` prior to creating an `OSRM` object. + * @param {String} [options.dataset_name] Connects to the persistent shared memory datastore defined by `--dataset_name` option when running `osrm-datastore`. + * This requires you to run `osrm-datastore --dataset_name` prior to creating an `OSRM` object. + * @param {String} [options.memory_file] **DEPRECATED** + * Old behaviour: Path to a file on disk to store the memory using mmap. Current behaviour: setting this value is the same as setting `mmap_memory: true`. + * @param {Boolean} [options.mmap_memory] Map on-disk files to virtual memory addresses (mmap), rather than loading into RAM. + * @param {String} [options.path] The path to the `.osrm` files. This is mutually exclusive with setting {options.shared_memory} to true. + * @param {Number} [options.max_locations_trip] Max. locations supported in trip query (default: unlimited). + * @param {Number} [options.max_locations_viaroute] Max. locations supported in viaroute query (default: unlimited). + * @param {Number} [options.max_locations_distance_table] Max. locations supported in distance table query (default: unlimited). + * @param {Number} [options.max_locations_map_matching] Max. locations supported in map-matching query (default: unlimited). + * @param {Number} [options.max_radius_map_matching] Max. radius size supported in map matching query (default: 5). + * @param {Number} [options.max_results_nearest] Max. results supported in nearest query (default: unlimited). + * @param {Number} [options.max_alternatives] Max. number of alternatives supported in alternative routes query (default: 3). + * + * @class OSRM + * + */ +// clang-format on Engine::Engine(const Napi::CallbackInfo &info) : Napi::ObjectWrap(info) {