1.0.5 • Published 5 years ago

osm-dude v1.0.5

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

🌐 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