1.0.5 • Published 6 years ago
osm-dude v1.0.5
🌐 OSM Dude
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
elementInteractionsis a customizable interface for programs that wish to run with more detailed Open Street Map functionality; optional. elementInteractionscan also be set later on by callingsetFeatureData).- asynchronous; returns once instance has been initialized.
- returns nothing.
isReady()
- returns
trueif any OSM data has been loaded. - returns
falseif 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
velis an object of keyslatandlonwhich represent the distance desired to travel to a new coordinate. - asynchronous; returns once incoming data has been accounted for.
- returns nothing.
getCollisions(player)
- where
playeris a supposed object of keysxandyrepresenting a relative position within the mapped bounds of theOsmDudeinstance. - returns an array of
OsmElementinstances which overlap with the player's 2d position.
setFeatureData(elementInteractions)
- where
elementInteractionsis 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
elsis an array ofOsmElementinstances; intended to be used in conjunction with the result ofgetCollisions. - returns the data specified in the pre-defined element interactions from
setFeatureData.
checkUnderneath(player)
- where
playeris a supposed object of keysxandyrepresenting a relative position within the mapped bounds of theOsmDudeinstance. - this is an alias who's input acts as
getCollisions's and who's output acts asgetElementInteractions's. - therefore, shares the same input convention as
getCollisionsand the same output convention asgetElementInteractions. - 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
OsmElementinstances.
setBounds(bounds)
- where
boundsis an object of keysminLat,minLon,maxLat, andmaxLon. - returns nothing.
setViewport(w, h)
- where
wandhare the respectivemapWidthandmapHeightvalues from the initialization example. - returns nothing.
setElementRenderer(elementRenderer)
- where
elementRendereris a function that takes argumentselandoffset.elis anOsmElementinstance andoffsetis an object of keysxandywhich represents the mapped distance from the center traversed without reloading. Iftraversehas never been called,offsetis 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
OsmDudeinstance. - 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