-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
249 lines (234 loc) · 9.71 KB
/
index.html
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Elecciones Venezuela 2024 por Parroquia</title>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<style>
body {
font-family: "Roboto", Arial, Helvetica, sans-serif;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
background-color: #f0f0f0;
}
header, main, footer {
width: 100%;
/* max-width: 1200px; */
padding: 20px;
box-sizing: border-box;
}
header {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px 0;
}
main {
flex-grow: 1;
overflow-y: auto;
background-color: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
footer {
background-color: #333;
color: #fff;
text-align: center;
padding: 10px 0;
}
#map {
height: 70%;
/* width: 80%; */
margin: auto;
min-height: 300px;
}
#info {
overflow-y: auto;
width: 75%;
height: 25%;
padding: 10px;
border: 1px solid #ddd;
background: #f9f9f9;
margin: 10px auto auto auto;
}
.modal {
display: none;
position: fixed;
z-index: 2;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.75);
}
.modal-content {
margin: auto;
display: block;
width: 80%;
max-width: 500px;
margin-top: 5%;
margin-bottom: 5%;
}
.modal-content img {
width: 100%;
height: auto;
}
.close {
position: fixed;
top: 15px;
right: 35px;
color: #fff;
font-size: 40px;
font-weight: bold;
transition: 0.3s;
}
.close:hover,
.close:focus {
color: #bbb;
text-decoration: none;
cursor: pointer;
}
</style>
</head>
<body>
<header>
<h1>🇻🇪🇻🇪 Resultados Electorales 2024 por Parroquia</h1>
</header>
<main>
<div id="map"></div>
<div id="info">Click en una parroquia para ver los resultados de las mesas</div>
<div id="myModal" class="modal">
<span class="close">×</span>
<div class="modal-content">
<img id="modalImage" src="" alt="Image">
</div>
</div>
</main>
<!-- <footer>
<p>Creado con ❤️ desde 🇪🇸. <a href="https://github.com/mapavenezuela2024/mapavenezuela2024.github.io" target="_blank">Ver en GitHub</a></
</footer> -->
<script>
// Load the GeoJSON file
fetch('./votes_geojson_min.json')
.then(response => response.json())
.then(venezuela_geojson => {
venezuela_geojson.features.forEach(feature => {
if (feature.properties.ADM1_ES) {
feature.properties.shapeName = feature.properties.ADM1_ES + ' - ' + feature.properties.ADM2_ES + ' - ' + feature.properties.ADM3_ES;
feature.properties.color = -1; // Set to -1 to indicate no data
} else {
feature.properties.shapeName = feature.properties.EDO + ' - ' + feature.properties.MUN + ' - ' + feature.properties.PAR;
}
if (!feature.properties.mesas || feature.properties.mesas.length === 0) {
feature.properties.mainInfo = 'No data';
} else {
// Format mesas information into a string, excluding the URL
let maduro = 0;
let gonzalez = 0;
let otros = 0;
for (let i = 0; i < feature.properties.mesas.length; i++) {
maduro += feature.properties.mesas[i]['N. Maduro'];
gonzalez += feature.properties.mesas[i]['E. González'];
otros += feature.properties.mesas[i]['OTROS'];
}
feature.properties.mainInfo = `N. Maduro: ${maduro} (${(maduro / (maduro + gonzalez + otros) * 100).toFixed(2)}%)<br>E. González: ${gonzalez} (${(gonzalez / (maduro + gonzalez + otros) * 100).toFixed(2)}%)<br>Otros: ${otros} (${(otros / (maduro + gonzalez + otros) * 100).toFixed(2)}%)`;
}
});
// Prepare data for Plotly
const locations = venezuela_geojson.features.map(feature => feature.properties.shapeName);
const colors = venezuela_geojson.features.map(feature => feature.properties.color);
const hoverTexts = venezuela_geojson.features.map(feature => feature.properties.mainInfo);
const data = [{
type: 'choroplethmapbox',
geojson: venezuela_geojson,
locations: locations,
z: colors,
featureidkey: 'properties.shapeName',
text: hoverTexts,
hovertemplate: '<b>%{location}</b><br>%{text}<extra></extra>',
colorscale: [ // red to blue, with grey for no data
[0, 'rgb(169,169,169)'], // Grey for no data
[0.0000001, 'rgb(255, 0, 0)'], // Red
[0.222222222222, 'rgb(244,109,67)'],
[0.5, 'rgb(255,255,224)'], // Light Yellow
[0.777777777778, 'rgb(116,173,209)'],
[1, 'rgb(69,117,180)'] // Blue
],
showscale: false,
zmin: -1,
zmax: 1,
marker: {line: {width: 0}},
}];
const layout = {
mapbox: {
style: "carto-positron",
center: {lat: 6.4238, lon: -66.5897},
zoom: 5.5
},
margin: {r: 0, t: 0, b: 0, l: 0}
};
Plotly.newPlot('map', data, layout, {responsive: true});
// Add click event listener
document.getElementById('map').on('plotly_click', function(data) {
const location = data.points[0].location;
const feature = venezuela_geojson.features.find(f => f.properties.shapeName === location);
if (feature) {
const infoDiv = document.getElementById('info');
infoDiv.innerHTML = `<h3>${location}</h3><strong>Totales:</strong><br>${feature.properties.mainInfo}`;
// Add detailed information from mesas
feature.properties.mesas.forEach((mesa, index) => {
const mesaDiv = document.createElement('div');
mesaDiv.innerHTML = `
<strong>Mesa ${index + 1}</strong><br>
N. Maduro: ${mesa['N. Maduro']}<br>
E. González: ${mesa['E. González']}<br>
Otros: ${mesa['OTROS']}
`;
infoDiv.appendChild(document.createElement('hr'));
infoDiv.appendChild(mesaDiv);
if (mesa.URL) {
const img = document.createElement('img');
img.src = img.src = 'https://static.resultadosconvzla.com/' + mesa.URL + '.jpg';
img.alt = 'Image';
img.style.maxWidth = '100%';
img.style.marginTop = '10px';
const bttn = document.createElement('button');
bttn.innerHTML = 'Abrir imagen del acta';
bttn.onclick = function() {
const modal = document.getElementById("myModal");
const modalImg = document.getElementById("modalImage");
modal.style.display = "block";
modalImg.src = img.src;
}
infoDiv.appendChild(document.createElement('br'));
infoDiv.appendChild(bttn);
}
});
}
});
})
.catch(error => console.error('Error loading the GeoJSON file:', error));
// Get the modal
const modal = document.getElementById("myModal");
// Get the <span> element that closes the modal
const span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
</body>
</html>