indoorgraphs
v0.0.86
Published
indoorgraphs is a node package that enables (client-side) routing in your mapping application.
Downloads
189
Readme
Campus Routing
indoorgraphs is a node package that enables (client-side) routing in your mapping application.
- Attribute-based queries (accessible): Graph nodes and edges can be assigned attributes which can then be used to determine accessible routes.
- Client-side: What is unique about the routing functionality is that it can be performed client-side rather than server-side using a routing engine. This eliminates the cost and maintenance of running a routing server. The routing graphs can be stored as simple JSON files and retrieved from a web server at runtime.
Documentation
The documentation is divided into several sections:
How to use this package?
From a Nodejs environment
To use this package, you will need to install Nodejs and the indoorgraphs package. You can install Nodejs from the official Nodejs website (https://nodejs.org/en), and the indoorgraphs package can be installed using npm:
npm install indoorgraphs
The package and the previously created graph can then be imported into a JavaScript environment:
// import indoorgraphs package
const { IndoorGraphs } = require("indoorgraphs");
// import routing graph
const data = require("./graph.json")
// instantiate a graph object and pass the routing data, routing options and a filter
const graph = new IndoorGraphs(data)
// calculate shortest path
const [coordinates, path, instructions, error] = graph.getRoute('EG_1', 'EG_2');
If no routing options and filters are specified, the corresponding objects remain empty (see { routingOptions: {}, filter: {} }
). If the attribute names do not match attributes in the graph, then they are ignored.
From a flutter environment
See here
From Indoorgraphs backend
The indoorgraphs backend comes with a REST API and a redis database that stores the graphs in memory for fast access.
1. Setup server
Clone the indoorgraphs-backend repository on your local machine.
Place all graphs that you want to query in src/graphs/
Start api and redis database: docker compose up -d
Test if API is running using curl: curl localhost:80
Add graphs to database: docker exec -it rest-api sh
-> sh initRedis.sh
-> exit
You can check if the graphs got successfully added to the database by exec'in into the container, open the redis cli and run a query:
docker exec -it redis sh
redis-cli
get <name of graph file (without .json), e.g. get test>
exit
To shutdown both containers and delete the images run: docker compose down --rmi local
2. Send queries
Use the following schema for the body of the POST request
{
"startNode": "UG_t3",
"destNode": "UG_t6",
"graphName": "<graphname without .json>",
"routingOptions": {
"pathOptions": {},
"doorOptions": {},
"preferElevator": false
}
}
curl
curl --location --request GET 'localhost:80/api/queries' \
--header 'Content-Type: application/json' \
--data '{
"startNode": "UG_t3",
"destNode": "UG_t6",
"graphName": "routingFive",
"graph": {"nodes":{"OD_t1":{"coordinates":[6.9399486133311035,50.943612032886136],"id":"OD_t1","type":"Node","level":"OD","adjacentNodes":["OD_t2"]},"OD_t2":{"coordinates":[6.927975232288623,50.935336961320644],"id":"OD_t2","type":"Node","level":"OD","adjacentNodes":["OD_t1"]}},"pathAttributes":{}}
}'
Nodejs axios
const axios = require('axios');
let data = JSON.stringify({
"startNode": "UG_t3",
"destNode": "UG_t6",
"graphName": "routingFive",
"routingOptions": {
"pathOptions": {},
"doorOptions": {},
"preferElevator": false
}
});
let config = {
method: 'get',
url: 'localhost:80/api/queries',
headers: {
'Content-Type': 'application/json'
},
data: data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});