-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapa.php
More file actions
187 lines (165 loc) · 5.19 KB
/
mapa.php
File metadata and controls
187 lines (165 loc) · 5.19 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<!DOCTYPE html>
<html>
<head>
<title>Mapa interactivo</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/leaflet.js"></script>
<style>
#map {
height: 600px;
width: 100%;
}
/* Estilo para las etiquetas de texto de los países */
.label {
font-size: 12px;
font-weight: bold;
background-color: #fff;
color: #555;
padding: 5px;
border-radius: 5px;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
/* Estilo para los popups de los países */
.popup h3 {
margin-top: 0;
}
.popup p {
margin-bottom: 5px;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
// Crear un objeto de mapa y establecer su vista inicial
var map = L.map('map').setView([-34.61, -58.38], 5);
// Establecer la extensión de los límites del mapa
var southWest = L.latLng(-55.0, -75.0);
var northEast = L.latLng(-20.0, -53.0);
var bounds = L.latLngBounds(southWest, northEast);
map.setMaxBounds(bounds);
map.on('drag', function() {
map.panInsideBounds(bounds, {
animate: false
});
});
map.setMinZoom(2);
// Agregar una capa de mosaico de OpenStreetMap
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
maxZoom: 18,
}).addTo(map);
// Agregar una capa de GeoJSON para mostrar los límites de los países
var geojsonLayer = L.geoJSON(null, {
style: function(feature) {
return {
color: '#555',
weight: 1,
fillOpacity: 0.5,
fillColor: getColor(feature.properties.nam) // Obtener el color basado en el nombre de la provincia
};
},
onEachFeature: function(feature, layer) {
layer.on('mouseover', function(e) {
layer.setStyle({
fillOpacity: 0.2 // Cambia la opacidad de relleno al 50%
});
});
layer.on('mouseout', function(e) {
layer.setStyle({
fillOpacity: 0.5 // Vuelve a la opacidad de relleno original
});
});
// Agregar etiquetas de texto para cada país y mostrarlas solo cuando se pasa el mouse sobre el país
var label = L
.tooltip({
permanent: false,
direction: 'center',
className: 'label',
opacity: 0.8,
offset: [0, 0],
sticky: true,
}).setContent(feature.properties.nam);
layer.bindTooltip(label);
// Agregar información adicional para cada país y mostrarla en una ventana emergente cuando se hace clic en el país
var popupContent = '<a href="https://sites.google.com/view/nticx-' + feature.properties.nam + '">' + feature.properties.nam + '</a>';
layer.on({
click: function(e) {
L.popup()
.setLatLng(e.latlng)
.setContent(popupContent)
.openOn(map);
},
mouseover: function(e) {
this.openTooltip();
},
mouseout: function(e) {
this.closeTooltip();
},
});
},
}).addTo(map);
// Cargar datos geográficos de las provincias desde un archivo GeoJSON
fetch('prov.json')
.then(response => response.json())
.then(data => geojsonLayer.addData(data));
// Función para obtener el color basado en el nombre de la provincia
function getColor(province) {
// Aquí puedes definir los colores para cada provincia
switch (province) {
case 'Tierra del Fuego, Antártida e Islas del Atlántico Sur':
return 'blue';
case 'Santa Cruz':
return 'blue';
case 'Chubut':
return 'blue';
case 'Río Negro':
return 'blue';
case 'Neuquén':
return 'blue';
case 'Mendoza':
return 'green';
case 'San Juan':
return 'green';
case 'San Luis':
return 'green';
case 'La Rioja':
return 'green';
case 'Misiones':
return '#7FFF00';
case 'Buenos Aires':
return 'orange';
case 'La Pampa':
return 'orange';
case 'Entre Ríoss':
return 'orange';
case 'Santa Fe':
return 'orange';
case 'Corrientes':
return 'orange';
case 'Chaco':
return 'orange';
case 'Formosa':
return 'orange';
case 'Córdoba':
return 'orange';
case 'Santiago del Estero':
return 'orange';
case 'Tucumán':
return 'orange';
case 'Catamarca':
return '#DC143C';
case 'Jujuy':
return '#6495ED';
case 'Salta':
return '#6495ED';
// Añade más casos para cada provincia con el color correspondiente
default:
return '#000000'; // Negro por defecto
}
}
</script>
</body>
</html>