Skip to content

Instantly share code, notes, and snippets.

@lxbarth
Last active October 15, 2015 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lxbarth/dda8f7494bcd255120b9 to your computer and use it in GitHub Desktop.
Save lxbarth/dda8f7494bcd255120b9 to your computer and use it in GitHub Desktop.
Load a geojson file from Github.
<!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