Last active
March 12, 2021 13:27
-
-
Save oalami/d61718d47266bd521228 to your computer and use it in GitHub Desktop.
Global Earthquakes in Realtime using Firebase Open Data Sets
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
const CONTINENTS = ["europe", "asia", "africa", "north_america", "south_america", "antartica", "oceanic"]; | |
var map; | |
var previousInfowindow; | |
var ref = new Firebase("https://publicdata-earthquakes.firebaseio.com/by_continent/"); | |
function mapQuake(snapshot) { | |
var quake = snapshot.val(); | |
var myLatlng = new google.maps.LatLng(quake.location.lat,quake.location.lng); | |
map.setCenter(myLatlng); | |
var marker = new google.maps.Marker({ | |
position: myLatlng, | |
map: map, | |
animation: google.maps.Animation.DROP, | |
}); | |
google.maps.event.addListener(marker, 'click', function() { | |
infowindow = new google.maps.InfoWindow({ | |
content: '<b>Magnitude: </b>' + quake.mag + '<br /><b>Where:</b> '+ quake.place + '<br /><b>When: </b>' + (new Date(quake.time)) | |
}); | |
if (previousInfowindow) { | |
previousInfowindow.close(); | |
} | |
infowindow.open(map,marker); | |
previousInfowindow = infowindow; | |
}); | |
} | |
function start() { | |
map = new google.maps.Map(document.getElementById('map_canvas'), {zoom: 3}); | |
for (var con=0; con<CONTINENTS.length; con++) { | |
var continent = CONTINENTS[con]; | |
for (var mag=0; mag<10; mag++) { | |
var magRef = ref.child(continent).child(mag.toString()); | |
magRef.orderByKey().limitToLast(3).on("child_added", mapQuake); | |
} | |
} | |
} | |
$(start); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment