Update index.html
Browse files- index.html +90 -34
index.html
CHANGED
|
@@ -1,17 +1,22 @@
|
|
| 1 |
<!DOCTYPE html>
|
|
|
|
| 2 |
<html lang="es">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
-
<title>Mapa Interactivo</title>
|
| 7 |
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
|
| 8 |
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
|
|
|
| 9 |
<style>
|
| 10 |
#map { height: 500px; width: 100%; }
|
| 11 |
#controls { margin: 10px; }
|
|
|
|
|
|
|
| 12 |
</style>
|
| 13 |
</head>
|
| 14 |
<body>
|
|
|
|
| 15 |
<div id="controls">
|
| 16 |
<label for="category">Selecciona una categoría:</label>
|
| 17 |
<select id="category" onchange="updateMarkers()">
|
|
@@ -27,25 +32,34 @@
|
|
| 27 |
|
| 28 |
<div id="map"></div>
|
| 29 |
|
| 30 |
-
<
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
-
|
| 34 |
-
attribution: '© OpenStreetMap contributors'
|
| 35 |
-
}).addTo(map);
|
| 36 |
|
| 37 |
var locations = [
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
];
|
| 48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
var categoryColors = {
|
| 50 |
"assessment": "blue",
|
| 51 |
"deployment": "green",
|
|
@@ -56,6 +70,7 @@
|
|
| 56 |
};
|
| 57 |
|
| 58 |
var markers = [];
|
|
|
|
| 59 |
|
| 60 |
function updateMarkers() {
|
| 61 |
var selectedCategory = document.getElementById("category").value;
|
|
@@ -64,37 +79,78 @@
|
|
| 64 |
markers.forEach(marker => map.removeLayer(marker));
|
| 65 |
markers = [];
|
| 66 |
|
| 67 |
-
//
|
| 68 |
-
locations.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
});
|
| 81 |
-
|
|
|
|
| 82 |
if (markers.length > 1) {
|
| 83 |
var group = new L.featureGroup(markers);
|
| 84 |
map.fitBounds(group.getBounds());
|
| 85 |
} else if (markers.length === 1) {
|
| 86 |
-
let zoom_nivel_pais = 6;
|
| 87 |
map.setView(markers[0].getLatLng(), zoom_nivel_pais);
|
| 88 |
} else {
|
| 89 |
map.setView([45, 10], 3); // Vista inicial si no hay puntos
|
| 90 |
}
|
| 91 |
-
|
| 92 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
}
|
| 94 |
|
| 95 |
-
// Mostrar todos los marcadores al inicio
|
| 96 |
updateMarkers();
|
| 97 |
</script>
|
| 98 |
-
</body>
|
| 99 |
-
</html>
|
| 100 |
|
|
|
|
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
+
<!DOCTYPE html>
|
| 3 |
<html lang="es">
|
| 4 |
<head>
|
| 5 |
<meta charset="UTF-8">
|
| 6 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 7 |
+
<title>Mapa Interactivo con Gráfico</title>
|
| 8 |
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>
|
| 9 |
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 11 |
<style>
|
| 12 |
#map { height: 500px; width: 100%; }
|
| 13 |
#controls { margin: 10px; }
|
| 14 |
+
#chart-container { width: 80%; margin: 20px auto; }
|
| 15 |
+
canvas { width: 100%; height: 300px; }
|
| 16 |
</style>
|
| 17 |
</head>
|
| 18 |
<body>
|
| 19 |
+
|
| 20 |
<div id="controls">
|
| 21 |
<label for="category">Selecciona una categoría:</label>
|
| 22 |
<select id="category" onchange="updateMarkers()">
|
|
|
|
| 32 |
|
| 33 |
<div id="map"></div>
|
| 34 |
|
| 35 |
+
<div id="chart-container">
|
| 36 |
+
<canvas id="connectionsChart"></canvas>
|
| 37 |
+
</div>
|
| 38 |
|
| 39 |
+
<script>
|
|
|
|
|
|
|
| 40 |
|
| 41 |
var locations = [
|
| 42 |
+
{ name: "Ragusa", coords: [36.9257, 14.7244], category: "operative", connections: 24 }, // Ragusa, Italia
|
| 43 |
+
{ name: "Seville", coords: [37.3886, -5.9823], category: "operative", connections: 9 }, // Sevilla, España
|
| 44 |
+
{ name: "Groningen", coords: [53.2194, 6.5665], category: "operative", connections: 13 }, // Groningen, Países Bajos
|
| 45 |
+
{ name: "Cape Town", coords: [-33.9249, 18.4241], category: "operative", connections: 1 }, // Ciudad del Cabo, Sudáfrica
|
| 46 |
+
{ name: "Bern", coords: [46.9481, 7.4474], category: "operative", connections: 0 }, // Berna, Suiza
|
| 47 |
+
{ name: "Kiel", coords: [54.3233, 10.1228], category: "removed", connections: 0 }, // Kiel, Alemania
|
| 48 |
+
{ name: "Le Mans", coords: [17.0151, 54.0924], category: "assessment", connections: 0 }, // Salalah, Omán
|
| 49 |
+
{ name: "Le Mans", coords: [48.0077, 0.1996], category: "assessment", connections: 0 }, // Le Mans, Francia
|
| 50 |
+
{ name: "Gdansk", coords: [54.3520, 18.6466], category: "assessment", connections: 0 }, // Gdansk, Polonia
|
| 51 |
+
{ name: "Prague", coords: [50.0755, 14.4378], category: "assessment", connections: 0 }, // Praga, República Checa
|
| 52 |
+
{ name: "Kuwait", coords: [29.3759, 47.9774], category: "assessment", connections: 0 } // Kuwait, Kuwait
|
| 53 |
];
|
| 54 |
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
var map = L.map('map').setView([50.0755, 14.4378], 3); // Mapa centrado en Europa
|
| 58 |
+
|
| 59 |
+
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
| 60 |
+
attribution: 'Map data © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
| 61 |
+
}).addTo(map);
|
| 62 |
+
|
| 63 |
var categoryColors = {
|
| 64 |
"assessment": "blue",
|
| 65 |
"deployment": "green",
|
|
|
|
| 70 |
};
|
| 71 |
|
| 72 |
var markers = [];
|
| 73 |
+
var chart = null; // Variable para almacenar el gráfico
|
| 74 |
|
| 75 |
function updateMarkers() {
|
| 76 |
var selectedCategory = document.getElementById("category").value;
|
|
|
|
| 79 |
markers.forEach(marker => map.removeLayer(marker));
|
| 80 |
markers = [];
|
| 81 |
|
| 82 |
+
// Filtrar y agregar los marcadores
|
| 83 |
+
var filteredLocations = locations.filter(location => selectedCategory === "all" || location.category === selectedCategory);
|
| 84 |
+
|
| 85 |
+
filteredLocations.forEach(location => {
|
| 86 |
+
var marker = L.circleMarker(location.coords, {
|
| 87 |
+
color: categoryColors[location.category],
|
| 88 |
+
fillColor: categoryColors[location.category],
|
| 89 |
+
fillOpacity: 0.8,
|
| 90 |
+
radius: 8
|
| 91 |
+
}).bindPopup(`<b>${location.name}</b><br>Categoría: ${location.category}`);
|
| 92 |
+
|
| 93 |
+
marker.addTo(map);
|
| 94 |
+
markers.push(marker);
|
| 95 |
});
|
| 96 |
+
|
| 97 |
+
// Ajustar el zoom
|
| 98 |
if (markers.length > 1) {
|
| 99 |
var group = new L.featureGroup(markers);
|
| 100 |
map.fitBounds(group.getBounds());
|
| 101 |
} else if (markers.length === 1) {
|
| 102 |
+
let zoom_nivel_pais = 6;
|
| 103 |
map.setView(markers[0].getLatLng(), zoom_nivel_pais);
|
| 104 |
} else {
|
| 105 |
map.setView([45, 10], 3); // Vista inicial si no hay puntos
|
| 106 |
}
|
|
|
|
| 107 |
|
| 108 |
+
// Actualizar el gráfico
|
| 109 |
+
updateChart(filteredLocations);
|
| 110 |
+
}
|
| 111 |
+
|
| 112 |
+
function updateChart(filteredLocations) {
|
| 113 |
+
// Obtener los datos para el gráfico
|
| 114 |
+
var cityNames = filteredLocations.map(location => location.name);
|
| 115 |
+
var connectionsData = filteredLocations.map(location => location.connections);
|
| 116 |
+
var categoryColorsData = filteredLocations.map(location => categoryColors[location.category]);
|
| 117 |
+
|
| 118 |
+
// Si el gráfico ya existe, destruirlo y crear uno nuevo
|
| 119 |
+
if (chart) {
|
| 120 |
+
chart.destroy();
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
// Crear el gráfico
|
| 124 |
+
var ctx = document.getElementById('connectionsChart').getContext('2d');
|
| 125 |
+
chart = new Chart(ctx, {
|
| 126 |
+
type: 'bar',
|
| 127 |
+
data: {
|
| 128 |
+
labels: cityNames,
|
| 129 |
+
datasets: [{
|
| 130 |
+
label: 'Remote Connections',
|
| 131 |
+
data: connectionsData,
|
| 132 |
+
backgroundColor: categoryColorsData, // Asignar color según categoría
|
| 133 |
+
borderColor: categoryColorsData, // Asignar color según categoría
|
| 134 |
+
borderWidth: 1
|
| 135 |
+
}]
|
| 136 |
+
},
|
| 137 |
+
options: {
|
| 138 |
+
responsive: true,
|
| 139 |
+
scales: {
|
| 140 |
+
y: {
|
| 141 |
+
beginAtZero: true,
|
| 142 |
+
ticks: {
|
| 143 |
+
stepSize: 1
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
}
|
| 147 |
+
}
|
| 148 |
+
});
|
| 149 |
}
|
| 150 |
|
| 151 |
+
// Mostrar todos los marcadores y gráfico al inicio
|
| 152 |
updateMarkers();
|
| 153 |
</script>
|
|
|
|
|
|
|
| 154 |
|
| 155 |
+
</body>
|
| 156 |
+
</html>
|