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-dude

v1.0.5

Published

Tiny OSM (Open Street Maps) API Wrapper

Downloads

19

Readme

🌐 OSM Dude

GitHub forks GitHub stars bundle size npm downloads

Tiny OSM (Open Street Maps) API wrapper

👇 Installation

💚 Node

npm i osm-dude

⚡ Browser

<script src="https://combinatronics.com/EthanThatOneKid/osm-dude/master/dist/bundle.latest.js"></script>

🛠 Usage

const OsmDude = require('osm-dude');

🌟 Initialization

const osm = new OsmDude(
  lat, // float center latitude value
  lon, // float center longitude value
  latCoverage, // float total distance across latitude value
  lonCoverage, // float total distance across longitude value; optional
  {
    mapWidth: mapWidth, // value to map the coordinate boundaries to in the x-dimension; defaults to 1
    mapHeight: mapHeight // value to map the coordinate boundaries to in the y-dimension; defaults to 1
  } // settings
);

osm.init();

💡 Pro-tip: Utilize the test file as an example

📃 Documentation

init(elementInteractions)

  • where elementInteractions is a customizable interface for programs that wish to run with more detailed Open Street Map functionality; optional.
  • elementInteractions can also be set later on by calling setFeatureData).
  • asynchronous; returns once instance has been initialized.
  • returns nothing.

isReady()

  • returns true if any OSM data has been loaded.
  • returns false if no OSM data has been loaded.

render()

  • renders each element according to the customizable, optional element renderer declared in setElementRenderer.
  • returns nothing.

traverse(vel)

  • where vel is an object of keys lat and lon which represent the distance desired to travel to a new coordinate.
  • asynchronous; returns once incoming data has been accounted for.
  • returns nothing.

getCollisions(player)

  • where player is a supposed object of keys x and y representing a relative position within the mapped bounds of the OsmDude instance.
  • returns an array of OsmElement instances which overlap with the player's 2d position.

setFeatureData(elementInteractions)

  • where elementInteractions is a detailed object that helps your program know what to do based on an occurring landmark or what-have-you.
  • an example sheet can be found here.
  • returns nothing.

getElementInteractions(els)

  • where els is an array of OsmElement instances; intended to be used in conjunction with the result of getCollisions.
  • returns the data specified in the pre-defined element interactions from setFeatureData.

checkUnderneath(player)

  • where player is a supposed object of keys x and y representing a relative position within the mapped bounds of the OsmDude instance.
  • this is an alias who's input acts as getCollisions's and who's output acts as getElementInteractions's.
  • therefore, shares the same input convention as getCollisions and the same output convention as getElementInteractions.
  • returns all of the element interactions of all of the elements physically overlapping the player's coordinates.

getMapData()

  • returns the data parsed from the Open Street Map API's response.

getElements()

  • returns an array of OsmElement instances.

setBounds(bounds)

  • where bounds is an object of keys minLat, minLon, maxLat, and maxLon.
  • returns nothing.

setViewport(w, h)

  • where w and h are the respective mapWidth and mapHeight values from the initialization example.
  • returns nothing.

setElementRenderer(elementRenderer)

  • where elementRenderer is a function that takes arguments el and offset. el is an OsmElement instance and offset is an object of keys x and y which represents the mapped distance from the center traversed without reloading. If traverse has never been called, offset is negligible.
  • intended to render to a visual representation of all the elements of the loaded map. Some visual frameworks can be found here.
  • returns nothing.

getElementInteractionsTemplate()

  • returns an element interactions template as seen here.

minmax()

  • returns an object with data detailing the furthest points of the current pool vertices given by the OSM data.
  • This may be useful for debugging purposes.

log()

  • intended for debugging purposes.
  • prints to the console a summary of the data within the OsmDude instance.
  • returns an object that represents the summary printed to the console.

📝 Examples

📚 Reference

📜 License

Contains information from OpenStreetMap which is made available under the Open Database License. Any rights in individual contents of the database are licensed under the Database Contents License.


Engineered with 💖 by @EthanThatOneKid