1(function ($) { 2 var mapcenter = { x: 359139.02745, y: 4129794.0256 }; 3 var mapbox = [100427.45229504647, 3987127.1119194655, 621550.2060316373, 4288689.931631325]; 4 $(window).on('resize', function () { 5 resize_elements(); 6 }); 7 8 $(window).on('load', function () { 9 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 10 }); 11 12 13 //Inicializamos Mapea 14 var mapajs = M.map({ 15 container: "mapea", 16 //wmcfiles: ["mapa"], 17 layers: [new M.layer.OSM()] 18 }); 19 20 21 mapajs.setCenter(mapcenter).setZoom(3); 22 23 //flag para desactivar el cambio de municipios 24 var desabilitarMunis = 0; 25 //flag para evitar la desactivacion del hover 26 var munihover = 0; 27 28 var defaultconvocatoria = 5; 29 var defaultfconvocatoria; 30 //var defaultfconvocatoria=201503; 31 var urlapi = (typeof SIEL_API_URL !== 'undefined') ? SIEL_API_URL : "https://ws040.juntadeandalucia.es/siel-api"; 32 33 34 $('#currentprovincia').val(-1); 35 $('#currentmunicipio').val(-1); 36 $('#rausentes').prop('checked', false); 37 $('#celectos').prop('checked', false); 38 $('#municipios').prop('disabled', true); 39 $('#distritos').prop('disabled', true); 40 $('#secciones').prop('disabled', true); 41 $('#mesas').prop('disabled', true); 42 $('#tablacandidatos').hide(); 43 $('.coldiputados').hide(); 44 45 $('#celectos').change(function () { 46 if ($(this).is(':checked')) { 47 //Desactivamos las opciones no compatibles con esta opcion 48 $('#rausentes').prop("disabled", true); 49 $('#provincia').prop("disabled", true); 50 $('#municipios').prop("disabled", true); 51 $('#distritos').prop("disabled", true); 52 $('#secciones').prop('disabled', true); 53 $('#mesas').prop('disabled', true); 54 //$('#partidos').prop( "disabled", true ); 55 $('#currentprovincia').val(-1); 56 $('#currentmunicipio').val(-1); 57 $('#provincia').val(-1); 58 $('#municipios').val(-1); 59 $('#distritos').val(-1); 60 $('#partidos').val(-1); 61 $('#tablacandidatos_wrapper').show(); 62 $('#tablacandidatos').show(); 63 $('#tablaresultados_wrapper').hide(); 64 $('#graficas').hide(); 65 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 66 } 67 else { 68 $('#partidos').val(-1); 69 $('#rausentes').prop("disabled", false); 70 $('#provincia').prop("disabled", false); 71 $('#partidos').prop("disabled", true); 72 $('#tablacandidatos_wrapper').hide(); 73 $('#tablacandidatos').hide(); 74 $('#tablaresultados_wrapper').show(); 75 $('#graficas').show(); 76 } 77 78 actualizartabladatos(); 79 actualizarinformacion(); 80 comprobarformulario(); 81 }); 82 83 $('#rausentes').change(function () { 84 if ($(this).is(':checked')) { 85 //Desactivamos las opciones no compatibles con esta opcion 86 $('#municipios').prop("disabled", true); 87 $('#distritos').prop("disabled", true); 88 $('#scciones').prop("disabled", true); 89 $('#mesas').prop("disabled", true); 90 $('#partidos').prop("disabled", true); 91 $('#currentprovincia').val(-1); 92 $('#currentmunicipio').val(-1); 93 $('#municipios').val(-1); 94 $('#distritos').val(-1); 95 $('#secciones').val(-1); 96 $('#mesas').val(-1); 97 $('#partidos').val(-1); 98 actualizartabladatos(); 99 actualizarinformacion(); 100 comprobarformulario(); 101 } 102 else { 103 //Volvemos a activar 104 $('#provincia').val(-1); 105 $('#municipios').prop("disabled", false); 106 $('#distritos').prop("disabled", false); 107 $('#mesas').prop("disabled", false); 108 $('#seccione').prop("disabled", false); 109 $('#partidos').prop("disabled", false); 110 $('#currentprovincia').val($('#provincia').val()); 111 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 112 actualizartabladatos(); 113 actualizarinformacion(); 114 comprobarformulario(); 115 } 116 }); 117 118 function cargarMunicipios () { 119 120 const mapa = mapajs; 121 let layer = new M.layer.Vector(); 122 layer.setZIndex(1000000); 123 layer.name = "Municipios IECA"; 124 125 function getFeatureRequestBody(requestParams) { 126 return new ol.format.WFS().writeGetFeature({ 127 srsName: requestParams.srsName, 128 featurePrefix: requestParams.featurePrefix, 129 featureTypes: requestParams.featureTypes, 130 outputFormat: requestParams.outputFormat 131 }); 132 } 133 134 function readGML3Features(gmlText) { 135 let proj = new ol.proj.Projection({ 136 code: 'http://www.opengis.net/gml/srs/epsg.xml#25830', 137 axis: 'enu' 138 }); 139 ol.proj.addEquivalentProjections([ol.proj.get(mapa.getProjection().code), proj]); 140 return new ol.format.GML3().readFeatures(gmlText, mapa.getProjection()); 141 } 142
143 const requestParams = { 144 "id": "poligonos_LLMM", 145 "type": "service", 146 "description": "Municipios IECA", 147 "url": "https://www.ieca.junta-andalucia.es/wfs/lineaslimite?", 148 "srsName": "EPSG:25830", 149 "featurePrefix": "", 150 "featureTypes": [ 151 "poligonos_LLMM" 152 ] 153 } 154 155 let featureRequest = getFeatureRequestBody(requestParams); 156 let body = new XMLSerializer().serializeToString(featureRequest); 157 let options = {}; 158 159 M.remote.post(requestParams.url, body, options) 160 .then(function (response) { 161 if (response.code === 200) { 162 return response.text; 163 } 164 else { 165 M.dialog.error('No se ha podido realizar la consulta'); 166 return; 167 } 168 }).then(function (text) { 169 var features = readGML3Features(text); 170 171 if (features.length > 0) { 172 let geojsonFormat = new ol.format.GeoJSON(); 173 for (let i = 0; i < features.length; i++) { 174 let jsonFeature = geojsonFormat.writeFeatureObject(features[i]); 175 let newFeature = new M.Feature(features[i].getId(), jsonFeature); 176 layer.addFeatures(newFeature); 177 } 178 } 179 else { 180 M.dialog.info('No se han encontrado ' + requestParams.description); 181 } 182 }).catch(function (e) { 183 M.dialog.error('No se ha podido realizar la consulta'); 184 }); 185 186 return layer; 187 } 188 189 //Cargamos capa GeoJSON Provincias 190 let layerprov = new M.layer.GeoJSON({ 191 name: "Provincias", 192 url: "https://hcsigc.juntadeandalucia.es/geoserver/IECA/wfs?service=WFS&version=1.0.0&request=GetFeature&typename=sigc_provincias_1724753768757&outputFormat=application/json&srsname=EPSG:25830", 193 extract: false, 194 }); 195 196 //Cargamos capa GeoJSON Municipios 197 let layermun = cargarMunicipios(); 198 199 var q = new M.style.Polygon({ stroke: { color: "#017537" } }); 200 var d = new M.style.Polygon({ label: { text: function (layerprov) { return (layerprov.getAttribute("municipio")) }, color: "black", stroke: { color: "#E5FFCC", width: 2 } }, fill: { color: "#017537", opacity: 0.25, }, stroke: { color: "#017537", width: 0.5, } }); 201 var c = new M.style.Polygon({ label: { text: function (layerprov) { return (layerprov.getAttribute("provincia")) }, color: "black", stroke: { color: "#E5FFCC", width: 3 } }, fill: { color: "#017537", opacity: 0.5, }, stroke: { color: "#FFFFFF", width: 0.5 } }); 202 var F = new M.style.Polygon({ label: { text: function (layerprov) { return (layerprov.getAttribute("municipio")) }, color: "black", stroke: { color: "#E5FFCC", width: 3 } }, fill: { color: "#017537", opacity: 0.75, }, stroke: { color: "#FFFFFF", width: 2 } }); 203 204 205 var styleprov = new M.style.Polygon({ label: { text: "", color: "black", stroke: { color: "#E5FFCC", width: 2 } }, fill: { color: "#017537", opacity: 0.25, }, stroke: { color: "#017537", width: 0.5, } }); 206 207 var styleprovhover = new M.style.Polygon({ label: { text: "", color: "black", stroke: { color: "#E5FFCC", width: 3 } }, fill: { color: "#017537", opacity: 0.5, }, stroke: { color: "#FFFFFF", width: 0.5 } }); 208 209 var styleprovoff = new M.style.Polygon({ label: { text: '', color: "black", stroke: { color: "transparent", width: 0 } }, fill: { color: "#017537", opacity: 0, }, stroke: { color: "transparent", width: 0, } }); 210 211 212 var stylemunoff = new M.style.Polygon({ label: { text: '', color: "black", stroke: { color: "transparent", width: 0 } }, fill: { color: "#017537", opacity: 0, }, stroke: { color: "transparent", width: 0, } }); 213 214 var stylemunon = new M.style.Polygon({ label: { text: '', color: "black", stroke: { color: "#E5FFCC", width: 2 } }, fill: { color: "#017537", opacity: 0.75, }, stroke: { color: "#017537", width: 0.75, } }); 215 216 var stylemunhover = new M.style.Polygon({ label: { text: function (layermun) { var nombremun = layermun.getAttribute("nameunit"); return nombremun; }, color: "#000000", stroke: { color: "#E5FFCC", width: 2 } }, fill: { color: "#017537", opacity: 0.90, }, stroke: { color: "#017537", width: 0.5, } }); 217 218 layerprov.setStyle(styleprov); 219 220 layermun.setStyle(stylemunoff); 221 222 mapajs.addLayers(layerprov); 223 mapajs.addLayers(layermun); 224 mapajs.removePopup(); 225 226
227 //Controlamos el CLIC sobre el municipio 228 layermun.on(M.evt.SELECT_FEATURES, function (features) { 229 // Limpiar selección anterior 230 layermun.getFeatures().forEach(function (muni) { 231 if (Number(muni.getAttribute('prov') == $('#currentprovincia').val())) { 232 muni.setStyle(stylemunon); 233 } 234 }); 235 236 // Procesar nueva selección 237 if ($('#currentprovincia').val() != 0 && $('#nextstep').val() == "municipio") { 238 features.forEach(function (feature) { 239 if (Number(feature.getAttribute('prov') == $('#currentprovincia').val())) { 240 var codigomunicipio = feature.getAttribute('codigo_ine').slice(2, 5); 241 codigomunicipio = Number(codigomunicipio); 242 $('#municipios').val(codigomunicipio); 243 $('#currentmunicipio').val(codigomunicipio); 244 munihover = feature.getAttribute("codigo_ine"); 245 feature.setStyle(stylemunhover); 246 } 247 }); 248 cambiarmunicipio(); 249 comprobarformulario(); 250 } 251 }); 252 253 //Controlamos el CLIC sobre la provincia 254 layerprov.on(M.evt.SELECT_FEATURES, function (features) { 255 //Se hace clic en el mapa 256 features.forEach(function (feature) { 257 if (feature.getId().slice(5, 15) == "provincias") { 258 //Se hace clic en una provincia distinta a la seleccionada 259 if ($('#provincia').val() != Number(feature.getAttribute('cod_prov'))) { 260 var coordenadaspoligono = feature.getGeometry(); 261 var limites = calcularbordespoligono(coordenadaspoligono.coordinates); 262 mapajs.setBbox(limites); 263 codigoprovincia = Number(feature.getAttribute('cod_prov')); 264 $('#provincia').val(codigoprovincia); 265 $('#currentprovincia').val(codigoprovincia); 266 cambiarprovincia(); 267 comprobarformulario(); 268 $('#nextstep').val("municipio"); 269 desabilitarMunis = 1; 270 //console.log('\nId: ' + feature.getId()); 271 //console.log('Provincia: ' + feature.getAttribute('nombre') + feature.getAttribute('cod_prov') ); 272 layermun.getFeatures().forEach(function (muni) { 273 var cod_provincia = muni.getAttribute('prov'); 274 if (cod_provincia == feature.getAttribute('cod_prov')) { 275 //console.log(muni.getAttribute('municipio')); 276 muni.setStyle(stylemunon); 277 } 278 else { 279 muni.setStyle(stylemunoff); 280 } 281 }); 282 feature.setStyle(styleprovoff); 283 } else { 284 feature.setStyle(styleprov); 285 } 286 } 287 }) 288 }); 289 290 //funcion para colorear los municipios 291 function mostrarMunisProvincia(features) { 292 features.forEach(function (feature) { 293 layermun.getFeatures().forEach(function (muni) { 294 var cod_provincia = muni.getAttribute('prov'); 295 //console.log("muniProv: ",provincia,"// featureProv: ",feature.getAttribute('provincia')); 296 if (cod_provincia == feature.getAttribute('cod_prov')) { 297 //console.log(muni.getAttribute('municipio')); 298 muni.setStyle(stylemunon); 299 } 300 else { 301 muni.setStyle(stylemunoff); 302 } 303 }); 304 }); 305 }; 306 307 308 /**ESTILOS PARA LAS CAPAS PROVINCIAS Y MUNICIPIOS**/ 309 layerprov.on(M.evt.LEAVE_FEATURES, function (K) { 310 var J = K[0]; 311 if (Number(J.getAttribute('cod_prov')) == $('#currentprovincia').val()) { 312 J.setStyle(styleprovoff); 313 } else { 314 J.setStyle(styleprov); 315 } 316 }); 317 318 layerprov.on(M.evt.HOVER_FEATURES, function (K) { 319 var J = K[0]; 320 if (Number(J.getAttribute('cod_prov')) == $('#currentprovincia').val()) { 321 J.setStyle(styleprovoff); 322 } else { 323 J.setStyle(styleprovhover); 324 } 325 }); 326 327 layermun.on(M.evt.LEAVE_FEATURES, function (K) { 328 // Limpiar hover de todos los municipios excepto el seleccionado 329 layermun.getFeatures().forEach(function (muni) { 330 if ($('#currentmunicipio').val() == -1 || 331 muni.getAttribute('codigo_ine') != $('#provincia').val() + 332 ($('#currentmunicipio').val() < 10 ? "00" : $('#currentmunicipio').val() < 100 ? "0" : "") + 333 $('#currentmunicipio').val()) { 334 335 if (Number(muni.getAttribute('prov')) == $('#provincia').val()) { 336 if (munihover == muni.getAttribute('codigo_ine')) { 337 munihover = 0; 338 muni.setStyle(stylemunhover); 339 } else { 340 muni.setStyle(stylemunon); 341 } 342 } else { 343 muni.setStyle(stylemunoff); 344 } 345 } 346 }); 347 }); 348 349 350 layermun.on(M.evt.HOVER_FEATURES, function (K) { 351 // Solo aplicar hover si no hay un municipio seleccionado actualmente 352 var J = K[0]; 353 if (Number(J.getAttribute('prov')) == $('#currentprovincia').val()) { 354 munihover = J.getAttribute("codigo_ine"); 355 J.setStyle(stylemunhover); 356 } 357 }); 358 359 360 361 //Inicializamos los tipos de elecciones desde la base de datos (por ahora no) 362 /*$$.getJSON( urlapi+"/v1/opciones/tconvocatoria", function( data ) { 363 $.each( data.reverse(), function( key, val ) { 364 $("#tconvocatoria").append( "<option value='" + val.clave + "'" + (val.clave==defaultconvocatoria?" selected='selected'":"") + ">" + val.valor + "</option>" ); 365 }); 366 });*/ 367 368 //Inicializamos los tipos de elecciones a mano incluyendo solo las andaluzas 369 $("#tconvocatoria").append("<option value='5' selected='selected'>Elecciones autonómicas</option>").append("<option value='1'>Referéndum</option>"); 370 371 //Inicializamos las convocatorias 372 $.getJSON(urlapi + "/v1/opciones/fconvocatoria?&tconvocatoria=" + defaultconvocatoria, function (data) { 373 $.each(data.reverse(), function (key, val) { 374 $("#fconvocatoria").append("<option value='" + val.clave + "'>" + val.valor.slice(0, 4) + "/" + val.valor.slice(4, 6) + "</option>"); 375 }); 376 // PREMARCAMOS LA CONVOCATORIA MAS RECIENTE 377 var miSelect = document.getElementById("fconvocatoria"); 378 $('#fconvocatoria option').eq(1).prop('selected', true); 379 // ALMACENAMOS EN LA VARIABLE defaultfconvocatoria LA OPCION PREMARCADA 380 const selectedOption = $('#fconvocatoria option:selected'); 381 defaultfconvocatoria = selectedOption.val(); 382 }); 383 384 // HACEMOS UNA PAUSA DE 2 SEGUNDOS PAARA EVITAR QUE SE EJECUTE LA FUNCION inipartidos 385 // ANTES DE QUE LA VARIABLE defaultfconvocatoria ESTE CARGADA 386 setTimeout(function () { 387 inidatosconvocatoria(); 388 console.log("Datos de convocatoria inicializados"); 389 }, 2000); 390 391 function inidatosconvocatoria() { 392 //Inicializamos los partidos 393 $.getJSON(urlapi + "/v1/opciones/partido/cautonoma?cautonoma=1&tconvocatoria=" + defaultconvocatoria + "&fconvocatoria=" + defaultfconvocatoria, function (data) { 394 data.sort(function (a, b) { 395 if (a.valor > b.valor) { 396 return 1; 397 } 398 if (a.valor < b.valor) { 399 return -1; 400 } 401 // a must be equal to b 402 return 0; 403 }); 404 $.each(data, function (key, val) { 405 $("#partidos").append("<option value='" + val.clave + "'>" + val.valor.toUpperCase() + "</option>"); 406 }); 407 }); 408 409 //Primera carga de información RESUMEN 410 $.getJSON(urlapi + "/v1/resumen/cautonoma?cautonoma=1&tconvocatoria=" + defaultconvocatoria + "&fconvocatoria=" + defaultfconvocatoria, function (data) { 411 formatearinformacion(data); 412 }); 413 414 } 415 416 //Inicializamos las provincias 417 $.getJSON(urlapi + "/v1/opciones/provincia?cautonoma=1", function (data) { 418 $.each(data, function (key, val) { 419 $("#provincia").append("<option value='" + val.clave + "'>" + val.valor + "</option>"); 420 }); 421 422 //Inicializamos la tabla con los datos de la convocatoria más reciente 423 actualizartabladatos(); 424 }); 425 426 427 $("#tconvocatoria").change(function () { 428 if ($(this).val() == -1) { 429 $('#chart').html("<p> </p>"); 430 $('#chartistbuttons').empty(); 431 $('#tablaresultados_wrapper').hide(); 432 $('#descripcion').text(''); 433 } 434 $('#currentprovincia').val(-1); 435 $('#currentmunicipio').val(-1); 436 $('#rausentes').prop('checked', false).prop('disabled', false); 437 $('#celectos').prop('checked', false).prop('disabled', false); 438 $('#provincia').prop('disabled', false).val(-1); 439 $('#municipios').prop('disabled', true).val(-1); 440 $('#distritos').prop('disabled', true).val(-1); 441 $('#secciones').prop('disabled', true).val(-1); 442 $('#mesas').prop('disabled', true).val(-1); 443 $('#tablacandidatos').hide(); 444 $('.coldiputados').hide(); 445 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 446 comprobarformulario(); 447 actualizarconvocatorias(); 448 //Metemos un delay de 500ms entre que se cargan las convocatorias y se cargan los datos de las tablas porque en Chrome da error 449 setTimeout(function () { 450 actualizarpartidos(); 451 actualizartabladatos(); 452 actualizarinformacion(); 453 }, 500); 454 455 }); 456 457 $("#fconvocatoria").change(function () { 458 if ($(this).val() == -1) { 459 $('#chart').html("<p> </p>"); 460 $('#chartistbuttons').empty(); 461 $('#dt-buttons').hide(); 462 $('#descripcion').text(''); 463 $('#tablaresultados_wrapper').hide(); 464 } 465 limpiarpartesformulario(); //SIEL-338 466 comprobarformulario(); 467 actualizarpartidos(); 468 actualizartabladatos(); 469 actualizarinformacion(); 470 }); 471 472 $("#provincia").change(function () { 473 cambiarprovincia(); 474 if ($(this).val() == -1) { 475 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 476 } 477 else { 478 centrarmapaprovincia(layerprov, layermun, mapajs, stylemunon, stylemunoff, $('#provincia').val()); 479 } 480 }); 481 482 $("#municipios").change(function () { 483 cambiarmunicipio(); 484 centrarmapamunicipio(layerprov, layermun, mapajs, stylemunhover, stylemunon, stylemunoff, $('#municipios').val()); 485 }); 486 487 $("#distritos").change(function () { 488 cambiardistrito(); 489 }); 490 491 $("#secciones").change(function () { 492 cambiarseccion(); 493 }); 494 495 $("#mesas").change(function () { 496 comprobarformulario(); 497 actualizartabladatos(); 498 actualizarinformacion(); 499 }); 500 501 $("#partidos").change(function () { 502 comprobarformulario(); 503 actualizartabladatos(); 504 actualizarinformacion(); 505 if ($('#celectos').is(':checked')) { 506 if ($(this).val() == -1) { 507 $('#graficas').hide(); 508 } 509 else { 510 $('#graficas').show(); 511 } 512 } 513 }); 514 515 516 // FUNCION QUE LIMPIA PARTES DEL FORMULARIO SIEL-338 517 function limpiarpartesformulario() { 518 $('#currentprovincia').val(-1); 519 $('#currentmunicipio').val(-1); 520 $('#rausentes').prop('checked', false).prop('disabled', false); 521 $('#celectos').prop('checked', false).prop('disabled', false); 522 $('#provincia').prop('disabled', false).val(-1); 523 $('#municipios').prop('disabled', true).val(-1); 524 $('#distritos').prop('disabled', true).val(-1); 525 $('#secciones').prop('disabled', true).val(-1); 526 $('#mesas').prop('disabled', true).val(-1); 527 $('#tablacandidatos').hide(); 528 $('.coldiputados').hide(); 529 resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff); 530 } 531 532 533 //Función para actualizar la tabla de datos 534 function actualizartabladatos() { 535 $('#error').hide(); 536 if ($("#tconvocatoria").val() != -1 && $("#fconvocatoria").val() != -1) { 537 if ($('#celectos').is(':checked') && $('#partidos').val() == -1) { 538 var urldata = urlapi + "/v1/celectos?cautonoma=1&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&partido=" + $("#partidos").val(); 539 } 540 else {
541 $('#titulocolumna').html('Formación polÃtica'); 542 var tipoambito = detectarambito(); 543 var endpoint = "ambito"; 544 if ($('#partidos').val() == -1) { 545 if ($('#rausentes').is(':checked')) { 546 endpoint = "ambito/rausentes"; 547 } 548 //Mostramos la tabla de resultados convencional 549 $('#titulocolumna').html('Formación polÃtica'); 550 if ($("#tconvocatoria").val() == 1) { 551 //Cabecera referendum 552 $('#titulocolumna').html('Opción votada'); 553 } 554 } 555 else { 556 $('#titulocolumna').html('Fromación polÃtica'); 557 endpoint = "partido"; 558 //Mostramos la tabla de resultados de partido 559 if (tipoambito == "distrito") { 560 tipoambito = "municipio"; 561 } 562 563 if (tipoambito == "cautonoma") { 564 $('#titulocolumna').html('Provincia'); 565 } 566 else if (tipoambito == "provincia") { 567 $('#titulocolumna').html('Municipio'); 568 } 569 else if (tipoambito == "municipio") { 570 $('#titulocolumna').html('Distrito'); 571 } 572 else if (tipoambito == "distrito") { 573 $('#titulocolumna').html('Sección'); 574 } 575 else if (tipoambito == "seccion") { 576 $('#titulocolumna').html('Mesa'); 577 } 578 else if (tipoambito == "mesa") { 579 $('#titulocolumna').html('Fromación polÃtica'); 580 } 581 } 582 var urldata = urlapi + "/v1/escrutinio/" + endpoint + "/" + tipoambito + "?cautonoma=1&provincia=" + $("#provincia").val() + "&municipio=" + $("#municipios").val() + "&distrito=" + $("#distritos").val() + "&seccion=" + $("#secciones").val() + "&mesa=" + $("#mesas").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&partido=" + $("#partidos").val(); 583 } 584 refrescandodatos(); 585 $.ajax({ 586 url: urldata, 587 dataType: 'json', 588 async: true, 589 success: function (data) { 590 if ($('#celectos').is(':checked') && $('#partidos').val() == -1) { 591 dibujatablacandidatos(data); 592 datosrefrescados('tablacandidatos'); 593 $('#chart').html().empty(); 594 $('#chartistbuttons').empty(); 595 } 596 else { 597 dibujatablanormal(data); 598 datosrefrescados('tablaresultados'); 599 //Dibujamos la gráfica 600 var labels = []; 601 var serienumvotos = []; 602 var serieporcvotos = []; 603 data.votos.forEach(function (linea) { 604 labels.push(linea.conjunto.split(" - ")[0]); 605 serienumvotos.push(Number(linea.numvotos)); 606 serieporcvotos.push(Number(linea.porcentajeVotos)); 607 }); 608 609 610 611 612 labels = labels.slice(0, 10); 613 serienumvotos = serienumvotos.slice(0, 10); 614 serieporcvotos = serieporcvotos.slice(0, 10); 615 616 617 serienumvotos = [serienumvotos]; 618 serieporcvotos = [serieporcvotos]; 619 var datosgrafico = { labels: labels, series: serienumvotos }; 620 var datosgrafico2 = { labels: labels, series: serieporcvotos }; 621 622 $('#chart >p').remove(); 623 $('#chartistbuttons').empty(); 624 dibujargrafica(datosgrafico); 625 $('#graficas').show(); 626 $('#chartistbuttons').append('<input id="graphvotos" class="btn-chartist" type="button" value="Votos"/>'); 627 $('#chartistbuttons').append('<input id="graphporc" class="btn-chartist" type="button" value="% Votos"/>'); 628 629 $('#graphvotos').click(function () { 630 dibujargrafica(datosgrafico); 631 }); 632 $('#graphporc').click(function () { 633 dibujargrafica(datosgrafico2); 634 }); 635 } 636 }, 637 fail: function () { 638 mostrarerror(); 639 }, 640 error: function () { 641 mostrarerror(); 642 }, 643 }); 644 645 646 } 647 else { 648 $('#tablaresultados').html(''); 649 $('#tablacandidatos').html('').hide(); 650 $('#informacion').html('<h3>Seleccione una convocatoria</h3>'); 651 } 652 } 653 654 //Función que se ejectura mientras se refrescan los datos 655 function refrescandodatos() { 656 $('#descripcion').text(''); 657 $('#tablaresultados').hide(); 658 $('#tablaresultados_wrapper').hide(); 659 $('#tablacandidatos').hide(); 660 $('#tablacandidatos_wrapper').hide(); 661 $('#loading').show(); 662 $('#error').hide(); 663 } 664 665 function datosrefrescados(tablaamostrar) { 666 $('#tablaresultados').hide(); 667 $('#tablacandidatos').hide(); 668 $('#loading').hide(); 669 $('#error').hide(); 670 $('#' + tablaamostrar).show(); 671 $('#' + tablaamostrar + "_wrapper").show(); 672 } 673 674 function mostrarerror() { 675 $('#chart').html("<p>No se han obtenido datos</p>"); 676 $('#chartistbuttons').empty(); 677 $('#loading').hide(); 678 $('#error').show(); 679 } 680 681 //Funcion que dibuja la tabla normal 682 function dibujatablanormal(data) { 683 //Dibujamos la tabla de datos 684 if (data.nombreconjunto != null) { 685 $('#titulocolumna').text(data.nombreconjunto); 686 } 687 if (data.descripcion != null) { 688 $('#descripcion').text(data.descripcion); 689 } 690 var table = $('#tablaresultados').dataTable({ 691 "destroy": true, 692 "language": { 693 "emptyTable": "No se han obtenido datos", 694 }, 695 "data": data.votos, 696 "columns": [ 697 { "data": "conjunto", render: $.fn.dataTable.render.text() }, 698 { "data": "numvotos", render: $.fn.dataTable.render.number('.', ',', 0, '') }, 699 { "data": "porcentajeVotos", render: $.fn.dataTable.render.number('.', ',', 2, '') }, 700 ], 701 "order": [[1, "desc"]], 702 "searching": false, 703 "pageLength": 100, 704 "paging": false, 705 "info": false, 706 dom: 'Bfrtip', 707 buttons: ["pdfHtml5", "csvHtml5"] 708 }); 709 } 710 711 //Funcion que dibuja la tabla de candidatos 712 function dibujatablacandidatos(data) { 713 //Dibujamos la tabla de datos 714 /*function SortArray(x, y){ 715 console.log(x.conjunto); 716 console.log(y.conjunto); 717 if (x.conjunto < y.conjunto) {return -1;} 718 if (x.conjunto > y.conjunto) {return 1;} 719 return 0; 720 } 721 var ordenado = data.celectos.sort(SortArray);*/ 722 723 if (data.nombreconjunto != null) { 724 $('#titulocolumna').text(data.nombreconjunto); 725 } 726 if (data.descripcion != null) { 727 $('#descripcion').text(data.descripcion); 728 } 729 var table2 = $('#tablacandidatos').dataTable({ 730 "destroy": true, 731 "language": { 732 "emptyTable": "No se han obtenido datos", 733 }, 734 "data": data.celectos, 735 "columns": [ 736 { "data": "conjunto", render: $.fn.dataTable.render.text() }, 737 { "data": "provincia", render: $.fn.dataTable.render.text() }, 738 { "data": "numdiputados", render: $.fn.dataTable.render.number('.', ',', 0, '') }, 739 { "data": "diputados", className: "coldiputados", render: function (data, type, row) { return data.join(", "); } }, 740 ], 741 rowGroup: { 742 dataSrc: "conjunto" 743 }, 744 "order": [[0, "asc"]], 745 "searching": false, 746 "pageLength": 100, 747 "paging": false, 748 "info": false, 749 dom: 'Bfrtip', 750 buttons: ["pdfHtml5", "csvHtml5"] 751 }); 752 } 753 //Funcion que dibuja la grafica 754 function dibujargrafica(datos) { 755 //console.log(datos); 756 var options = { 757 seriesBarDistance: 10, 758 axisX: { showGrid: false, }, 759 axisY: { 760 labelInterpolationFnc: function (value) { 761 return new Intl.NumberFormat('es-ES').format(value); 762 } 763 } 764 }; 765 766 var responsiveOptions = [ 767 ['screen and (max-width: 640px)', { 768 seriesBarDistance: 5, 769 axisX: { 770 labelInterpolationFnc: function (value) { 771 return value[0] + value[1]; 772 773 }, 774 showGrid: false, 775 } 776 }] 777 ]; 778 var grafica = new Chartist.Bar('#chart', datos, options, responsiveOptions); 779 } 780 781 782 //Refresca la información de resumen cada vez que se cambia algún parámetro 783 function actualizarinformacion() { 784 if ($("#tconvocatoria").val() != -1 && $("#fconvocatoria").val() != -1) { 785 var endpoint = "resumen"; 786 var tipoambito = detectarambito(); 787 if ($('#rausentes').is(':checked')) { 788 endpoint = "resumen/rausentes"; 789 } 790 var urldata = urlapi + "/v1/" + endpoint + "/" + tipoambito + "?cautonoma=1&provincia=" + $("#provincia").val() + "&municipio=" + $("#municipios").val() + "&distrito=" + $("#distritos").val() + "&seccion=" + $("#secciones").val() + "&mesa=" + $("#mesas").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&partido=" + $("#partidos").val(); 791 $.getJSON(urldata, function (data) { 792 formatearinformacion(data); 793 }).fail(function () { $('#informacion').html('<p>No se han obtenido datos</p>'); }); 794 } 795 else { 796 $('#informacion').html('<h3>Seleccione una convocatoria</h3>'); 797 } 798 resize_elements(); 799 800 } 801 //Función para eliminar todos los options de un campo select. No elimina el primer option ya que indica la acción que debe realizar el usuario 802 function eliminarvaloresselect(options) { 803 $i = 0; 804 options.each(function () { 805 if ($i > 0) $(this).remove(); 806 ++$i; 807 }); 808 } 809 810 //Función para actualizar las convocatorias 811 function actualizarconvocatorias() { 812 eliminarvaloresselect($("#fconvocatoria option")); 813 eliminarvaloresselect($("#distritos option")); 814 eliminarvaloresselect($("#partidos option")); 815 $.getJSON(urlapi + "/v1/opciones/fconvocatoria?&tconvocatoria=" + $("#tconvocatoria").val(), function (data) { 816 var counter = 0; 817 $.each(data.reverse(), function (key, val) { 818 $("#fconvocatoria").append("<option value='" + val.clave + "'" + (counter == 0 ? " selected='selected'" : "") + ">" + val.valor.slice(0, 4) + "/" + val.valor.slice(4, 6) + "</option>"); 819 counter++; 820 }); 821 }); 822 if ($('#tconvocatoria').val() > -1) { 823 $('#provincia').prop('disabled', false); 824 $('#rausentes').prop('checked', false).prop('disabled', false); 825 } 826 } 827 828 829 //Función para actualizar el select de los municipios 830 function actualizarmunicipios() { 831 eliminarvaloresselect($("#municipios option")); 832 if ($("#provincia").val() != -1) { 833 $.getJSON(urlapi + "/v1/opciones/municipio?cautonoma=1&provincia=" + $("#provincia").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val(), function (data) { 834 data.sort(function (a, b) { 835 if (a.valor > b.valor) { 836 return 1; 837 } 838 if (a.valor < b.valor) { 839 return -1; 840 } 841 // a must be equal to b 842 return 0; 843 }); 844 $.each(data, function (key, val) { 845 $("#municipios").append("<option value='" + val.clave + "'>" + val.valor.toUpperCase() + "</option>"); 846 }); 847 }); 848 } 849 } 850 851 //Función para actualizar el select de los distritos 852 function actualizardistritos() { 853 eliminarvaloresselect($("#distritos option")); 854 if ($("#provincia").val() != -1) { 855 var municipioSeleccionado = $("#municipios").val(); 856 if (!municipioSeleccionado || municipioSeleccionado == -1 || municipioSeleccionado === 'null') { 857 return; 858 } 859 var url = urlapi + "/v1/opciones/distrito?cautonoma=1&provincia=" + $("#provincia").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&municipio=" + municipioSeleccionado; 860 $.getJSON(url, function (data) { 861 data.sort(function (a, b) { 862 if (a.valor > b.valor) { 863 return 1; 864 } 865 if (a.valor < b.valor) { 866 return -1; 867 } 868 // a must be equal to b 869 return 0; 870 }); 871 $.each(data, function (key, val) { 872 $("#distritos").append("<option value='" + val.clave + "'>" + val.valor + "</option>"); 873 }); 874 }); 875 } 876 } 877 878 //Funcion para actualizar select secciones 879 function actualizarsecciones() { 880 eliminarvaloresselect($("#secciones option")); 881 if ($("#distritos").val() != -1) { 882 $.getJSON(urlapi + "/v1/opciones/seccion?cautonoma=1&provincia=" + $("#provincia").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&municipio=" + $("#municipios").val() + "&distrito=" + $("#distritos").val(), function (data) { 883 data.sort(function (a, b) { 884 if (a.valor > b.valor) { 885 return 1; 886 } 887 if (a.valor < b.valor) { 888 return -1; 889 } 890 // a must be equal to b 891 return 0; 892 }); 893 $.each(data, function (key, val) { 894 $("#secciones").append("<option value='" + val.valor + "'>" + val.valor + "</option>"); 895 }); 896 }); 897 } 898 } 899 900 //Funcion para actualizar select mesas 901 function actualizarmesas() { 902 eliminarvaloresselect($("#mesas option")); 903 if ($("#secciones").val() != -1) { 904 $.getJSON(urlapi + "/v1/opciones/mesa?cautonoma=1&provincia=" + $("#provincia").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&municipio=" + $("#municipios").val() + "&distrito=" + $("#distritos").val() + "&seccion=" + $("#secciones").val(), function (data) { 905 data.sort(function (a, b) { 906 if (a.valor > b.valor) { 907 return 1; 908 } 909 if (a.valor < b.valor) { 910 return -1; 911 } 912 // a must be equal to b 913 return 0; 914 }); 915 $.each(data, function (key, val) { 916 $("#mesas").append("<option value='" + val.valor + "'>" + val.valor + "</option>"); 917 }); 918 }); 919 } 920 } 921 922 //Función para actualizar el select de los partidos 923 function actualizarpartidos() { 924 var partidoactual = $("#partidos").val(); 925 eliminarvaloresselect($("#partidos option")); 926 var tipoambito = detectarambito(); 927 if (tipoambito === "distrito" || tipoambito === "seccion" || tipoambito === "mesa") { 928 tipoambito = "municipio"; 929 } 930 931 var urldata = urlapi + "/v1/opciones/partido/" + tipoambito + "?cautonoma=1&provincia=" + $("#provincia").val() + "&municipio=" + $("#municipios").val() + "&distrito=" + $("#distritos").val() + "&seccion=" + $("#secciones").val() + "&mesa=" + $("#mesas").val() + "&fconvocatoria=" + $("#fconvocatoria").val() + "&tconvocatoria=" + $("#tconvocatoria").val() + "&partido=" + $("#partidos").val(); 932 933 934 $.ajax({ 935 url: urldata, 936 dataType: 'json', 937 async: false, 938 success: function (data) { 939 data.sort(function (a, b) { 940 if (a.valor > b.valor) { 941 return 1; 942 } 943 if (a.valor < b.valor) { 944 return -1; 945 } 946 // a must be equal to b 947 return 0; 948 }); 949 $.each(data, function (key, val) { 950 $("#partidos").append("<option value='" + val.clave + "'" + (val.clave == partidoactual ? " selected='selected'" : "") + ">" + val.valor.toUpperCase() + "</option>"); 951 }); 952 } 953 }); 954 } 955 956 function cambiarprovincia() { 957 // Limpiar selección de municipio
958 layermun.getFeatures().forEach(function (muni) { 959 muni.setStyle(stylemunoff); 960 }); 961 962 $('#currentmunicipio').val(-1); 963 $('#currentprovincia').val($('#provincia').val()); 964 $('#partidos').prop('disabled', false).val(-1); 965 actualizarpartidos(); 966 actualizarmunicipios(); 967 actualizartabladatos(); 968 actualizarinformacion(); 969 comprobarformulario(); 970 } 971 972 function centrarmapaprovincia(layerprov, layermun, mapajs, stylemunon, stylemunoff, cod_prov) { 973 var features = layerprov.getFeatures(); 974 //console.log("cod_prov: ", cod_prov); 975 if (cod_prov < 10) { 976 cod_prov = "0" + cod_prov; 977 } 978 features.forEach(function (feature) { 979 //console.log(feature.getAttribute('cod_prov')+"--"+cod_prov); 980 if (feature.getAttribute('cod_prov') == cod_prov) { 981 //Esta es la provincia que hay que centrar 982 983 var coordenadaspoligono = feature.getGeometry(); 984 var limites = calcularbordespoligono(coordenadaspoligono.coordinates); 985 mapajs.setBbox(limites); 986 //console.log(limites); 987 $('#provincia').val(Number(feature.getAttribute('cod_prov'))); 988 $('#nextstep').val("municipio"); 989 //console.log('Provincia: ' + feature.getAttribute('provincia') + "/ cod: " + feature.getAttribute('cod_prov')); 990 layermun.getFeatures().forEach(function (muni) { 991 //console.log("muni prov: " + muni.getAttribute('provincia')) 992 var provincia = muni.getAttribute('provincia'); 993 if (provincia == feature.getAttribute('provincia')) { 994 //console.log(muni.getAttribute('municipio')); 995 muni.setStyle(stylemunon); 996 } 997 else { 998 //console.log("stylemunoff"); 999 muni.setStyle(stylemunoff); 1000 } 1001 }); 1002 1003 } 1004 }); 1005 } 1006 1007 function cambiarmunicipio() { 1008 $('#currentmunicipio').val($('#municipios').val()); 1009 $('#partidos').prop('disabled', false).val(-1); //SIEL-338 1010 actualizarpartidos(); 1011 actualizardistritos(); 1012 actualizartabladatos(); 1013 actualizarinformacion(); 1014 comprobarformulario(); 1015 } 1016 1017 function cambiardistrito() { 1018 actualizarsecciones(); 1019 actualizarpartidos(); 1020 actualizartabladatos(); 1021 actualizarinformacion(); 1022 comprobarformulario(); 1023 } 1024 1025 function cambiarseccion() { 1026 actualizarmesas(); 1027 actualizartabladatos(); 1028 actualizarinformacion(); 1029 comprobarformulario(); 1030 } 1031 1032 function centrarmapamunicipio(layerprov, layermun, mapajs, stylemunhover, stylemunon, stylemunoff, cod_mun) { 1033 // Resetear todos los municipios primero 1034 layermun.getFeatures().forEach(function (muni) { 1035 if (Number(muni.getAttribute('prov')) == $('#provincia').val()) { 1036 muni.setStyle(stylemunon); 1037 } else { 1038 muni.setStyle(stylemunoff); 1039 } 1040 }); 1041 1042 // Aplicar estilo al municipio seleccionado 1043 var features = layermun.getFeatures(); 1044 if ($('#currentprovincia').val() != 0 && $('#nextstep').val() == "municipio") { 1045 if (cod_mun < 10) { 1046 cod_mun = "00" + cod_mun; 1047 } else if (cod_mun < 100) { 1048 cod_mun = "0" + cod_mun; 1049 } 1050 if ($('#provincia').val() > 0 && $('#provincia').val() < 10) { 1051 cod_mun = "0" + $('#provincia').val() + cod_mun; 1052 } else { 1053 cod_mun = $('#provincia').val() + cod_mun; 1054 } 1055 1056 features.forEach(function (feature) { 1057 if (feature.getAttribute('codigo_ine') == cod_mun) { 1058 feature.setStyle(stylemunhover); 1059 } 1060 }); 1061 } 1062 } 1063 1064 //Función para mostrar la ficha resumen 1065 function formatearinformacion(data) { 1066 $('#informacion').html(''); 1067 $("#informacion").append("<h3>" + data.idescrutinio.tconvocatoria.valor + " " + data.idescrutinio.cautonoma.valor + "</h3>"); 1068 $("#informacion").append("<h4>Convocatoria " + data.idescrutinio.fconvocatoria.valor.slice(0, 4) + "/" + data.idescrutinio.fconvocatoria.valor.slice(4, 6) + "</h4>"); 1069 1070 if ($('#rausentes').is(':checked')) { 1071 $("#informacion").append("<h4>Residentes ausentes</h4>"); 1072 } 1073 1074 if (data.idescrutinio.provincia != null) { 1075 $("#informacion").append("<h4>Provincia: " + data.idescrutinio.provincia.valor + "</h4>"); 1076 } 1077 1078 if (data.idescrutinio.municipio != null) { 1079 $("#informacion").append("<h4>Municipio: " + data.idescrutinio.municipio.valor + "</h4>"); 1080 } 1081 1082 if (data.idescrutinio.distrito != null) { 1083 $("#informacion").append("<h4>Distrito: " + data.idescrutinio.distrito.valor + "</h4>"); 1084 } 1085 1086 1087 if (data.idescrutinio.seccion != null) { 1088 $("#informacion").append("<h4>Sección: " + data.idescrutinio.seccion.valor + "</h4>"); 1089 } 1090 1091 1092 if (data.idescrutinio.mesa != null) { 1093 $("#informacion").append("<h4>Mesa: " + data.idescrutinio.mesa.valor + "</h4>"); 1094 } 1095 1096 if (data.idescrutinio.partido != null) { 1097 $("#informacion").append("<h4>Formación polÃtica: " + data.idescrutinio.partido.valor + "</h4>"); 1098 } 1099 1100 1101 if (data.censo != null) { 1102 $("#informacion").append("<p><strong>Censo</strong>: " + new Intl.NumberFormat('es-ES').format(data.censo) + "</p>"); 1103 } 1104 if (data.votostotales != null) { 1105 $("#informacion").append("<p><strong>Nº votantes</strong>: " + new Intl.NumberFormat('es-ES').format(data.votostotales) + " (" + calcularporcentaje(data.votostotales, data.censo) + "%)</p>"); 1106 } 1107 if (data.abstenciones != null) { 1108 $("#informacion").append("<p><strong>Abstenciones</strong>: " + new Intl.NumberFormat('es-ES').format(data.abstenciones) + " (" + calcularporcentaje(data.abstenciones, data.censo) + "%)</p>"); 1109 } 1110 if (data.votosvalidos != null) { 1111 $("#informacion").append("<p><strong>Votos válidos</strong>: " + new Intl.NumberFormat('es-ES').format(data.votosvalidos) + " (" + calcularporcentaje(data.votosvalidos, data.votostotales) + "%)</p>"); 1112 } 1113 if (data.votosnulos != null) { 1114 $("#informacion").append("<p><strong>Votos nulos</strong>: " + new Intl.NumberFormat('es-ES').format(data.votosnulos) + " (" + calcularporcentaje(data.votosnulos, data.votostotales) + "%)</p>"); 1115 } 1116 if (data.votosblanco != null) { 1117 $("#informacion").append("<p><strong>Votos en blanco</strong>: " + new Intl.NumberFormat('es-ES').format(data.votosblanco) + " (" + calcularporcentaje(data.votosblanco, data.votosvalidos) + "%)</p>"); 1118 } 1119 if (data.votoscandidatura != null) { 1120 $("#informacion").append("<p><strong>Votos a candidaturas</strong>: " + new Intl.NumberFormat('es-ES').format(data.votoscandidatura) + " (" + calcularporcentaje(data.votoscandidatura, data.votosvalidos) + "%)</p>"); 1121 } 1122 if (data.nummesas != null) { 1123 $("#informacion").append("<p><strong>Núm. de mesas</strong>: " + new Intl.NumberFormat('es-ES').format(data.nummesas) + "</p>"); 1124 } 1125 1126 } 1127 //Función para detectar el ámbito en el que nos encontramos 1128 function detectarambito() { 1129 //console.log($( "#municipios" ).val()); 1130 if ($("#provincia").val() == -1) { 1131 // Mostramos los datos a nivel de Comunidad Autónoma 1132 var tipoambito = "cautonoma"; 1133 } 1134 else if ($("#municipios").val() == -1 || $("#municipios").val() == null) { 1135 var tipoambito = "provincia"; 1136 } 1137 else if ($("#distritos").val() == -1) { 1138 var tipoambito = "municipio"; 1139 } 1140 else if ($("#secciones").val() == -1) { 1141 var tipoambito = "distrito"; 1142 } 1143 else if ($("#mesas").val() == -1) { 1144 var tipoambito = "seccion"; 1145 } 1146 else { 1147 var tipoambito = "mesa"; 1148 } 1149 return tipoambito; 1150 } 1151 1152 //Función para calcular porcentajes 1153 function calcularporcentaje(num, total) { 1154 return new Intl.NumberFormat('es-ES', { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format((num / total) * 100); 1155 } 1156 1157 //Función que sirve para centrar una provincia en el mapa al seleccionarla 1158 function calcularbordespoligono(coordenadaspoligono) { 1159 let minX = Infinity; 1160 let maxX = -Infinity; 1161 let minY = Infinity; 1162 let maxY = -Infinity; 1163 //Las estructuras de coordenadas de las proincias son Multipolygon
1164 coordenadaspoligono.forEach(polygon => { 1165 polygon.forEach(ring => { 1166 ring.forEach(([x, y]) => { 1167 if (x < minX) minX = x; 1168 if (x > maxX) maxX = x; 1169 if (y < minY) minY = y; 1170 if (y > maxY) maxY = y; 1171 }); 1172 }); 1173 }); 1174 //console.log([minx,miny,maxx,maxy]); 1175 //minx=minx-20000; 1176 //miny=miny-100000; 1177 //maxx=maxx+20000; 1178 //maxy=maxy+50000; 1179 //console.log([minx,miny,maxx,maxy]); 1180 return [minX, minY, maxX, maxY]; 1181 } 1182 1183 function comprobarformulario() { 1184 $('#tconvocatoria').prop('disabled', false); 1185 $('#fconvocatoria').prop('disabled', false); 1186 $('#provincia').prop('disabled', false); 1187 $('#municipios').prop('disabled', false); 1188 $('#distritos').prop('disabled', false); 1189 $('#secciones').prop('disabled', false); 1190 $('#mesas').prop('disabled', false); 1191 $('#partidos').prop('disabled', false); 1192 $('#rausentes').prop('disabled', false); 1193 1194 if ($('#celectos').is(':checked')) { 1195 $('#provincia').prop('disabled', true); 1196 $('#municipios').prop('disabled', true).val(-1); 1197 $('#distritos').prop('disabled', true).val(-1); 1198 //$('#partidos').prop('disabled', true).val(-1); 1199 $('#rausentes').prop('disabled', true).prop('checked', false); 1200 } 1201 1202 if ($('#tconvocatoria').val() == -1 || $('#fconvocatoria').val() == -1) { 1203 $('#provincia').prop('disabled', true); 1204 $('#municipios').prop('disabled', true).val(-1); 1205 $('#distritos').prop('disabled', true).val(-1); 1206 $('#secciones').prop('disabled', true).val(-1); 1207 $('#mesas').prop('disabled', true).val(-1); 1208 $('#partidos').prop('disabled', true).val(-1); 1209 $('#rausentes').prop('disabled', true).prop('checked', false); 1210 $('#celectos').prop('checked', false).prop('disabled', true); 1211 1212 } 1213 else if ($('#provincia').val() == -1) { 1214 $('#municipios').prop('disabled', true).val(-1); 1215 $('#distritos').prop('disabled', true).val(-1); 1216 $('#secciones').prop('disabled', true).val(-1); 1217 $('#mesas').prop('disabled', true).val(-1); 1218 } 1219 else if ($('#municipios').val() == -1) { 1220 $('#distritos').prop('disabled', true).val(-1); 1221 $('#secciones').prop('disabled', true).val(-1); 1222 $('#mesas').prop('disabled', true).val(-1); 1223 } 1224 else if ($('#distritos').val() == -1) { 1225 $('#secciones').prop('disabled', true).val(-1); 1226 $('#mesas').prop('disabled', true).val(-1); 1227 } 1228 else if ($('#secciones').val() == -1) { 1229 $('#mesas').prop('disabled', true).val(-1); 1230 } 1231 1232 if ($('#tconvocatoria').val() == -1 || $('#tconvocatoria').val() == 1) { 1233 $('#partidos').prop('disabled', true); 1234 } 1235 1236 if ($('#tconvocatoria').val() == 1 || $('#provincia').val() > 0) { 1237 $('#celectos').prop('disabled', true).prop('checked', false); 1238 } 1239 else { 1240 $('#celectos').prop('disabled', false); 1241 } 1242 1243 if ($('#partidos').val() > 0) { 1244 $('#distritos').prop('disabled', true).val(-1); 1245 $('#secciones').prop('disabled', true).val(-1); 1246 $('#mesas').prop('disabled', true).val(-1); 1247 } 1248 1249 if ($('#municipio').val() > 0) { 1250 $('#rausentes').prop('disabled', true).prop('checked', false); 1251 } 1252 1253 if ($('#rausentes').is(':checked')) { 1254 $('#municipios').prop('disabled', true).val(-1); 1255 $('#distritos').prop('disabled', true).val(-1); 1256 $('#secciones').prop('disabled', true).val(-1); 1257 $('#mesas').prop('disabled', true).val(-1); 1258 $('#partidos').prop('disabled', true); 1259 $('#celectos').prop('disabled', true); 1260 } 1261 1262 if ($('#distritos').val() > 0) { 1263 $('#partidos').prop('disabled', true); 1264 } 1265 1266 } 1267 1268 function calcularlimitesmapa(layerprov) { 1269 var minx = 10000000; 1270 var maxx = -10000000; 1271 var miny = 10000000; 1272 var maxy = -10000000; 1273 layerprov.getFeatures().forEach(function (feature) { 1274 var coordenadaspoligono = feature.getGeometry(); 1275 //console.log(coordenadaspoligono); 1276 coordenadaspoligono.coordinates[0][0].forEach(function (coordenada) { 1277 if (coordenada[0] < minx) { 1278 minx = coordenada[0]; 1279 } 1280 if (coordenada[0] > maxx) { 1281 maxx = coordenada[0]; 1282 } 1283 if (coordenada[1] < miny) { 1284 miny = coordenada[1]; 1285 } 1286 if (coordenada[1] > maxy) { 1287 maxy = coordenada[1]; 1288 } 1289 }); 1290 }); 1291 return [minx, miny, maxx, maxy]; 1292 } 1293 1294 function resetmap(mapajs, mapcenter, layerprov, layermun, styleprov, stylemunoff) { 1295 mapajs.setZoom(3).setCenter(mapcenter);
1296 layerprov.getFeatures().forEach(function (feature) { 1297 feature.setStyle(styleprov); 1298 }); 1299 layermun.getFeatures().forEach(function (feature) { 1300 feature.setStyle(stylemunoff); 1301 }); 1302 var mapbox = calcularlimitesmapa(layerprov); 1303 //console.log(mapbox); 1304 mapajs.setBbox(mapbox); 1305 } 1306 1307 //Esta funcion mantiene las proporciones al redimensionar 1308 function resize_elements() { 1309 $('#tablaresultados').width($('#tablaresultados_wrapper').width()); 1310 /*var regularheight=$('#mapea').height(); 1311 1312 if($('#sidebar_mapand').outerHeight()>regularheight) 1313 { 1314 $('#mapea').height($('#sidebar_mapand').outerHeight()); 1315 $('#mapea canvas').height($('#sidebar_mapand').outerHeight()); 1316 }*/ 1317 1318 //$('#separador_mapand .graficas').height($('#informacion').outerHeight()); 1319 } 1320 1321}(jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.