npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

osm-road-graph

v0.0.1

Published

```sh npm i osm-road-graph ``` ## Usage examples: ### Initialize: ```js import RoadGraph from 'osm-road-graph/lib/roadGraph'; import {elements as roads_graph} from 'osm-road-graph/test/with_footways.json';

Downloads

13

Readme

Install:

npm i osm-road-graph

Usage examples:

Initialize:

import RoadGraph from 'osm-road-graph/lib/roadGraph';
import {elements as roads_graph} from 'osm-road-graph/test/with_footways.json';

const roadGraph = RoadGraph.fromOsmGraph(roads_graph, RoadGraph.GraphTypes.pedestrian);

Ways finding:

Find way by coords:

const coords1 = {lat: 53.68350, lng: 23.83437};
const coords2 = {lat: 53.67722, lng: 23.82298};

const result = roadGraph.findShortestWayByCoords(coords1, coords2);

Find way between road graph nodes (works faster than counting by coords):

const node1 = roadGraph.nodes[5];
const node2 = roadGraph.nodes[100];

const result = roadGraph.findShortestWay(node1, node2);

Result:

{ 
  distance: 7355,
  polyline: [ 
    {lat: 53.68350, lng: 23.83437},
      ...
    {lat: 53.67722, lng: 23.82298}
  ]
}

Distance matrix calculation:

Basic:

let points = [ {lat: 53.67719, lng: 23.823}, {lat: 53.68384, lng: 23.83443}, {lat: 53.68817, lng: 23.84796} ];
const distanceMatrix = roadGraph.makeDistanceMatrix(points);

Results - Distance matrix:

[ 
  [point_object_1]: [ 
    { key: [point_object_2], distance: 1234 },
    ...
   ],
   ...
]

Extended:

makeDistanceMatrix params:

points, // Any collection of objects which have coords

gettingCoordsFunc = null, // A function which must returns {lat, lng} from object

distanceLimit = Infinity, // Maximal distance which can be added into distance matrix

gettingPointIdentificatorFunc = null, // A function which returns key from object (by default is same object)

updatingPointFunc = null // A function for collection object modifying

Example:

let points = [
    {
        name: "Castle",
        coords: {lat: 53.67719, lng: 23.823}
    }, {
        name: "City Square",
        coords: {lat: 53.68384, lng: 23.83443}
    }, {
        name: "Zoo",
        coords: {lat: 53.68817, lng: 23.84796}
    }
];
const gettingCoordsFunc = (p => p.coords);
const gettingPointIdentificatorFunc = (p => p.name);
const updatingPointFunc = (function(currentPoint, otherPoint, distance){
    if (!currentPoint.distances) currentPoint.distances = [];
    currentPoint.distances.push({point: otherPoint.name, distance});
});
const distanceMatrix = roadGraph.makeDistanceMatrix(points, gettingCoordsFunc, 1500, gettingPointIdentificatorFunc, updatingPointFunc);

Results - Distance matrix:

[ 
  'Castle': [ 
    { key: 'City Square', distance: 1202 } 
   ],
  'City Square': [ 
    { key: 'Castle', distance: 1202 },
    { key: 'Zoo', distance: 1242 } 
  ],
  'Zoo': [ 
    { key: 'City Square', distance: 1242 } 
  ]
]

Results - Modified points object:

[ 
  { 
    name: 'Castle',
    coords: { lat: 53.67719, lng: 23.823 },
    distances: [ {point: "City Square", distance: 1202}, ... ] 
  },
  ...
]

Todo:

  • [x] Add function for generating distance matrix.
  • [ ] Jump through single-way-out nodes.
  • [ ] Prolong a found path to the nearest roads intersection if the destination is on the other side of the road (for vehicles).