-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
142 lines (122 loc) · 3.79 KB
/
script.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
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
console.log("Practica 7");
/** Variables Globales */
let map;
let btnEliminar;
let marcadoresArray = [];
let markersArray = [];
let lat = 18.8690435;
let lng = -97.0984946;
let nombre = "";
const colors = ["blue", "red", "black", "green", "orange"];
let colorIndex = 0;
/** Clase global para los valores de Latitud y Longitud. */
let myLatLng = { lat: lat, lng: lng };
/** Opciones iniciales del mapa. */
let mapOptions = {
center: myLatLng,
zoom: 8,
};
function iniciarMap() {
btnEliminar = document.getElementById("btnEliminar");
btnEliminar.disabled = true;
map = new google.maps.Map(document.getElementById("map"), mapOptions);
let marker = new google.maps.Marker({
position: myLatLng,
animation: google.maps.Animation.DROP,
icon:
"https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png",
title: "Universidad del Valle de Orizaba",
});
marker.setMap(map);
let infowindow = new google.maps.InfoWindow();
infowindow.setContent(
"<strong>" +
marker.title +
"</strong><br /><strong> Coordenadas:</strong>" +
marker.position
);
marker.addListener("click", () => {
infowindow.open(map, marker);
});
}
function agregarMarcadores() {
document.getElementById("divTablaMarcadores").innerHTML = "";
let txtLat = document.getElementById("txtLat").value;
let txtLng = document.getElementById("txtLng").value;
let txtNombre = document.getElementById("txtNombre").value;
lat = txtLat;
lng = txtLng;
nombre = txtNombre;
myLatLng = { lat: parseFloat(lat), lng: parseFloat(lng) };
const svgMarker = {
path:
"M10.453 14.016l6.563-6.609-1.406-1.406-5.156 5.203-2.063-2.109-1.406 1.406zM12 2.016q2.906 0 4.945 2.039t2.039 4.945q0 1.453-0.727 3.328t-1.758 3.516-2.039 3.070-1.711 2.273l-0.75 0.797q-0.281-0.328-0.75-0.867t-1.688-2.156-2.133-3.141-1.664-3.445-0.75-3.375q0-2.906 2.039-4.945t4.945-2.039z",
fillColor: colors[colorIndex++ % colors.length],
fillOpacity: 1.0,
strokeWeight: 0,
rotation: 0,
scale: 2,
anchor: new google.maps.Point(15, 30),
};
let marker = new google.maps.Marker({
position: myLatLng,
animation: google.maps.Animation.DROP,
icon: svgMarker,
title: nombre,
});
marker.setMap(map);
let infowindow = new google.maps.InfoWindow();
infowindow.setContent(
"<strong>" +
marker.title +
"</strong><br /><strong> Coordenadas: </strong>" +
marker.position
);
marker.addListener("click", () => {
infowindow.open(map, marker);
});
/** Agregar Marcador */
markersArray.push(marker);
agregarMarcador();
mostrarTablaMarcadores();
limpiarInputs();
}
/** Elimina Marcadores del mapa. */
function eliminarMarcadores() {
markersArray.forEach((e) => {
e.setMap(null);
});
markersArray = [];
marcadoresArray = [];
document.getElementById("divTablaMarcadores").innerHTML = "";
btnEliminar.disabled = true;
}
/** Arma el arreglo de marcadores. */
function agregarMarcador() {
marcadoresArray.push({
_nombre: nombre,
_lat: lat,
_lng: lng,
});
btnEliminar.disabled = false;
}
function mostrarTablaMarcadores() {
let resultado =
"<table><thead> <tr> <th>Nombre</th> <th>Latitud</th> <th>Longitud</th> </tr> </thead>";
resultado += "<tbody>";
marcadoresArray.forEach((e) => {
resultado += "<tr>";
resultado += "<td>" + e._nombre + "</td>";
resultado += "<td>" + e._lat + "</td>";
resultado += "<td>" + e._lng + "</td>";
resultado += "</tr>";
});
resultado += "</tbody> </table>";
document.getElementById("divTablaMarcadores").innerHTML = resultado;
}
/** Limpia los inputs del formularios. */
function limpiarInputs() {
document.getElementById("txtNombre").value = "";
document.getElementById("txtLng").value = "";
document.getElementById("txtLat").value = "";
}