-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmaps.js
112 lines (99 loc) · 2.29 KB
/
maps.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
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
var map;
const marker_icon = './assets/img/marker.png';
const marker_hover_icon = './assets/img/marker_hover.png';
let coords = [];
let marker;
let routes;
let paths = [];
let markers = [];
// Sets the map on all markers in the array.
function setMapOnAll(map) {
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}
//Remove Path
function clearPath(map){
routes.setMap(map);
coords = [];
}
// Removes the markers from the map, but keeps them in the array.
function clearMarkers() {
setMapOnAll(null);
}
// Deletes all markers
function deleteMarkersAndPath() {
clearMarkers();
markers = [];
if(routes){
clearPath(null);
}
}
function addPoint(point) {
coords.push(point);
}
//set alert box for each marker
function setInfo(data) {
marker.addListener('click', function () {
swal({
title: `${data.query}`,
text: `ISP: <span style="color:#00bc64">${data.isp} - ${data.as}</span></br>
Local: <span style="color:#00bc64">${data.city}, ${data.region} - ${data.country}</span></br>
Lat/Lon: <span style="color:#00bc64">${data.lat},${data.lon}</span>
`,
confirmButtonText: 'FECHAR',
confirmButtonColor: '#00bc64',
html: true,
});
});
}
function setMarkers(data) {
marker = new google.maps.Marker({
position: {
lat: data.lat,
lng: data.lon
},
map: map,
icon: marker_icon
});
markers.push(marker);
marker.setMap(map);
setHoverEvents(data);
setInfo(data);
}
function setHoverEvents(data) {
const box_id = `ip-${data.query.split(".").join("")}`;
const box = $(`#${box_id}`)
marker.addListener('mouseover', function() {
box.addClass('box-hover');
this.setIcon(marker_hover_icon);
});
marker.addListener('mouseout', function() {
box.removeClass('box-hover');
this.setIcon(marker_icon);
});
}
function setPath() {
routes = new google.maps.Polyline({
path: coords,
strokeColor: '#00bc64',
strokeOpacity: 1.0,
strokeWeight: 2,
});
routes.setMap(map);
}
function setCenter(center) {
map.setCenter(center);
map.setZoom(6);
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: -22.397,
lng: 45.644
},
disableDefaultUI: true,
zoom: 2,
styles: mapStyle
});
}