Skip to content

Instantly share code, notes, and snippets.

@rowanv
Last active January 6, 2016 09:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanv/4c20214cd6ccca95d202 to your computer and use it in GitHub Desktop.
Save rowanv/4c20214cd6ccca95d202 to your computer and use it in GitHub Desktop.
Map Dashboard Visualization
<html>
<meta charset='utf-8'>
<head>
</head>
<body>
<div id="map_container" style="position: relative; width: 80%; max-height: 500px;"></div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.12/d3.js" charset='utf-8'></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://datamaps.github.io/scripts/datamaps.world.min.js?v=1"></script>
<script>
$(document).ready(function() {
d3.json("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_month.geojson",function(error,data){
data = data.features;
var map = new Datamap({
scope: 'world',
element: document.getElementById('map_container'),
projection: 'equirectangular',
height: 500,
fills: {
defaultFill: '#F1EBF4',
lt50: 'rgba(0,244,244,0.9)',
gt50: '#20438A',
},
geographyConfig: {
highlightFillColor: '#bfdfec',
highlightBorderColor: 'white',
},
bubblesConfig: {
highlightFillColor: '#2265aa',
highlightBorderColor: '#61b3b7',
}
});
var bubble_array = [];
function getBubble(lat, lon, name){
var bubble = {
name: name,
latitude: lat,
longitude: lon,
radius: 10,
fillKey: 'gt50',
}
bubble_array.push(bubble);
return bubble;
}
for (var i = 0; i < data.length; i++) {
getBubble(data[i].geometry.coordinates[1],
data[i].geometry.coordinates[0],
data[i].properties.title);
}
//bubbles, custom popup on hover template
map.bubbles(bubble_array, {
popupTemplate: function(geo, data) {
return "<div class='hoverinfo'>" + data.name + "</div>";
}
});
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment