-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravel.js
86 lines (74 loc) · 3.34 KB
/
travel.js
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
var travel_map
function travel() {
ScrollTop()
$(".search-bar").fadeOut();
if ($(".travel").hasClass('loaded')) {
$(".nav-link").removeClass("active");
$(".travel_link").addClass("active");
$(".tab").fadeOut()
$(".travel").fadeIn();
close_button()
setTimeout(function(){
travel_map.invalidateSize();
},300)
}
else {
$(".spinner-cases").fadeIn()
$(".travel").addClass("loaded")
$(".nav-link").removeClass("active");
$(".travel_link").addClass("active");
$(".tab").fadeOut()
$(".travel").fadeIn();
travel_map = L.map('travel_map').setView([20.685, 15.118], 2);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/dark-v10',
tileSize: 512,
zoomOffset: -1,
accessToken: 'pk.eyJ1IjoiZG9uYWxkem91IiwiYSI6ImNrOHN1M2JrZTBjZGEzbnI0amhzNG13dTYifQ.uTvTibSyi2lvdrbT4ipj4w'
}).addTo(travel_map);
setTimeout(function () {
load_travel()
}, 500)
}
}
function load_travel() {
var travel_list = Object.keys(travel_history).sort()
for (var a in travel_list){
if (travel_list[a] != '' && travel_list[a] != 'Not Reported'){
$(".travel tbody").append('<tr><th scope="row">'+travel_list[a]+'</th><td>'+travel_history[travel_list[a]]+'</td></tr>')
}
}
var not = travel_history[''] + travel_history['Not Reported']
$(".travel tbody").append('<tr><th scope="row">Not Reported</th><td>'+not+'</td></tr>')
for (var n in Object.keys(travel_history)) {
var country_name = Object.keys(travel_history)[n]
if (country_name == 'U.S. Virgin Islands') {
country_name = 'Virgin Islands'
}
$.ajax({
type: 'GET',
url: "https://geocoder.ls.hereapi.com/search/6.2/geocode.json?languages=en-US&maxresults=1&searchtext=" + country_name + "&apiKey=1VOe2SSnYK_atMeC1iN-KrCYh_T9T8oqALHXPv_O0FE",
dataType: "text",
async: false,
success: function (data) {
var temp_travel = JSON.parse(data)
temp_travel.name = Object.keys(travel_history)[n]
if (temp_travel.Response.View[0].Result[0].MatchLevel == 'city' || temp_travel.Response.View[0].Result[0].MatchLevel == 'country') {
var circle = L.circle([temp_travel.Response.View[0].Result[0].Location.DisplayPosition.Latitude, temp_travel.Response.View[0].Result[0].Location.DisplayPosition.Longitude,], {
color: '#6efffd',
fillColor: '#6efffd',
fillOpacity: 0.5,
radius: travel_history[temp_travel.name] * 20000
}).addTo(travel_map);
circle.bindPopup("<h5>" + temp_travel.name + "</h5><p>" + travel_history[temp_travel.name] + " cases</p>")
}
}
})
}
$(".spinner-cases").fadeOut();
$(".t_map").css('opacity',1);
close_button();
travel_map.invalidateSize();
}