Created
August 7, 2016 03:39
-
-
Save kamath/7f59557ab118285aa23e577e4476df75 to your computer and use it in GitHub Desktop.
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
tweetstream = Session.get('tweets') | |
var data = []; | |
var map = new Datamap({ | |
element: document.getElementById('mapContainer'), | |
responsive: true, | |
fills: { | |
RED: '#E84343', | |
defaultFill: '#CFCFCF' | |
}, | |
done: function(datamap) { | |
datamap.svg.call(d3.behavior.zoom().on('zoom', redraw)); | |
function redraw() { | |
datamap.svg.selectAll('g').attr('transform', 'translate(' + d3.event.translate + ')scale(' + d3.event.scale + ')'); | |
} | |
} | |
}); | |
window.addEventListener('resize', function() { | |
map.resize(); | |
}); | |
// Get JSON of tweets | |
for (var a = 0; a < tweetstream.length; a++) { | |
// Necessary bubble data | |
console.log(tweetstream[a]) | |
tweetstream[a].radius = tweetstream[a].risk_level / 10; | |
tweetstream[a].latitude = tweetstream[a].location.coordinates[1]; | |
tweetstream[a].longitude = tweetstream[a].location.coordinates[0]; | |
var rgbGreenBlue = -2 * tweetstream[a].risk_level + 200; | |
tweetstream[a].fillKey = 'RED'; | |
tweetstream[a].borderWidth = 0; | |
} | |
console.log(tweetstream) | |
map.bubbles(tweetstream, { | |
popupTemplate: function(geo, data) { | |
return '<div class="hoverinfo">Yield:' + data.name + 'Exploded on ' + data.date + 'by the ' + data.risk_level + '</div>' | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment