Last active
October 15, 2015 19:27
-
-
Save lxbarth/dda8f7494bcd255120b9 to your computer and use it in GitHub Desktop.
Load a geojson file from Github.
This file contains hidden or 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>Strava style comparison</title> | |
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
<script src='https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.js'></script> | |
<link href='https://api.mapbox.com/mapbox.js/v2.2.2/mapbox.css' rel='stylesheet' /> | |
<script src='https://api.mapbox.com/mapbox.js/plugins/leaflet-hash/v0.2.1/leaflet-hash.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> | |
L.mapbox.accessToken = 'pk.eyJ1Ijoibmlja2kiLCJhIjoiczVvbFlXQSJ9.1Gegt3V_MTupW6wfjxq2QA'; | |
var map = L.mapbox.map('map', 'nicki.blprdx6r').setView([49.3580, -123.1306], 11); | |
var hash = L.hash(map); | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState == 4 && xhr.status == 200) { | |
map.featureLayer.setGeoJSON(JSON.parse(JSON.parse(xhr.responseText).files['map.geojson'].content)); | |
} | |
}; | |
xhr.open("GET", 'https://api.github.com/gists/0eaaea0f8699b43ea4a1', true); | |
xhr.send(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment