-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathearthquakes.html
142 lines (119 loc) · 4.48 KB
/
earthquakes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA6U2ExB8yLDc7RiGPYK3C3yIzDPpyFJE0&sensor=false"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/lodash/lodash.js"></script>
<script src="bower_components/rsvp/rsvp.js"></script>
<script src="bower_components/geofire/dist/geofire.js"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="Firebase Open Data Sets examples - Earthquakes">
<meta name="viewport" id="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="all">
<title>Firebase Open Data Sets examples - Earthquakes</title>
</head>
<body>
<header>
Firebase Open Data Sets Examples - Earthquakes
</header>
<div class="earthquakes-opendata-example" id="map-canvas"></div><br />
<script>
/*
* earthquakes.js
*
* powering the earthquakes open data example
*/
/* global Firebase, google, _ */
var earthquakes = {
continents: ['europe', 'asia', 'africa', 'north_america', 'south_america', 'antartica', 'oceanic'],
infoWindowContent: _.template('<b>Magnitude:</b> <%= quake.mag %> <br />' +
'<b>Where:</b> <%= quake.place %> <br />' +
'<b>When:</b> <%= (new Date(quake.time)) %>'),
ref: undefined,
map: undefined,
previousInfoWindow: undefined,
$container: undefined,
/*
* init
*
* initialize the module
*/
init: function() {
this.$container = $('.earthquakes-opendata-example');
if (this.$container.length) {
this.ref = new Firebase('https://publicdata-earthquakes.firebaseio.com/by_continent/');
this.fetchContinents();
}
},
/*
* fetchContinents
*
* initialize the Google Maps API and listen for new earthquakes to be added
*/
fetchContinents: function() {
var self = this;
var magRef;
this.map = new google.maps.Map(document.getElementById('map-canvas'), {zoom: 3});
// SET LISTENERS FOR NEW EARTHQUAKE EVENTS ON ALL CONTINENTS
_.forEach(this.continents, function(continent) {
for (var mag = 0; mag < 10; mag++) {
magRef = self.ref.child(continent).child(mag.toString());
magRef.orderByKey().limitToLast(3).on('child_added', self.renderQuakeMarkers, self);
}
});
},
/*
* renderQuakeMarkers
*
* plot earthquake event on the map and enable clicking to reveal more earthquake info
*/
renderQuakeMarkers: function(snapshot) {
var self = this;
var quake = snapshot.val();
var quakeLatLng = new google.maps.LatLng(quake.location.lat, quake.location.lng);
var marker = new google.maps.Marker({
position: quakeLatLng,
map: this.map,
animation: google.maps.Animation.DROP
});
this.map.setCenter(quakeLatLng);
// LISTEN FOR USERS TO CLICK ON GOOGLE MAPS PLACE ICON
google.maps.event.addListener(marker, 'click', function () {
var templateData = {quake: quake};
var infoWindow = new google.maps.InfoWindow({
content: self.infoWindowContent(templateData)
});
if (self.previousInfoWindow) {
self.previousInfoWindow.close();
}
infoWindow.open(self.map, marker);
self.previousInfoWindow = infoWindow;
});
}
};
$(document).ready(function(){
earthquakes.init();
});
</script>
<style>
header {
text-align: center;
font-family: proxima-nova,"Helvetica Neue Light","Helvetica Neue",Helvetica,Arial,"Lucida Grande",sans-serif;
font-size: 16px;
margin-bottom: 10px;
}
.gm-style label { width: auto; display: inline; }
.google-maps img, .gm-style img {
max-width: none !important;
max-height: none !important;
}
#map-canvas {
width: 600px; height: 400px; margin: 0 auto;
}
</style>
</body>