osm-dude
v1.0.5
Published
Tiny OSM (Open Street Maps) API Wrapper
Downloads
19
Maintainers
Readme
🌐 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
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 callingsetFeatureData
).- 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 keyslat
andlon
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 keysx
andy
representing a relative position within the mapped bounds of theOsmDude
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 ofOsmElement
instances; 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
player
is a supposed object of keysx
andy
representing a relative position within the mapped bounds of theOsmDude
instance. - 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
getCollisions
and 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
OsmElement
instances.
setBounds(bounds)
- where
bounds
is an object of keysminLat
,minLon
,maxLat
, andmaxLon
. - returns nothing.
setViewport(w, h)
- where
w
andh
are the respectivemapWidth
andmapHeight
values from the initialization example. - returns nothing.
setElementRenderer(elementRenderer)
- where
elementRenderer
is a function that takes argumentsel
andoffset
.el
is anOsmElement
instance andoffset
is an object of keysx
andy
which represents the mapped distance from the center traversed without reloading. Iftraverse
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