├── .github
└── workflows
│ └── static.yml
├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── docs
├── .nojekyll
├── assets
│ ├── highlight.css
│ ├── main.js
│ ├── search.js
│ └── style.css
├── classes
│ └── index.default.html
├── index.html
├── modules.html
├── modules
│ ├── index.html
│ └── types.html
└── types
│ ├── types.Coordinates.html
│ ├── types.Edge.html
│ ├── types.Key.html
│ ├── types.PathFinderGraph.html
│ ├── types.PathFinderOptions.html
│ ├── types.Topology.html
│ ├── types.Vertex.html
│ └── types.Vertices.html
├── package-lock.json
├── package.json
├── src
├── compactor.ts
├── dijkstra.ts
├── index.ts
├── preprocessor.ts
├── round-coord.ts
├── topology.ts
└── types.ts
├── test
├── 66.json
├── advent24.json
├── compactor.spec.js
├── large-network.json
├── network.json
├── osm-weight.js
├── path.spec.js
├── preprocessor.spec.js
├── topologySpec.js
└── two-islands.json
├── tsconfig.cjs.json
└── tsconfig.json
/.github/workflows/static.yml:
--------------------------------------------------------------------------------
1 | # Simple workflow for deploying static content to GitHub Pages
2 | name: Deploy static content to Pages
3 |
4 | on:
5 | # Runs on pushes targeting the default branch
6 | push:
7 | branches: ["gh-pages"]
8 |
9 | # Allows you to run this workflow manually from the Actions tab
10 | workflow_dispatch:
11 |
12 | # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
13 | permissions:
14 | contents: read
15 | pages: write
16 | id-token: write
17 |
18 | # Allow one concurrent deployment
19 | concurrency:
20 | group: "pages"
21 | cancel-in-progress: true
22 |
23 | jobs:
24 | # Single deploy job since we're just deploying
25 | deploy:
26 | environment:
27 | name: github-pages
28 | url: ${{ steps.deployment.outputs.page_url }}
29 | runs-on: ubuntu-latest
30 | steps:
31 | - name: Checkout
32 | uses: actions/checkout@v4
33 | - name: Set up Node
34 | uses: actions/setup-node@v4
35 | with:
36 | node-version: lts/*
37 | cache: "npm"
38 | - name: Install dependencies
39 | run: npm ci
40 | - name: Build
41 | run: npm run build
42 | - name: Setup Pages
43 | uses: actions/configure-pages@v5
44 | - name: Upload artifact
45 | uses: actions/upload-pages-artifact@v3
46 | with:
47 | # Upload dist folder
48 | path: "./dist"
49 | - name: Deploy to GitHub Pages
50 | id: deployment
51 | uses: actions/deploy-pages@v4
52 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | dist/
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "8"
4 | - "10"
5 | - "12"
6 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | ## ISC License
2 |
3 | Copyright (c) 2016, Per Liedman (per@liedman.net)
4 |
5 | Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6 |
7 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GeoJSON Path Finder
2 |
3 | [](https://travis-ci.org/perliedman/geojson-path-finder)
4 |
5 | Find shortest paths through a network of GeoJSON.
6 |
7 | Given a network of GeoJSON `LineString`s, GeoJSON Path Finder will find the shortest path between two points in the network. This might be useful for automatic route searches in smaller networks, where setting up a real route planner like OSRM is too much work, or you simply need to do everything on the client.
8 |
9 | See the [GeoJSON Path Finder demo](https://www.liedman.net/geojson-path-finder/).
10 |
11 | _Upgrade notice_ Version 2.0 has been released, which is a TypeScript rewrite - you can still use the module from plain JavaScript, of course. This version also contains some breaking changes regarding option naming; for most common use cases, everything will work as before.
12 |
13 | Breaking changes:
14 |
15 | - option `precision` is now named `tolerance`
16 | - option `keyFn` is now named `key`
17 | - option `weightFn` is now named `weight`
18 | - option `edgeDataReduceFn` is now named `edgeDataReducer`
19 | - option `edgeDataSeed` is now _a function_ taking the properties of the start node
20 |
21 | ## Installing
22 |
23 | ```
24 | npm install --save geojson-path-finder
25 | ```
26 |
27 | ## API
28 |
29 | Detailed (and somewhat experimental) [API Docs](https://www.liedman.net/geojson-path-finder/docs/)
30 |
31 | Create a path finding object:
32 |
33 | ```javascript
34 | import PathFinder from "geojson-path-finder";
35 | import geojson from "./network.json";
36 |
37 | const pathFinder = new PathFinder(geojson);
38 | ```
39 |
40 | The GeoJSON object should be a `FeatureCollection` of `LineString` features. The network will be built
41 | into a topology, so that lines that start and end, or cross, at the same coordinate are joined such that
42 | you can find a path from one feature to the other.
43 |
44 | To find the shortest path between two coordinates:
45 |
46 | ```javascript
47 | var path = pathFinder.findPath(start, finish);
48 | ```
49 |
50 | Where `start` and `finish` are two GeoJSON `point` features. Note that both points _have to_ be vertices in the routing network; if they are not, no route will be found.
51 |
52 | If a route can be found, an object with two properties: `path` and `weight` is returned, where `path`
53 | is the coordinates the path runs through, and `weight` is the total weight (distance in kilometers, if you use the default weight function) of the path.
54 |
55 | As a convenience, the function `pathToGeoJSON` is also exported, it converts the result of a `findPath` call to
56 | a GeoJSON linestring:
57 |
58 | ```javascript
59 | import PathFinder, { pathToGeoJSON } from "geojson-path-finder";
60 | const pathFinder = new PathFinder(geojson);
61 | const pathLineString = pathToGeoJSON(pathFinder.findPath(start, finish));
62 | ```
63 |
64 | (If `findPath` does not find a path, pathToGeoJSON will also return `undefined`.)
65 |
66 | ### `PathFinder` options
67 |
68 | The `PathFinder` constructor takes an optional seconds parameter containing `options` that you can
69 | use to control the behaviour of the path finder. Available options:
70 |
71 | - `weight` controls how the weight (or cost) of travelling between two vertices is calculated;
72 | by default, the geographic distance between the coordinates is calculated and used as weight;
73 | see [Weight functions](#weight-functions) below for details
74 | - `tolerance` (default `1e-5`) controls the tolerance for how close vertices in the GeoJSON can be
75 | before considered being the same vertice; you can say that coordinates closer than this will be
76 | snapped together into one coordinate
77 | - `edgeDataReducer` can optionally be used to store data present in the GeoJSON on each edge of
78 | the routing graph; typically, this can be used for storing things like street names; if specified,
79 | the reduced data is present on found paths under the `edgeDatas` property
80 | - `edgeDataSeed` is a function returning taking a network feature's `properties` as argument and returning the seed used when reducing edge data with the `edgeDataReducer` above
81 |
82 | ## Weight functions
83 |
84 | By default, the _cost_ of going from one node in the network to another is determined simply by
85 | the geographic distance between the two nodes. This means that, by default, shortest paths will be found.
86 | You can however override this by providing a cost calculation function through the `weight` option:
87 |
88 | ```javascript
89 | const pathFinder = new PathFinder(geojson, {
90 | weight: function (a, b, props) {
91 | const dx = a[0] - b[0];
92 | const dy = a[1] - b[1];
93 | return Math.sqrt(dx * dx + dy * dy);
94 | },
95 | });
96 | ```
97 |
98 | The weight function is passed two coordinate arrays (in GeoJSON axis order), as well as the feature properties
99 | that are associated with this feature, and should return either:
100 |
101 | - a numeric value for the cost of travelling between the two coordinates; in this case, the cost is assumed
102 | to be the same going from `a` to `b` as going from `b` to `a`; as cost of `0` means the edge can't be used
103 | - an object with two properties: `forward` and `backward`; in this case,
104 | `forward` denotes the cost of going from `a` to `b`, and
105 | `backward` the cost of going from `b` to `a`; setting either
106 | to `0` will prevent taking that direction, the segment will be a oneway.
107 | - `undefined` is the same as setting the weight to `0`: this edge can't be used
108 |
--------------------------------------------------------------------------------
/docs/.nojekyll:
--------------------------------------------------------------------------------
1 | TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
--------------------------------------------------------------------------------
/docs/assets/highlight.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --light-hl-0: #001080;
3 | --dark-hl-0: #9CDCFE;
4 | --light-hl-1: #000000;
5 | --dark-hl-1: #D4D4D4;
6 | --light-hl-2: #0000FF;
7 | --dark-hl-2: #569CD6;
8 | --light-hl-3: #795E26;
9 | --dark-hl-3: #DCDCAA;
10 | --light-hl-4: #A31515;
11 | --dark-hl-4: #CE9178;
12 | --light-hl-5: #098658;
13 | --dark-hl-5: #B5CEA8;
14 | --light-hl-6: #AF00DB;
15 | --dark-hl-6: #C586C0;
16 | --light-code-background: #FFFFFF;
17 | --dark-code-background: #1E1E1E;
18 | }
19 |
20 | @media (prefers-color-scheme: light) { :root {
21 | --hl-0: var(--light-hl-0);
22 | --hl-1: var(--light-hl-1);
23 | --hl-2: var(--light-hl-2);
24 | --hl-3: var(--light-hl-3);
25 | --hl-4: var(--light-hl-4);
26 | --hl-5: var(--light-hl-5);
27 | --hl-6: var(--light-hl-6);
28 | --code-background: var(--light-code-background);
29 | } }
30 |
31 | @media (prefers-color-scheme: dark) { :root {
32 | --hl-0: var(--dark-hl-0);
33 | --hl-1: var(--dark-hl-1);
34 | --hl-2: var(--dark-hl-2);
35 | --hl-3: var(--dark-hl-3);
36 | --hl-4: var(--dark-hl-4);
37 | --hl-5: var(--dark-hl-5);
38 | --hl-6: var(--dark-hl-6);
39 | --code-background: var(--dark-code-background);
40 | } }
41 |
42 | :root[data-theme='light'] {
43 | --hl-0: var(--light-hl-0);
44 | --hl-1: var(--light-hl-1);
45 | --hl-2: var(--light-hl-2);
46 | --hl-3: var(--light-hl-3);
47 | --hl-4: var(--light-hl-4);
48 | --hl-5: var(--light-hl-5);
49 | --hl-6: var(--light-hl-6);
50 | --code-background: var(--light-code-background);
51 | }
52 |
53 | :root[data-theme='dark'] {
54 | --hl-0: var(--dark-hl-0);
55 | --hl-1: var(--dark-hl-1);
56 | --hl-2: var(--dark-hl-2);
57 | --hl-3: var(--dark-hl-3);
58 | --hl-4: var(--dark-hl-4);
59 | --hl-5: var(--dark-hl-5);
60 | --hl-6: var(--dark-hl-6);
61 | --code-background: var(--dark-code-background);
62 | }
63 |
64 | .hl-0 { color: var(--hl-0); }
65 | .hl-1 { color: var(--hl-1); }
66 | .hl-2 { color: var(--hl-2); }
67 | .hl-3 { color: var(--hl-3); }
68 | .hl-4 { color: var(--hl-4); }
69 | .hl-5 { color: var(--hl-5); }
70 | .hl-6 { color: var(--hl-6); }
71 | pre, code { background: var(--code-background); }
72 |
--------------------------------------------------------------------------------
/docs/assets/search.js:
--------------------------------------------------------------------------------
1 | window.searchData = JSON.parse("{\"kinds\":{\"2\":\"Module\",\"128\":\"Class\",\"512\":\"Constructor\",\"1024\":\"Property\",\"2048\":\"Method\",\"65536\":\"Type literal\",\"4194304\":\"Type alias\"},\"rows\":[{\"kind\":2,\"name\":\"index\",\"url\":\"modules/index.html\",\"classes\":\"tsd-kind-module\"},{\"kind\":128,\"name\":\"default\",\"url\":\"classes/index.default.html\",\"classes\":\"tsd-kind-class tsd-parent-kind-module\",\"parent\":\"index\"},{\"kind\":512,\"name\":\"constructor\",\"url\":\"classes/index.default.html#constructor\",\"classes\":\"tsd-kind-constructor tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":1024,\"name\":\"graph\",\"url\":\"classes/index.default.html#graph\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":1024,\"name\":\"options\",\"url\":\"classes/index.default.html#options\",\"classes\":\"tsd-kind-property tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":2048,\"name\":\"findPath\",\"url\":\"classes/index.default.html#findPath\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":2048,\"name\":\"_createPhantom\",\"url\":\"classes/index.default.html#_createPhantom\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":2048,\"name\":\"_removePhantom\",\"url\":\"classes/index.default.html#_removePhantom\",\"classes\":\"tsd-kind-method tsd-parent-kind-class\",\"parent\":\"index.default\"},{\"kind\":2,\"name\":\"types\",\"url\":\"modules/types.html\",\"classes\":\"tsd-kind-module\"},{\"kind\":4194304,\"name\":\"Key\",\"url\":\"types/types.Key.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":4194304,\"name\":\"Edge\",\"url\":\"types/types.Edge.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":4194304,\"name\":\"Topology\",\"url\":\"types/types.Topology.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/types.Topology.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"types.Topology\"},{\"kind\":1024,\"name\":\"vertices\",\"url\":\"types/types.Topology.html#__type.vertices\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.Topology.__type\"},{\"kind\":1024,\"name\":\"edges\",\"url\":\"types/types.Topology.html#__type.edges\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.Topology.__type\"},{\"kind\":4194304,\"name\":\"Vertex\",\"url\":\"types/types.Vertex.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":4194304,\"name\":\"Vertices\",\"url\":\"types/types.Vertices.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":4194304,\"name\":\"Coordinates\",\"url\":\"types/types.Coordinates.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":4194304,\"name\":\"PathFinderGraph\",\"url\":\"types/types.PathFinderGraph.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"},{\"kind\":65536,\"name\":\"__type\",\"url\":\"types/types.PathFinderGraph.html#__type\",\"classes\":\"tsd-kind-type-literal tsd-parent-kind-type-alias\",\"parent\":\"types.PathFinderGraph\"},{\"kind\":1024,\"name\":\"vertices\",\"url\":\"types/types.PathFinderGraph.html#__type.vertices\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":1024,\"name\":\"edgeData\",\"url\":\"types/types.PathFinderGraph.html#__type.edgeData\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":1024,\"name\":\"sourceCoordinates\",\"url\":\"types/types.PathFinderGraph.html#__type.sourceCoordinates\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":1024,\"name\":\"compactedVertices\",\"url\":\"types/types.PathFinderGraph.html#__type.compactedVertices\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":1024,\"name\":\"compactedCoordinates\",\"url\":\"types/types.PathFinderGraph.html#__type.compactedCoordinates\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":1024,\"name\":\"compactedEdges\",\"url\":\"types/types.PathFinderGraph.html#__type.compactedEdges\",\"classes\":\"tsd-kind-property tsd-parent-kind-type-literal\",\"parent\":\"types.PathFinderGraph.__type\"},{\"kind\":4194304,\"name\":\"PathFinderOptions\",\"url\":\"types/types.PathFinderOptions.html\",\"classes\":\"tsd-kind-type-alias tsd-parent-kind-module\",\"parent\":\"types\"}],\"index\":{\"version\":\"2.3.9\",\"fields\":[\"name\",\"comment\"],\"fieldVectors\":[[\"name/0\",[0,29.267]],[\"comment/0\",[]],[\"name/1\",[1,29.267]],[\"comment/1\",[]],[\"name/2\",[2,29.267]],[\"comment/2\",[]],[\"name/3\",[3,29.267]],[\"comment/3\",[]],[\"name/4\",[4,29.267]],[\"comment/4\",[]],[\"name/5\",[5,29.267]],[\"comment/5\",[]],[\"name/6\",[6,29.267]],[\"comment/6\",[]],[\"name/7\",[7,29.267]],[\"comment/7\",[]],[\"name/8\",[8,29.267]],[\"comment/8\",[]],[\"name/9\",[9,29.267]],[\"comment/9\",[]],[\"name/10\",[10,29.267]],[\"comment/10\",[]],[\"name/11\",[11,29.267]],[\"comment/11\",[]],[\"name/12\",[12,24.159]],[\"comment/12\",[]],[\"name/13\",[13,20.794]],[\"comment/13\",[]],[\"name/14\",[14,29.267]],[\"comment/14\",[]],[\"name/15\",[15,29.267]],[\"comment/15\",[]],[\"name/16\",[13,20.794]],[\"comment/16\",[]],[\"name/17\",[16,29.267]],[\"comment/17\",[]],[\"name/18\",[17,29.267]],[\"comment/18\",[]],[\"name/19\",[12,24.159]],[\"comment/19\",[]],[\"name/20\",[13,20.794]],[\"comment/20\",[]],[\"name/21\",[18,29.267]],[\"comment/21\",[]],[\"name/22\",[19,29.267]],[\"comment/22\",[]],[\"name/23\",[20,29.267]],[\"comment/23\",[]],[\"name/24\",[21,29.267]],[\"comment/24\",[]],[\"name/25\",[22,29.267]],[\"comment/25\",[]],[\"name/26\",[23,29.267]],[\"comment/26\",[]]],\"invertedIndex\":[[\"__type\",{\"_index\":12,\"name\":{\"12\":{},\"19\":{}},\"comment\":{}}],[\"_createphantom\",{\"_index\":6,\"name\":{\"6\":{}},\"comment\":{}}],[\"_removephantom\",{\"_index\":7,\"name\":{\"7\":{}},\"comment\":{}}],[\"compactedcoordinates\",{\"_index\":21,\"name\":{\"24\":{}},\"comment\":{}}],[\"compactededges\",{\"_index\":22,\"name\":{\"25\":{}},\"comment\":{}}],[\"compactedvertices\",{\"_index\":20,\"name\":{\"23\":{}},\"comment\":{}}],[\"constructor\",{\"_index\":2,\"name\":{\"2\":{}},\"comment\":{}}],[\"coordinates\",{\"_index\":16,\"name\":{\"17\":{}},\"comment\":{}}],[\"default\",{\"_index\":1,\"name\":{\"1\":{}},\"comment\":{}}],[\"edge\",{\"_index\":10,\"name\":{\"10\":{}},\"comment\":{}}],[\"edgedata\",{\"_index\":18,\"name\":{\"21\":{}},\"comment\":{}}],[\"edges\",{\"_index\":14,\"name\":{\"14\":{}},\"comment\":{}}],[\"findpath\",{\"_index\":5,\"name\":{\"5\":{}},\"comment\":{}}],[\"graph\",{\"_index\":3,\"name\":{\"3\":{}},\"comment\":{}}],[\"index\",{\"_index\":0,\"name\":{\"0\":{}},\"comment\":{}}],[\"key\",{\"_index\":9,\"name\":{\"9\":{}},\"comment\":{}}],[\"options\",{\"_index\":4,\"name\":{\"4\":{}},\"comment\":{}}],[\"pathfindergraph\",{\"_index\":17,\"name\":{\"18\":{}},\"comment\":{}}],[\"pathfinderoptions\",{\"_index\":23,\"name\":{\"26\":{}},\"comment\":{}}],[\"sourcecoordinates\",{\"_index\":19,\"name\":{\"22\":{}},\"comment\":{}}],[\"topology\",{\"_index\":11,\"name\":{\"11\":{}},\"comment\":{}}],[\"types\",{\"_index\":8,\"name\":{\"8\":{}},\"comment\":{}}],[\"vertex\",{\"_index\":15,\"name\":{\"15\":{}},\"comment\":{}}],[\"vertices\",{\"_index\":13,\"name\":{\"13\":{},\"16\":{},\"20\":{}},\"comment\":{}}]],\"pipeline\":[]}}");
--------------------------------------------------------------------------------
/docs/index.html:
--------------------------------------------------------------------------------
1 |
Given a network of GeoJSON LineStrings, GeoJSON Path Finder will find the shortest path between two points in the network. This might be useful for automatic route searches in smaller networks, where setting up a real route planner like OSRM is too much work,
22 | or you simply need to do everything on the client.
The GeoJSON object should be a FeatureCollection of LineString features. The network will be built
38 | into a topology, so that lines that start and end, or cross, at the same coordinate are joined such that
39 | you can find a path from one feature to the other.
40 |
To find the shortest path between two coordinates:
Where start and finish are two GeoJSON point features.
44 |
If a route can be found, an object with two properties: path and weight is returned, where path
45 | is the coordinates the path runs through, and weight is the total weight (distance in kilometers, if you use the default weight function) of the path.
The PathFinder constructor takes an optional seconds parameter containing options that you can
51 | use to control the behaviour of the path finder. Available options:
52 |
53 |
weightFn controls how the weight (or cost) of travelling between two vertices is calculated;
54 | by default, the geographic distance between the coordinates is calculated and used as weight;
55 | see Weight functions below for details
56 |
precision (default 1e-5) controls the tolerance for how close vertices in the GeoJSON can be
57 | before considered being the same vertice; you can say that coordinates closer than this will be
58 | snapped together into one coordinate
59 |
edgeDataReduceFn can optionally be used to store data present in the GeoJSON on each edge of
60 | the routing graph; typically, this can be used for storing things like street names; if specified,
61 | the reduced data is present on found paths under the edgeDatas property
62 |
edgeDataSeed is the seed used when reducing edge data with the edgeDataReduceFn above
By default, the cost of going from one node in the network to another is determined simply by
69 | the geographic distance between the two nodes. This means that, by default, shortest paths will be found.
70 | You can however override this by providing a cost calculation function through the weightFn option:
The weight function is passed two coordinate arrays (in GeoJSON axis order), as well as the feature properties
74 | that are associated with this feature, and should return either:
75 |
76 |
a numeric value for the cost of travelling between the two coordinates; in this case, the cost is assumed
77 | to be the same going from a to b as going from b to a
78 |
an object with two properties: forward and backward; in this case,
79 | forward denotes the cost of going from a to b, and
80 | backward the cost of going from b to a; setting either
81 | to 0, null or undefined will prevent taking that direction,
82 | the segment will be a oneway.
A graph vertex, containing the edges
21 | connecting it to other vertices;
22 | edges are described as a lookup withthe target vertex's
23 | key associated to the edge's weight
Edge from A to B, containing its vertex keys and associated properties
21 |