-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather_map.html
More file actions
121 lines (101 loc) · 5.11 KB
/
weather_map.html
File metadata and controls
121 lines (101 loc) · 5.11 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Weather Map</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.css' rel='stylesheet' />
<link href="https://fonts.googleapis.com/css2?family=Montserrat&family=Roboto+Condensed&display=swap" rel="stylesheet">
<style>
#map {
width: 100%;
height: 550px;
}
#card-stack {
height: 350px;
font-size: 1em;
}
h3 {
font-family: 'Montserrat', sans-serif;
}
</style>
</head>
<body>
<div class="bg-primary text-white p-1 mb-3 d-flex justify-content-between"><h3 class="display-4">Open Weathermapbox</h3><h5 class="my-auto mr-3">Current city: <span id="current-city">Dallas, TX</span></h5></div>
<div id="container" class="container-fluid">
<div class="form-group ml-5">
<input id="search-text" type="text" class="mr-3" value="Dallas, TX"> <button id="search-button" class="btn btn-primary">Find Weather</button>
</div>
<div id="card-stack" class="row d-flex justify-content-around my-3"></div>
<div id="map"></div>
</div>
<script src="js/keys.js"></script>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.53.0/mapbox-gl.js'></script>
<script src="js/mapbox-geocoder-utils.js"></script>
<script>
</script>
<script>
(function() {
var lat = 32.7767;
var lon = -96.7970;
function weatherUpdate(lat, lon) {
$('#card-stack').empty();
$.get("https://api.openweathermap.org/data/2.5/onecall?lat=" + lat + "&lon=" + lon + "&exclude=current,minutely,hourly&appid=" + OWM_key, {
units: 'imperial'
}).done(function (data) {
for (var i = 0; i <= 4; i++) {
var timestamp = Number(new Date(data.daily[i].dt * 1000))
var date = new Date(timestamp).toDateString();
$('#card-stack').append("<div class=\"col-2\">\n" +
" <div class=\"card\">\n" +
" <div class=\"card-header text-center\">" + date + "</div>\n" +
" <div class=\"card-body\">\n" +
" <div class=\"text-center my-2\"><strong>" + data.daily[i].temp.min + " / " + data.daily[i].temp.max + "°F</strong></div>\n" +
" <div class=\"text-center my-2\"><img src=\"http://openweathermap.org/img/w/" + data.daily[i].weather[0].icon + ".png\"></div>\n" +
" <p>Description: <strong>" + data.daily[i].weather[0].description + "</strong></p>\n" +
" <p>Humidity: <strong>" + data.daily[i].humidity + "</strong></p>\n" +
" <p>Wind: <strong>" + data.daily[i].wind_speed + "</strong></p>\n" +
" <p>Pressure: <strong>" + data.daily[i].pressure + "</strong></p>\n" +
" </div>\n" +
" </div>\n" +
" </div>"
);
};
});
};
//jQuery and actual code stuff
$(document).ready(function() {
weatherUpdate(lat, lon);
//mapbox map
mapboxgl.accessToken = mapboxToken;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
zoom: 10,
center: [lon, lat]
});
var marker = new mapboxgl.Marker();
map.on('click', function(e) {
marker.setLngLat(e.lngLat).addTo(map);
var lngLat = marker.getLngLat();
weatherUpdate(lngLat.lat, lngLat.lng)
});
$('#search-button').click(function() {
var location = $('#search-text').val();
$('#current-city').text(location);
geocode(location, mapboxToken).then(function(result) {
map.setCenter(result);
weatherUpdate(result[1], result[0]);
marker.setLngLat(result).addTo(map);
map.setZoom(10)
});
});
});
})();
</script>
</body>
</html>