-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
275 lines (237 loc) · 9.9 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mapa Andalucía - Elecciones autonómicas 2012</title>
<meta name="description" content="">
<meta name="author" content="">
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!-- Le styles -->
<link href="css/bootstrap.css" rel="stylesheet">
<style>
html, body {
margin: 0;
padding: 0;
height: 100%;
overflow:hidden;
}
#map_canvas {background:#F0F0F0; top: 40px; }
#loader {
width:200px;
padding:10px;
position:absolute;
top: 50px;
z-index:1000;
margin:auto;
margin-left:-100px;
left:50%;
}
#legend {
background:#FFF;
width:200px;
padding:10px;
position:absolute;
top: 50px;
z-index:1000;
margin:auto;
margin-left:-100px;
right:0;
display:none;
}
</style>
<!-- Le fav and touch icons -->
<link rel="shortcut icon" href="images/favicon.ico">
<link rel="apple-touch-icon" href="images/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png">
<link href="css/leaflet.css" rel="stylesheet" type="text/css" />
<link href="css/leaflet.ie.css" rel="stylesheet" type="text/css" />
<link href="css/cartodb.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="js/leaflet.js"></script>
<script type="text/javascript" src="js/wax.leaflet.min.js"></script>
<script type="text/javascript" src="js/cartodb-leaflet.js"></script>
<script type="text/javascript">
var cartodb_leaflet1
, cartodb_leaflet2;
var map;
function create_polygons(ready) {
var polygons = {};
var polygons_url = 'https://viz2.cartodb.com/api/v2/sql?q=select name_2,name_4, ST_Simplify(the_geom, 0.005) as the_geom from andalucia&format=geojson';
$.getJSON(polygons_url, function(data) {
var geojson = new L.GeoJSON();
var features = data.features;
for (var i = 0, len = features.length; i < len; ++i) {
var pol = new Object();
var geo = L.GeoJSON.geometryToLayer(features[i].geometry);
geo.setStyle({
weight: 4,
color: '#FFFFFF',
opacity: 1,
fillColor: '#FFFFFF',
fillOpacity: 0.1
});
pol.geo = geo;
pol.prop = features[i].properties;
var key = features[i].properties.name_2 + "_" + features[i].properties.name_4;
if(polygons[key]) {
polygons[key].push(pol);
} else {
polygons[key] = [pol];
}
}
ready(polygons);
});
}
function init_map(polygons) {
var current_polygon = null;
map = new L.Map('map_canvas').setView(new L.LatLng(37.26312408340919,-4.66094970703125), 8);
var legend = {
out: function() {
$('div.over').hide();
$('body').css({cursor:'default'});
$("#legend").hide();
},
over: function(feature, div, opt3, evt){
$('div.over').text(feature).show();
$('div.over').tooltip('show')
featureAttributes = feature.split(":");
//["Jaén", "Pozo Alcón", "PSOE", "PP", "IULV-CA", "45.24", "43.23", "4.81", "1127", "1077", "120"]
$("#provincia").text(featureAttributes[0]);
$("#municipio").text(featureAttributes[1]);
$("#primer_partido").text(featureAttributes[2]);
$("#segundo_partido").text(featureAttributes[3]);
$("#tercer_partido").text(featureAttributes[4]);
$("#percen_1").text(featureAttributes[5]);
$("#percen_2").text(featureAttributes[6]);
$("#percen_3").text(featureAttributes[7]);
$("#votos_1").text(featureAttributes[8]);
$("#votos_2").text(featureAttributes[9]);
$("#votos_3").text(featureAttributes[10]);
$("#legend").show();
}
}
// options to control events on geometries
var waxOptions = {
callbacks: {
out: function(){
$('body').css({cursor:'default'});
if(current_polygon) {
for(var i=0; i < current_polygon.length; ++i) {
map.removeLayer(current_polygon[i].geo);
}
current_polygon = null;
}
legend.out();
},
over: function(feature, div, opt3, evt){
legend.over(feature, div, opt3, evt);
$('body').css({cursor:'pointer'});
var key = feature.split(':').slice(0, 2).join('_');
current_polygon = polygons[key];
for(var i=0; i < current_polygon.length; ++i) {
map.addLayer(current_polygon[i].geo);
}
},
click: function(feature, div, op3, evt) {
}
},
};
cartodb_leaflet2 = new L.CartoDBLayer({
map_canvas: 'map_canvas',
map: map,
user_name:"viz2",
table_name: 'andalucia',
infowindow: false,
query: "SELECT * FROM {{table_name}}",
interactivity: ["info"],
auto_bound: false,
debug: false,
waxOptions: waxOptions
});
}
/**
* init the app
*/
function initialize() {
// ask for the data first, when it is ready the map can be initializated
create_polygons(function(vector_polygons) {
init_map(vector_polygons);
});
}
function openfeature(feature) {
alert("sddsd");
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
<div id="legend">
<h2 id="provincia">Granada</h2>
<h3 id="municipio">Roquetas del mar</h3><br>
<b id="primer_partido">PP</b> - <span id="votos_1">2323</span> votos (<span id="percen_1">56</span>%)<br>
<b id="segundo_partido">PSOE</b> - <span id="votos_2">123</span> votos (<span id="percen_2">30</span>%)<br>
<b id="tercer_partido">IUE_LVASD</b> - <span id="votos_3">22</span> votos (<span id="percen_3">2</span>%)<br>
</div>
<a class="cartodb_logo" href="http://www.cartodb.com" target="_blank">CartoDB</a>
<div class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Andalucía - Elecciones autonómicas 2012 </a>
<div class="nav-collapse">
<ul class="nav">
<li class="active"><a href="#">Mapa</a></li>
<li><a href="#myModal "data-toggle="modal" id="about">Acerca</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div id="myModal" class="modal hide fade">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Acerca de este mapa...</h3>
</div>
<div class="modal-body">
<p>Los datos de este mapa han sido sacados de <a href="http://resultados-elecciones.rtve.es/andalucia/municipios">rtve.es</a>, ya que ha sido imposible encontrar una fuente donde descargar los datos la noche electoral.<br><br>
Puedes descargar todos los datos en un <a href="http://vizzuality.s3.amazonaws.com/andalucia_map/andalucia_shp.zip">shapefile</a>,<a href="http://vizzuality.s3.amazonaws.com/andalucia_map/andalucia.kmz">KML</a>, <a href="http://vizzuality.s3.amazonaws.com/andalucia_map/andalucia.csv.zip">CSV</a>, o bien utilizar la <a href="http://viz2.cartodb.com/api/v1/sql?q=SELECT%20*%20from%20andalucia" target="_blank">API de CartoDB</a>.<br><br>
Si quieres, tambien puedes embedder este mapa en tu página web usando el siguiente código:<br><br>
<code>
<iframe width="950" height="500" frameborder="0" src='http://vizzuality.s3.amazonaws.com/andalucia_map/embed.html' />
</code>
<br><br>
Este mapa utiliza <a href="http://www.cartodb.com">CartoDB</a> para crear los mapas, y <a href="http://leaflet.cloudmade.com/">Leaflet</a> para visualizarlos. Ha sido realizado por <a href="https://twitter.com/#!/jatorre/">@jatorre</a>, si tienes alguna duda contactame via Twitter.
</p>
</div>
<div class="modal-footer">
<a href="#" class="btn" data-dismiss="modal" >Close</a>
</div>
</div>
<div class="container">
</div> <!-- /container -->
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-tab.js"></script>
<script src="js/bootstrap-tooltip.js"></script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20934186-3']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>