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

nearest-roads

v1.1.0

Published

Get nearest roads to a given location, or all roads within a bounding box.

Downloads

21

Readme

nearest-roads

Get nearest roads to a given location, or all roads within a bounding box.

Version 1.0.1: Breaking Backwards Compatibility

Previously, this module would only return an array containing all the names of roads that matched the query. Quite clearly though, this was fairly limited. It also didn't take full advantage of the data coming from OpenStreetMaps.

Therefore, this update now returns an array of objects - one for each road. Each road object contains the following fields:

  • name: Name of the road (yes, would you believe it.)
  • type: If the road is a [residential, tertiary, secondary, service, ...] road
  • oneway*: true if the road is a oneway
  • lit*: true if the road has lighting
  • lanes*: No. of lanes the road has
  • maxspeed*: The maximum permitted speed limit as an integer

*The existence of these fields for each road is entirely dependent on if there is such data in OSM i.e., these will only exist if the relevant data is present in OSM, otherwise the fields will be undefined.

N.B. Some of the fields of the road objects have been converted to a more programmatically consumable type when compared to OSM data.

I have also removed the array-unique dependency that this module used to have, as it is no longer relevant.

Finally, this completes the intended requirements that were laid out when I aimed to create this module. Hence due to breaking backwards compatibility, and completing the intended functionality of this module, this is officially version 1.x

Version 0.2.0: Bounding Box Support!

Previously, you could only retrieve the nearest roads to a central (lat, lon) location and a given radius distance.

Now, there is support for getting all the roads inside a Bounding box.

Installation

npm install nearest-roads --save

Usage

const nearestRoads = require('nearest-roads');

Nearest roads from a location: fromLocation(lat, long, distance, callback)

Returns an array containing the names of the roads that are within distance metres radius of lat long location.

nearestRoads.fromLocation(51.42, -0.148, 100, (err, data) => {
  if (err) console.log(err);
  else console.log(data);
});

Roads within a Bounding Box: boundingBox(northLat, eastLong, southLat, westLong, callback)

nearestRoads.boundingBox(51.5707755427, 0.922651543, 51.5046221724, 0.6790402342, (err, data) => {
  if (err) console.log(err);
  else console.log(data);
});

Example Return:

[ { name: 'Cuckoo Corner',
    type: 'trunk',
    oneway: true,
    lit: true,
    lanes: 2,
    maxspeed: 40 },
  { name: 'Prince Avenue',
    type: 'trunk',
    oneway: true,
    lit: true,
    lanes: 2,
    maxspeed: 40 },
  { name: 'Queensway',
    type: 'primary',
    oneway: true,
    lit: true,
    maxspeed: 40 },
  { name: 'Southchurch Avenue',
    type: 'primary',
    oneway: true,
    lit: true,
    maxspeed: 30 },
  { name: 'Prince Avenue',
    type: 'trunk',
    oneway: true,
    lit: true,
    lanes: 2,
    maxspeed: 40 },
    ...
    { name: 'Eastern Avenue', 
    type: 'primary', 
    maxspeed: 30 },
    ... 1526 more items ]

Contributing

This project adheres to the Airbnb JavaScript Style Guide.

Add unit tests for any new or changed functionality. Lint and test your code.