FOAM API Example - Leaflet
-
-
Save kejace/0d93e33c0da9696b0fc5db3b0fbae06d to your computer and use it in GitHub Desktop.
FOAM API Example - Leaflet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset='utf-8' /> | |
<title>FOAM API Example - Leaflet</title> | |
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.css" /> | |
<script src="http://cdn.leafletjs.com/leaflet/v0.7.7/leaflet.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<script src="https://cdn.jsdelivr.net/npm/latlon-geohash@1.1.0/latlon-geohash.min.js"></script> | |
<style> | |
body { margin:0; padding:0; } | |
#map { position:absolute; top:0; bottom:0; width:100%; } | |
</style> | |
</head> | |
<body> | |
<div id='map'></div> | |
<script> | |
//see this in action: http://bl.ocks.org/FergusDevelopmentLLC/3b3fd8491b3df85e40d6e0d4b9911493 | |
//get bounding box: http://bboxfinder.com | |
let mapBounds = [ | |
[39.580819,-105.154953], //Southwest corner | |
[39.941857,-104.646835] //Northeast corner | |
]; | |
//create a Leaflet map, assign it to map div, fit it to maxBounds | |
let map = L.map('map').fitBounds(mapBounds); | |
//add basemap | |
//check out more basemaps here: http://leaflet-extras.github.io/leaflet-providers/preview/ | |
let tiles = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/terrain/{z}/{x}/{y}.{ext}', { | |
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>', | |
subdomains: 'abcd', | |
minZoom: 0, | |
maxZoom: 18, | |
ext: 'png' | |
}).addTo(map); | |
let url = 'https://map-api-direct.foam.space:443/poi/map?swLon=' + mapBounds[0][1] + '&swLat=' + mapBounds[0][0] + '&nwLon=' + mapBounds[1][1] + '&nwLat=' + mapBounds[1][0]; | |
axios.get(url) | |
.then((response) => { | |
let beacons = response.data; | |
//for each beacon in the response from FOAM api | |
for (beacon in beacons) { | |
//decode the beaconGeoHash value to lat, lon | |
//https://github.com/chrisveness/latlon-geohash | |
let decodedLatLng = Geohash.decode(beacons[beacon].geohash); | |
//use decoded lat/lon to create Markers for map | |
let latlng = L.latLng({ lat: decodedLatLng.lat, lng: decodedLatLng.lon }); | |
let marker = L.marker(latlng).addTo(map); | |
} | |
}, | |
(error) => { | |
let status = error.response.status | |
} | |
); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment