-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
296 lines (251 loc) · 11 KB
/
index.php
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
//We need to pull in the Sag PHP library. SAG is an open API used to connect to the Cloudant database.
//We only need to do this once!
require('vendor/autoload.php');
$services_json = json_decode(getenv('VCAP_SERVICES'),true);
$VcapSvs = $services_json["cloudantNoSQLDB"][0]["credentials"];
//Debug: If you want to see all the variables returned you can use this line of code.
//var_dump($services_json);
// Extract the VCAP_SERVICES variables for Cloudant connection.
$myUsername = $VcapSvs["username"];
$myPassword = $VcapSvs["password"];
try {
// Let's login to the database.
$sag = new Sag($myUsername . ".cloudant.com");
$sag->login($myUsername, $myPassword);
$sag->setDatabase("tweets");
$resp = $sag->get('_design/views/_view/tweet-view')->body->rows;
$sag->setDatabase("weather");
$weather = $sag->get('_design/views/_view/weather-view')->body->rows;
}
catch(Exception $e) {
//We sent something to Sag that it didn't expect.
echo '<p>There Was an Error Getting Data from the database :/ </p>';
echo $e->getMessage();
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Leaky Rivers</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--[if lte IE 8]><script src="assets/js/ie/html5shiv.js"></script><![endif]-->
<link rel="stylesheet" href="assets/css/main.css" />
<link rel="stylesheet" href="assets/css/ol.css" type="text/css">
<script src="assets/js/ol.js"></script>
<!--[if lte IE 9]><link rel="stylesheet" href="assets/css/ie9.css" /><![endif]-->
<!--[if lte IE 8]><link rel="stylesheet" href="assets/css/ie8.css" /><![endif]-->
</head>
<body onpageshow="getLocation();">
<!-- Wrapper -->
<div id="wrapper">
<!-- Header -->
<header id="header">
<div class="inner">
<!-- Logo -->
<a href="index.php" class="logo">
<span class="symbol"><img src="images/logo.png" alt="Leaky Rivers" /></span>
</a>
<!-- <div class="field">
<input type="text" name="location" id="location" placeholder="Location " />
</div> -->
<!-- Nav -->
<nav>
<ul>
<li><a href="#menu">Menu</a></li>
</ul>
</nav>
</div>
</header>
<!-- Menu -->
<nav id="menu">
<h2>Menu</h2>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php">Change Location</a></li>
</ul>
</nav>
<!-- Main -->
<div id="main">
<div class="inner">
<header>
<div id="popup" class="popup"></div>
<div id="map" class="map"></div>
</header>
<section class="tiles">
<?php foreach($weather as &$value)
echo '<article class="style1">
<span class="image">
<img src="images/pic01.jpg" alt="" />
</span>
<a href="#">
<h2> ' . $value->value->phrase_12char . '</h2>
<div class="content">
<p>How is it looking?</p>
</div>
</a>
</article>';
echo ' <article class="style2">
<span class="image">
<img src="images/pic01.jpg" alt="" />
</span>
<a href="#">
<h2> ' . $value->value->sky_cover . ' </h2>
<div class="content">
<p>Sky cover</p>
</div>
</a>
</article>';
echo '<article class="style3">
<span class="image">
<img src="images/pic01.jpg" alt="" />
</span>
<a href="#">
<h2> ' . $value->value->metric->temp . '℃ </h2>
<div class="content">
<p>Temperature</p>
</div>
</a>
</article>';
?>
</section>
</div>
</div>
<!-- Footer -->
<footer id="footer">
<div class="inner">
<section>
<h2>Get in touch</h2>
<form method="post" action="messageUs.php">
<div class="field half first">
<input type="text" name="name" id="name" placeholder="Name" />
</div>
<div class="field half">
<input type="email" name="email" id="email" placeholder="Email" />
</div>
<div class="field">
<textarea name="message" id="message" placeholder="Message"></textarea>
</div>
<ul class="actions">
<li><input type="submit" value="Send" class="special" /></li>
</ul>
</form>
</section>
<section>
<h2>Follow</h2>
<ul class="icons">
<li><a href="http://twitter.com/LeakyRivers" class="icon style2 fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="http://facebook.com/LeakyRivers" class="icon style2 fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="https://github.com/LeakyRivers" class="icon style2 fa-github"><span class="label">GitHub</span></a></li>
</ul>
</section>
<ul class="copyright">
<li>Leaky Rivers 2016 - NASA SpaceAppChallenge.</li><li>Design: <a href="http://html5up.net">HTML5 UP</a></li>
</ul>
</div>
</footer>
</div>
<script>
var projection = ol.proj.get('EPSG:3857');
var raster = new ol.layer.Tile({
source: new ol.source.BingMaps({
imagerySet: 'Aerial',
key: 'AqzR3QSX8denhtQSfY2k-RPalRm7QBcC9kolBk103fshoCpc6HIoIcdv3n9YcOt4'
})
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'data/kml/waterNL.kml',
format: new ol.format.KML()
})
});
var latlon;
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
}
}
function displayTweets() {
var tweets = <?php echo json_encode($resp); ?>;
var features = [];
for (i = 0; i < tweets.length; i++) {
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform(tweets[i].value.coordinates,'EPSG:4326', 'EPSG:3857')),
text: tweets[i].value.text
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'images/icon.png'
}))
});
iconFeature.setStyle(iconStyle);
features.push(iconFeature);
}
var source = vector.getSource();
source.addFeatures(features);
}
function showPosition(position) {
latlon = [position.coords.longitude, position.coords.latitude];
map.getView().setCenter(ol.proj.transform(latlon, 'EPSG:4326', 'EPSG:3857'));
map.getView().setZoom(10);
displayTweets();
}
var map = new ol.Map({
layers: [raster, vector],
target: document.getElementById('map'),
view: new ol.View({
center: [0, 0],
projection: projection,
zoom: 3
})
});
var element = document.getElementById('popup');
var popup = new ol.Overlay({
element: element,
positioning: 'bottom-center',
stopEvent: false
});
map.addOverlay(popup);
// display popup on click
map.on('click', function(evt) {
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature) {
return feature;
});
if (feature) {
popup.setPosition(evt.coordinate);
$(element).popover({
'placement': 'top',
'html': true,
'content': feature.get('text')
});
$(element).popover('show');
} else {
$(element).popover('destroy');
}
});
// change mouse cursor when over marker
map.on('pointermove', function(e) {
if (e.dragging) {
$(element).popover('destroy');
return;
}
var pixel = map.getEventPixel(e.originalEvent);
var hit = map.hasFeatureAtPixel(pixel);
map.getTarget().style.cursor = hit ? 'pointer' : '';
});
</script>
<!-- Scripts -->
<script src="assets/js/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<!--[if lte IE 8]><script src="assets/js/ie/respond.min.js"></script><![endif]-->
<script src="assets/js/main.js"></script>
</body>
</html>