Skip to content

Instantly share code, notes, and snippets.

@tsamaya
Last active August 29, 2015 14:15
Show Gist options
  • Save tsamaya/26701d7956a422c1c879 to your computer and use it in GitHub Desktop.
Save tsamaya/26701d7956a422c1c879 to your computer and use it in GitHub Desktop.
MapTime-Alpes - Leaftlet Getting started with LeafletJS - Challenge Earthquakes
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Getting started with LeafletJS - Challenge Earthquakes" />
<link href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.css">
<link rel="stylesheet" type="text/css" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet.markercluster/0.4.0/MarkerCluster.Default.css">
<title>MapTime-Alpes - Leaftlet</title>
<style id="jsbin-css">
body {
padding: 0;
margin: 0;
}
html, body, #leaflet-map {
height: 90%;
}
.leaflet-popup-content {
max-height: 400px;
overflow-y: scroll;
}
</style>
</head>
<body>
<div id="leaflet-map"></div>
<script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/plugins/leaflet-heat/v0.1.3/leaflet-heat.js'></script>
<script>
// MAP
var map = L.map('leaflet-map', {
center: [25.0, -20.0],
zoom: 3,
});
// copyright
var mbAttr = 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
mbUrl = 'https://{s}.tiles.mapbox.com/v3/{id}/{z}/{x}/{y}.png';
// mapbox gray
var grayscale = L.tileLayer(mbUrl, {
id: 'examples.map-20v6611k',
attribution: mbAttr
});
grayscale.addTo(map);
// add empty heatmap
heat = L.heatLayer([], { maxZoom: 12 }).addTo(map);
$.ajax({
url: "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson",
cache: true,
success: function (data) {
// make geojson layer from data
geojsonlayer = L.geoJson(data);
// fit data to map
map.fitBounds(geojsonlayer.getBounds());
// iterate geojson layer, adding to heatmap
geojsonlayer.eachLayer(function(l) {
heat.addLatLng(l.getLatLng());
});
}
});
</script></body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment