-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtur1_vs_tur2.html
executable file
·959 lines (890 loc) · 44.9 KB
/
tur1_vs_tur2.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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="style/style.css" />
<link rel="stylesheet" href="assets/leaflet/leaflet.css" />
<link rel="stylesheet" href="assets/bootstrap-4.4.1-dist/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/bootstrap-select-1.13.9/dist/css/bootstrap-select.min.css">
<link rel="stylesheet" href="assets/jquery-ui-1.12.1/jquery-ui.css">
<link rel="stylesheet" href="assets/fontawesome-free-5.12.0-web/css/all.css">
<script src="assets/leaflet/leaflet.js"></script>
<script src="assets/Leaflet.VectorGrid.bundled.js"></script>
<script src="assets/leaflet-control-swipe.js"></script>
<script src="assets/d3/d3.min.js"></script>
<script src="assets/topojson-client.min.js"></script>
<script src="assets/jquery-3.4.1.min.js"></script>
<script src="assets/jquery-ui-1.12.1/jquery-ui.js"></script>
<script src="assets/popper.min.js"></script>
<script src="assets/bootstrap-4.4.1-dist/js/bootstrap.min.js"></script>
<script src="assets/bootstrap-select-1.13.9/dist/js/bootstrap-select.min.js"></script>
<script src="assets/Chart.bundle.min.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<strong><i class="fas fa-person-booth"></i> <a class="navbar-brand" href="#">Alegeri 2019 - Turul 1 vs. Turul 2</a></strong>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="#" data-toggle="modal" data-target="#despre_harta"><i class="fas fa-info-circle"></i> Despre</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-laptop-code"></i> Harta pas cu pas
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="part0.html">0 - Introducere</a>
<a class="dropdown-item" href="part1.html">1 - Mașina virtuală OSGeoLive</a>
<a class="dropdown-item" href="part2.html">2 - Datele de intrare</a>
<a class="dropdown-item" href="part3.html">3 - Realizarea hărții la nivel de secție de votare (poligon)</a>
<a class="dropdown-item" href="part4.html">4 - Se poate oare coborî mai jos de secție cu reprezentarea?</a>
<a class="dropdown-item" href="part5.html">5 - Hărțile clasice, la nivel de UAT și județ</a>
<a class="dropdown-item" href="part6.html">6 - Crearea hărții interactive</a>
<a class="dropdown-item" href="part7.html">7 - Utilizarea rezultatelor în OSGeoLive</a>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="download.html"><i class="fas fa-download"></i> Download</a>
</li>
<li class="nav-item dropdown active">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class="fas fa-toggle-on"></i> Hartă
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="turul1.html">Turul 1</a>
<a class="dropdown-item" href="index.html">Turul 2</a>
<a class="dropdown-item active" href="#">Turul 1 vs Turul 2</a>
</div>
</li>
</ul>
<p alt="Rezultat" title="Rezultat"><i class="fas fa-poll"></i> </p>
<form>
<div class="form-row align-items-center">
<div class="col-auto my-1">
<label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Rezultate</label>
<select class="custom-select mr-sm-2" id="rezultat">
<option value="1" selected>Secții</option>
<option value="2">UAT-uri</option>
<option value="3">Județe</option>
<option value="4">Doar zonele populate</option>
<option value="5">Fiecare procent (secție)</option>
<option value="6">Fiecare procent (UAT)</option>
<option value="7">Fiecare procent (județ)</option>
</select>
</div>
</div>
</form>
<p alt="Straturi de referință" title="Straturi de referință"><i class="fas fa-layer-group"></i> </p>
<form style="z-index: 2000;">
<select class="selectpicker" multiple data-live-search="false" data-none-selected-text="Nimic selectat" id="straturi">
<option value="1">Contur secții</option>
<option value="2">Contur UAT-uri</option>
<option value="3">Contur județe</option>
<option value="4">Localizare secții</option>
</select>
</form>
<p alt="Hartă fundal" title="Hartă fundal"><i class="fas fa-map"></i> </p>
<form>
<div class="form-row align-items-center">
<div class="col-auto my-1">
<label class="mr-sm-2 sr-only" for="inlineFormCustomSelect">Rezultate alegeri</label>
<select class="custom-select mr-sm-2" id="fundal">
<option value="1" selected>OSM Light</option>
<option value="2">OSM Normal</option>
<option value="3">Fără fundal</option>
</select>
</div>
</div>
</form>
</div>
</nav>
<div class="modal fade bd-example-modal-xl" id="despre_harta" tabindex="-1" role="dialog" aria-labelledby="myExtraLargeModalLabel" aria-hidden="true" style="z-index: 2001">
<div class="modal-dialog modal-xl modal-dialog-scrollable" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalScrollableTitle">Despre hartă</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Închide">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" role="alert">
<strong>Disclaimer:</strong> <a href="http://www.geo-spatial.org/" target="_blank">geo-spatial.org</a> nu a fost și nu va fi vreodată implicat în demersuri cu caracter politic. Acest material are un scop pur didactic și nu urmărește aprecierea în sens pozitv sau negativ a candidaților ce au participat la cele două tururi de alegeri prezidențiale din 2019.</a>
</div>
<p>Demersul de față și-a propus realizarea unor hărți interactive detaliate ale rezultatelor alegerilor prezidențiale din 2019 și <a href="part0.html" target="_blank">prezentarea pas cu pas</a> a modului de prelucrare și reprezentare a datelor. Provocarea principală a fost coborîrea la o scară mai fină decît clasicele reprezentări la nivel de județ și UAT. Nefiind experți în analize electorale, nu știm cît de relevante sînt respectivele reprezentări, bunul simț ne spune însă că o mai fină reprezentare a culorilor votului cetățenilor poate ajuta la înțelegerea mai bună a resorturilor ce au stat în spatele deciziilor de vot ale acestora.</p>
<div class="card-body">
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link active" id="judet-tab"
data-toggle="tab" href="#judet">Județ</a>
</li>
<li class="nav-item">
<a class="nav-link" id="uat-tab"
data-toggle="tab" href="#uat">UAT</a>
</li>
<li class="nav-item">
<a class="nav-link" id="sectie-tab"
data-toggle="tab" href="#sectie">Secție</a>
</li>
<li class="nav-item">
<a class="nav-link" id="sub-sectie-tab"
data-toggle="tab" href="#sub-sectie">Fiecare procent dintr-o secție</a>
</li>
</ul>
<div class="tab-content" id="myTabContent">
<div class="tab-pane show active" id="judet">
<img src="images/despre_01.png" class="img-fluid" alt="Exemplu rezultate la nivel de județ">
</div>
<div class="tab-pane" id="uat">
<img src="images/despre_02.png" class="img-fluid" alt="Exemplu rezultate la nivel de UAT">
</div>
<div class="tab-pane" id="sectie">
<img src="images/despre_03.png" class="img-fluid" alt="Exemplu rezultate la nivel de secție">
</div>
<div class="tab-pane" id="sub-sectie">
<img src="images/despre_04.png" class="img-fluid" alt="Exemplu rezultate la nivel de procent din secție">
</div>
</div>
</div>
<p>Aplicația include trei hărți interactive:</p>
<ul>
<li><a href="tur1.html" target="_blank">Rezultate turul 1 al alegerilor</a>;</li>
<li><a href="tur1.html" target="_blank">Rezultate turul 2 al alegerilor</a>;</li>
<li><a href="tur1.html" target="_blank">Rezultate comparative turul 1 vs turul 2 al alegerilor</a>.</li>
</ul>
<p>În cadrul fiecărei hărți pot fi vizualizate rezultatele la nivel de:</p>
<ul>
<li>Județ;</li>
<li>UAT;</li>
<li>Secție de votare (consultați <a href="part0.html" target="_blank">această pagină</a> pentru a vedea cum au fost delimitate secțiile folosind tehnica poligoanelor Voronoi);</li>
<li>Fiecare procent la nivel de secție;</li>
<li>Fiecare procent la nivel de UAT;</li>
<li>Fiecare procent la nivel de județ;</li>
<li>Fiecare vot.</li>
</ul>
<p>Aplicația mai permite ajustarea nivelului de opacitate a straturilor cu rezultate, suprapunerea unor straturi de referință și schimbarea hărții de fundal. Datele din aplicație pot fi <a href="download.html" target="_blank">descărcate în format GeoPackages</a>. De asemenea, codul sursă al aplicației poate fi descărcat liber de pe <a href="https://github.com/geospatialorg/alegeri2019" target="_blank">GitHub</a>. Harta are o serie de limitări de ordin tehnic, limitări pentru care există soluții dar aplicarea acestora ar depăși scopul acestui demers.</p>
<div class="alert alert-warning" role="alert">
<strong>Limitări tehnice:</strong>
<ul>
<li>Încărcarea inițială a hărții, mai ales a celei intitulată <code class="highlighter-rouge">Turul 1 vs Turul 2</code>, poate fi destul de lentă din cauza volumului mare de date ce se încarcă în aplicația client;</li>
<li>Afișarea rezultatelor nu funcționează atunci cînd sînt afișate pe hartă și straturile de referință de tip poligon (<code class="highlighter-rouge">Contur secție</code>, <code class="highlighter-rouge">Contur UAT</code> sau <code class="highlighter-rouge">Contur județe</code>).</li></a>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Închide</button>
</div>
</div>
</div>
</div>
<div style="" id="loadingDiv"><div class="loader">Încărcare...</div><p><center>Așteptați o clipă, încărcăm <strong>10.031.762</strong> de voturi (well, exagerăm puțin, 182.648 au fost declarate nule)...</center></p></div>
<div class="map" id="mapcon"></div>
<script type="text/javascript">
$(window).on('load', function(){
setTimeout(removeLoader, 2000);
});
function removeLoader(){
$( '#loadingDiv' ).fadeOut(500, function() {
$( '#loadingDiv' ).remove();
});
}
var graficRezultateTur1 = function(labels, data) {
var dataLength = labels ? labels.length : 0;
var backgroundColors = ['rgba(31, 120, 180, 1)',
'rgba(114, 155, 111, 1)',
'rgba(255, 127, 0, 1)',
'rgba(51, 160, 44, 1)',
'rgba(227, 26, 28, 1)',
'rgba(213, 180, 60, 1)',
'rgba(125, 139, 143, 1)',
'rgba(196, 60, 57, 1)',
'rgba(94, 204, 243, 1)',
'rgba(145, 82, 45, 1)',
'rgba(66, 153, 152, 1)',
'rgba(141, 90, 153, 1)',
'rgba(248, 53, 232, 1)',
'rgba(225, 89, 137, 1)'];
var colors = [];
for (var i = 0; i < dataLength; i++) {
colors.push(backgroundColors[i]);
};
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'nr. de voturi',
data: data,
backgroundColor: colors,
borderColor: colors,
borderWidth: 1
}]
},
options: {
animation: false,
scales: {
xAxes: [{
ticks: {
autoSkip: false,
fontSize: 11,
maxRotation: 90,
minRotation: 90
}
}],
yAxes: [{
ticks: {
fontSize: 10,
beginAtZero: true
}
}]
}
}
});
};
var graficRezultateTur2 = function(labels, data) {
var dataLength = labels ? labels.length : 0;
var backgroundColors = ['rgba(31, 120, 180, 0.9)',
'rgba(227, 26, 28, 0.9)'];
var colors = [];
for (var i = 0; i < dataLength; i++) {
colors.push(backgroundColors[i]);
};
var ctx = document.getElementById('myChart');
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: labels,
datasets: [{
label: 'nr. de voturi',
data: data,
backgroundColor: colors,
borderColor: colors,
borderWidth: 1
}]
},
options: {
animation: false,
scales: {
xAxes: [{
ticks: {
autoSkip: false,
fontSize: 11,
maxRotation: 90,
minRotation: 90
}
}],
yAxes: [{
ticks: {
fontSize: 10,
beginAtZero: true
}
}]
}
}
});
};
function titleCase(str) {
str = str.toLowerCase().split(' ');
for (var i = 0; i < str.length; i++) {
str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1);
}
return str.join(' ');
}
$(function(){
$('#slider').slider({
max: 1,
min: 0,
value: 0.5,
step: 0.1
});
});
var neighbors;
var getsections = {};
var geojson;
window.onload = function () {
var neighbors
function styleSectii(feature) {
return {
fillColor: getColorFill(feature.properties.castigator),
weight: 0.9,
opacity: 1,
color: getColor(feature.properties.castigator),
dashArray: '0.5',
fillOpacity: 1
};
}
function styleSectii2(feature) {
return {
fillColor: getColorFill2(feature.properties.castigator),
weight: 0.9,
opacity: 1,
color: getColor2(feature.properties.castigator),
dashArray: '0.5',
fillOpacity: 1
};
}
function styleContur(feature) {
return {
fillColor: '#ffffff',
opacity: 1,
weight: 1,
color: '#000000',
dashArray: '0.5',
fillOpacity: 0
};
}
var optiuniSectiiPunct = {
radius: 2,
fillColor: '#000000',
color: '#000000',
weight: 1,
opacity: 1,
fillOpacity: 1,
pane: 'sectii_punct'
};
function styleFiecareProcent(castigator) {
return {
fillColor: getColor(castigator),
weight: 0.9,
opacity: 1,
color: getColor(castigator),
dashArray: '0.5',
fillOpacity: 1,
fill: true
};
}
function styleFiecareProcentTur1(castigator) {
return {
fillColor: getColor2(castigator),
weight: 0.9,
opacity: 1,
color: getColor2(castigator),
dashArray: '0.5',
fillOpacity: 1,
fill: true
};
}
function getColor(d) {
return d == 1 ? '#1f78b4' :
d == 2 ? '#e31a1c':
'#33a02c';
}
function getColorFill(d) {
return d == 1 ? '#8dbbda' :
d == 2 ? '#f38b8b':
'#97d093';
}
function getColor2(d) {
return d == 1 ? '#1f78b4' :
d == 2 ? '#729b6f':
d == 3 ? '#ff7f00':
d == 4 ? '#33a02c':
d == 5 ? '#e31a1c':
d == 6 ? '#d5b43c':
d == 7 ? '#7d8b8f':
d == 8 ? '#c43c39':
d == 9 ? '#5eccf3':
d == 10 ? '#91522d':
d == 11 ? '#429998':
d == 12 ? '#8d5a99':
d == 13 ? '#f835e8':
d == 0 ? '#33a02c':
'#e15989';
}
function getColorFill2(d) {
return d == 1 ? '#8dbbda' :
d == 2 ? '#b7cdb6':
d == 3 ? '#ffc07a':
d == 4 ? '#97d093':
d == 5 ? '#f38b8b':
d == 6 ? '#ebda9a':
d == 7 ? '#bec5c7':
d == 8 ? '#e29d9b':
d == 9 ? '#ace5fa':
d == 10 ? '#c9a895':
d == 11 ? '#9fcccb':
d == 12 ? '#c7abcd':
d == 13 ? '#fd97f5':
d == 0 ? '#33a02c':
'#f1abc4';
}
var req = new XMLHttpRequest();
var url = 'data/data_tur2.topojson';
req.open('GET', url, true);
req.onreadystatechange = handler;
req.send();
topoob = {};
getsections = {};
responseText = req.responseText
var req2 = new XMLHttpRequest();
var url2 = 'data/data_tur1.topojson';
req2.open('GET', url2, true);
req2.onreadystatechange = handler;
req2.send();
topoob2 = {};
getsections2 = {};
responseText2 = req2.responseText
function parseTopoJSON(layer, style, onEachF, pane) {
topoob = JSON.parse(req.responseText)
neighbors = topojson.neighbors(topoob.objects[layer].geometries);
getsections = topojson.feature(topoob, topoob.objects[layer])
getsections.features = getsections.features.map(function(fm,i){
var ret = fm;
ret.indie = i;
return ret
});
content = L.geoJson(getsections, {style: style, onEachFeature: onEachF, pane: pane});
return content;
}
function parseTopoJSON2(layer, style, onEachF, pane) {
topoob2 = JSON.parse(req2.responseText)
neighbors2 = topojson.neighbors(topoob2.objects[layer].geometries);
getsections2 = topojson.feature(topoob2, topoob2.objects[layer])
getsections2.features = getsections2.features.map(function(fm,i){
var ret = fm;
ret.indie = i;
return ret
});
content = L.geoJson(getsections2, {style: style, onEachFeature: onEachF, pane: pane});
return content;
}
function handler(){
if(req.readyState === XMLHttpRequest.DONE && req2.readyState === XMLHttpRequest.DONE){
function hideShowLayers (visibleLayers) {
var layers = ['sectii_rez', 'sectii_rez1', 'uat_rez', 'uat_rez1', 'judete_rez', 'judete_rez1', 'pop_rez', 'pop_rez1', 'fiecare_procent_sectie', 'fiecare_procent_sectie1', 'fiecare_procent_uat', 'fiecare_procent_uat1', 'fiecare_procent_judete', 'fiecare_procent_judete1', 'fiecare_procent_judete', 'fiecare_procent_judete1'];
var layersLength = layers.length;
for (var i = 0; i < layersLength; i++) {
if (visibleLayers.indexOf(layers[i]) !== -1){
map.addLayer(eval(layers[i]));
}
else{
map.removeLayer(eval(layers[i]));
}
}
}
var layer = 'terrain';
var map = new L.Map('mapcon',
{
center: new L.LatLng(46, 26),
zoom: 7
});
map.createPane('sectii_rez');
map.createPane('uat_rez');
map.createPane('judete_rez');
map.createPane('pop_rez');
map.createPane('sectii_contur');
map.createPane('uat_contur');
map.createPane('judete_contur');
map.createPane('sectii_punct');
map.createPane('fiecare_procent_sectie');
map.createPane('fiecare_procent_uat');
map.createPane('fiecare_procent_judete');
var lightOSM = L.tileLayer('https://cartodb-basemaps-{s}.global.ssl.fastly.net/light_all/{z}/{x}/{y}.png', {
maxZoom: 18,
zIndex: 1,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
var normalOSM = L.tileLayer( 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: ['a','b','c']
});
var blankBasemap = L.tileLayer('');
map.addLayer(lightOSM, normalOSM, blankBasemap);
//Încărcare straturi din TopoJSON
sectii_rez = parseTopoJSON('sectii_voronoi_pv_tur2', styleSectii, onEachFeature, 'sectii_rez');
sectii_rez1 = parseTopoJSON2('sectii_voronoi_pv_tur1', styleSectii2, onEachFeature, 'swipePane');
uat_rez = parseTopoJSON('uat_pv_cumulat_tur2', styleSectii, onEachFeature, 'uat_rez');
uat_rez1 = parseTopoJSON2('uat_pv_cumulat_tur1', styleSectii2, onEachFeature, 'swipePane');
judete_rez = parseTopoJSON('judete_pv_cumulat_tur2', styleSectii, onEachFeature, 'judete_rez');
judete_rez1 = parseTopoJSON2('judete_pv_cumulat_tur1', styleSectii2, onEachFeature, 'swipePane');
pop_rez = parseTopoJSON('sectii_voronoi_pv_tur2_clip_pop', styleSectii, '', 'pop_rez');
pop_rez1 = parseTopoJSON2('sectii_voronoi_pv_tur1_clip_pop', styleSectii2, '', 'swipePane');
sectii_contur = parseTopoJSON('sectii_voronoi_pv_tur2', styleContur, '', 'sectii_contur');
uat_contur = parseTopoJSON('uat_pv_cumulat_tur2', styleContur, '', 'uat_contur');
judete_contur = parseTopoJSON('judete_pv_cumulat_tur2', styleContur, '', 'judete_contur');
//Încărcare secții punct
topoob = JSON.parse(req.responseText)
neighbors = topojson.neighbors(topoob.objects.sectii_punct_tur2.geometries);
getsections = topojson.feature(topoob, topoob.objects.sectii_punct_tur2)
getsections.features = getsections.features.map(function(fm,i){
var ret = fm;
ret.indie = i;
return ret
});
sectii_punct = L.geoJson(getsections, {pointToLayer: function (feature, latlng) {return L.circleMarker(latlng, optiuniSectiiPunct)}});
fiecare_procent_sectie = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_sectie_tur2@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
maxNativeZoom: 16,
minZoom: 11,
pane: 'fiecare_procent_sectie',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_sectie_tur2: properties => {
return styleFiecareProcent(properties.castigator)
}
}
});
fiecare_procent_sectie1 = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_sectie_tur1@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
maxNativeZoom: 16,
minZoom: 11,
pane: 'swipePane',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_sectie_tur1: properties => {
return styleFiecareProcentTur1(properties.castigator)
}
}
});
fiecare_procent_uat = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_uat_tur2@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
maxNativeZoom: 16,
minZoom: 10,
pane: 'fiecare_procent_uat',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_uat_tur2: properties => {
return styleFiecareProcent(properties.castigator)
}
}
});
fiecare_procent_uat1 = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_uat_tur1@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
maxNativeZoom: 16,
minZoom: 10,
pane: 'swipePane',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_uat_tur1: properties => {
return styleFiecareProcentTur1(properties.castigator)
}
}
});
fiecare_procent_judete = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_judete_tur2@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
pane: 'fiecare_procent_judete',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_judete_tur2: properties => {
return styleFiecareProcent(properties.castigator)
}
}
});
fiecare_procent_judete1 = L.vectorGrid.protobuf('http://localhost:8082/geoserver/gwc/service/tms/1.0.0/alegeri:fiecare_procent_judete_tur1@EPSG%3A3857@pbf/{z}/{x}/{-y}.pbf', {
rendererFactory: L.svg.tile,
pane: 'swipePane',
getFeatureId: function(f) {
return f.properties.id;
},
vectorTileLayerStyles: {
fiecare_procent_judete_tur1: properties => {
return styleFiecareProcentTur1(properties.castigator)
}
}
});
map.getPane('sectii_rez').style.zIndex = 1200;
map.getPane('uat_rez').style.zIndex = 1199;
map.getPane('judete_rez').style.zIndex = 1198;
map.getPane('pop_rez').style.zIndex = 1197;
map.getPane('fiecare_procent_sectie').style.zIndex = 1198;
map.getPane('fiecare_procent_uat').style.zIndex = 1199;
map.getPane('fiecare_procent_judete').style.zIndex = 1200;
map.getPane('sectii_contur').style.zIndex = 1523;
map.getPane('uat_contur').style.zIndex = 1524;
map.getPane('judete_contur').style.zIndex = 1525;
map.getPane('sectii_punct').style.zIndex = 1526;
map.getPane('swipePane').style.zIndex = 1500;
map.addLayer(sectii_rez);
map.addLayer(sectii_rez1);
var swipe = L.control.swipe();
swipe.addTo(map);
var legend = L.control({position: 'bottomleft'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'info legend'),
grades = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0],
labels = ['Klaus-Werner Iohannis', 'Theodor Paleologu', 'Ilie-Dan Barna', 'Hunor Kelemen', 'Vasilica-Viorica Dăncilă', 'Cătălin-Sorin Ivan', 'Ninel Peia', 'Sebastian-Constantin Popescu', 'John-Ion Banu', 'Mircea Diaconu', 'Bogdan-Dragos-Aureliu Marian Stanoevici', 'Ramona-Ioana Bruynseels', 'Viorel Cataramă', 'Alexandru Cumpănașu', 'Egalitate (turul 2)'];
for (var i = 0; i < grades.length; i++) {
div.innerHTML +=
'<i style="background:' + getColor2(grades[i]) + '"></i> ' +
labels[i] + '<br>';
}
return div;
};
legend.addTo(map);
function highlightFeature(e){
var layer = e.target;
if (e.target.options.pane == 'pop_rez')
layer.setStyle({
fillOpacity: .7
})
else{
layer.setStyle({
weight: 2,
color: '#ffffff',
dashArray: '',
fillOpacity: .7
})
}
if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) {
layer.bringToFront();
}
info.update(layer.feature.properties, e.target.options.pane);
}
function resetHighlight(e){
if (e.target.options.pane == 'sectii_rez')
sectii_rez.resetStyle(e.target);
if (e.target.options.pane == 'swipePane')
sectii_rez1.resetStyle(e.target);
if (e.target.options.pane == 'uat_rez')
uat_rez.resetStyle(e.target);
if (e.target.options.pane == 'judete_rez')
judete_rez.resetStyle(e.target);
if (e.target.options.pane == 'pop_rez')
pop_rez.resetStyle(e.target);
info.update(e.target.properties, e.target.options.pane);
$('#myChart').css('display', 'none');
$('#rezultate_info').css('display', 'none');
}
function zoomToFeature(e) {
map.fitBounds(e.target.getBounds());
}
function onEachFeature(feature, layer){
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight, click: zoomToFeature})
}
var info = L.control();
info.onAdd = function(map) {
this._div = L.DomUtil.create('div', 'info');
this.update();
return this._div;
}
info.update = function(props, strat){
if (props && props.g3){
var labels = ['Klaus-Werner Iohannis', 'Theodor Paleologu', 'Ilie-Dan Barna', 'Hunor Kelemen', 'Vasilica-Viorica Dăncilă', 'Cătălin-Sorin Ivan', 'Ninel Peia', 'Sebastian-Constantin Popescu', 'John-Ion Banu', 'Mircea Diaconu', 'Bogdan-Dragos-Aureliu Marian Stanoevici', 'Ramona-Ioana Bruynseels', 'Viorel Cataramă', 'Alexandru Cumpănașu'];
var data = [props.g1, props.g2, props.g3, props.g4, props.g5, props.g6, props.g7, props.g8, props.g9, props.g10, props.g11, props.g12, props.g13, props.g14];
}
if (props && !props.g3){
var labels = ['Klaus-Werner Iohannis', 'Vasilica-Viorica Dăncilă'];
var data = [props.g1, props.g2];
}
if (strat == 'sectii_rez'){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px'>" +
"<h4>Secții de votare</h4>" +
(props ? 'Localitate: ' + titleCase(props.localitate) + '</br>' : "") +
(props ? 'Județul: ' + titleCase(props.judet) + '</br>' : "") +
(props ? 'Număr secție (secții): ' + props.id_sectii + '</br>' : "") +
(props ? 'Klaus-Werner Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Vasilica-Viorica Dăncilă: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur2(labels, data);
}
if (strat == 'swipePane' && map.hasLayer(sectii_rez1)){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px;'>" +
"<h4>Secții de votare</h4>" +
(props ? 'Localitate: ' + titleCase(props.localitate) + '</br>' : "") +
(props ? 'Județul: ' + titleCase(props.judet) + '</br>' : "") +
(props ? 'Număr secție (secții): ' + props.id_sectii + '</br>' : "") +
(props ? 'Klaus-Werner Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Theodor Paleologu: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
(props ? 'Ilie-Dan Barna: ' + props.g3 + ' (' + props.g3p +' %)</br>' : "") +
(props ? 'Hunor Kelemen: ' + props.g4 + ' (' + props.g4p +' %)</br>' : "") +
(props ? 'Vasilica-Viorica Dăncilă: ' + props.g5 + ' (' + props.g5p +' %)</br>' : "") +
(props ? 'Cătălin-Sorin Ivan: ' + props.g6 + ' (' + props.g6p +' %)</br>' : "") +
(props ? 'Ninel Peia: ' + props.g7 + ' (' + props.g7p +' %)</br>' : "") +
(props ? 'Sebastian-Constantin Popescu: ' + props.g8 + ' (' + props.g8p +' %)</br>' : "") +
(props ? 'John-Ion Banu: ' + props.g9 + ' (' + props.g9p +' %)</br>' : "") +
(props ? 'Mircea Diaconu: ' + props.g10 + ' (' + props.g10p +' %)</br>' : "") +
(props ? 'Bogdan-Dragos-Aureliu Marian Stanoevici: ' + props.g11 + ' (' + props.g11p +' %)</br>' : "") +
(props ? 'Ramona-Ioana Bruynseels: ' + props.g12 + ' (' + props.g12p +' %)</br>' : "") +
(props ? 'Viorel Cataramă: ' + props.g13 + ' (' + props.g13p +' %)</br>' : "") +
(props ? 'Alexandru Cumpănașu: ' + props.g14 + ' (' + props.g14p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur1(labels, data);
}
if (strat == 'uat_rez'){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px;'>" +
"<h4>UAT-uri</h4>" +
(props ? 'Localitate: ' + titleCase(props.name) + '</br>' : "") +
(props ? 'Județul: ' + titleCase(props.county) + '</br>' : "") +
(props ? 'Voturi Klaus Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Voturi Viorica Dăncilă: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur2(labels, data);
}
if (strat == 'swipePane' && map.hasLayer(uat_rez1)){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px;'>" +
"<h4>Secții de votare</h4>" +
(props ? 'Localitate: ' + titleCase(props.name) + '</br>' : "") +
(props ? 'Județul: ' + titleCase(props.county) + '</br>' : "") +
(props ? 'Klaus-Werner Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Theodor Paleologu: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
(props ? 'Ilie-Dan Barna: ' + props.g3 + ' (' + props.g3p +' %)</br>' : "") +
(props ? 'Hunor Kelemen: ' + props.g4 + ' (' + props.g4p +' %)</br>' : "") +
(props ? 'Vasilica-Viorica Dăncilă: ' + props.g5 + ' (' + props.g5p +' %)</br>' : "") +
(props ? 'Cătălin-Sorin Ivan: ' + props.g6 + ' (' + props.g6p +' %)</br>' : "") +
(props ? 'Ninel Peia: ' + props.g7 + ' (' + props.g7p +' %)</br>' : "") +
(props ? 'Sebastian-Constantin Popescu: ' + props.g8 + ' (' + props.g8p +' %)</br>' : "") +
(props ? 'John-Ion Banu: ' + props.g9 + ' (' + props.g9p +' %)</br>' : "") +
(props ? 'Mircea Diaconu: ' + props.g10 + ' (' + props.g10p +' %)</br>' : "") +
(props ? 'Bogdan-Dragos-Aureliu Marian Stanoevici: ' + props.g11 + ' (' + props.g11p +' %)</br>' : "") +
(props ? 'Ramona-Ioana Bruynseels: ' + props.g12 + ' (' + props.g12p +' %)</br>' : "") +
(props ? 'Viorel Cataramă: ' + props.g13 + ' (' + props.g13p +' %)</br>' : "") +
(props ? 'Alexandru Cumpănașu: ' + props.g14 + ' (' + props.g14p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur1(labels, data);
}
if (strat == 'judete_rez'){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px;'>>" +
"<h4>Județe</h4>" +
(props ? 'Județul: ' + titleCase(props.county) + '</br>' : "") +
(props ? 'Voturi Klaus Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Voturi Viorica Dăncilă: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur2(labels, data);
}
if (strat == 'swipePane' && map.hasLayer(judete_rez1)){
this._div.innerHTML = "<div id='rezultate_info' style='width: 350px;'>" +
"<h4>Secții de votare</h4>" +
(props ? 'Județul: ' + titleCase(props.county) + '</br>' : "") +
(props ? 'Klaus-Werner Iohannis: ' + props.g1 + ' (' + props.g1p +' %)</br>' : "") +
(props ? 'Theodor Paleologu: ' + props.g2 + ' (' + props.g2p +' %)</br>' : "") +
(props ? 'Ilie-Dan Barna: ' + props.g3 + ' (' + props.g3p +' %)</br>' : "") +
(props ? 'Hunor Kelemen: ' + props.g4 + ' (' + props.g4p +' %)</br>' : "") +
(props ? 'Vasilica-Viorica Dăncilă: ' + props.g5 + ' (' + props.g5p +' %)</br>' : "") +
(props ? 'Cătălin-Sorin Ivan: ' + props.g6 + ' (' + props.g6p +' %)</br>' : "") +
(props ? 'Ninel Peia: ' + props.g7 + ' (' + props.g7p +' %)</br>' : "") +
(props ? 'Sebastian-Constantin Popescu: ' + props.g8 + ' (' + props.g8p +' %)</br>' : "") +
(props ? 'John-Ion Banu: ' + props.g9 + ' (' + props.g9p +' %)</br>' : "") +
(props ? 'Mircea Diaconu: ' + props.g10 + ' (' + props.g10p +' %)</br>' : "") +
(props ? 'Bogdan-Dragos-Aureliu Marian Stanoevici: ' + props.g11 + ' (' + props.g11p +' %)</br>' : "") +
(props ? 'Ramona-Ioana Bruynseels: ' + props.g12 + ' (' + props.g12p +' %)</br>' : "") +
(props ? 'Viorel Cataramă: ' + props.g13 + ' (' + props.g13p +' %)</br>' : "") +
(props ? 'Alexandru Cumpănașu: ' + props.g14 + ' (' + props.g14p +' %)</br>' : "") +
"<canvas id='myChart' width='10' height='10'></canvas>" +
"</div>";
graficRezultateTur1(labels, data);
}
if (strat == 'fiecare_vot' || strat == 'fiecare_procent_sectie' || strat == 'fiecare_procent_uat' || strat == 'fiecare_procent_judete' || strat == 'pop_rez'){
if (props && props.castigator == 1)
castigatorVot = 'Klaus Iohannis';
if (props && props.castigator == 2)
castigatorVot = 'Viorica Dăncilă';
if (props && props.castigator == 0)
castigatorVot = 'Egalitate';
this._div.innerHTML = "<div id='rezultate_info'>" +
"<h4>Vot individual</h4>" +
(props ? castigatorVot + '</br>' : "")
}
}
info.addTo(map);
$('#rezultat').change(function () {
if ($('#rezultat').val() == '1'){
hideShowLayers(['sectii_rez', 'sectii_rez1']);
}
if ($('#rezultat').val() == '2'){
hideShowLayers(['uat_rez', 'uat_rez1']);
}
if ($('#rezultat').val() == '3'){
hideShowLayers(['judete_rez', 'judete_rez1']);
}
if ($('#rezultat').val() == '4'){
hideShowLayers(['pop_rez', 'pop_rez1']);
}
if ($('#rezultat').val() == '5'){
zoomLevel = map.getZoom();
if (zoomLevel < 13)
map.setZoom(13);
hideShowLayers(['fiecare_procent_sectie', 'fiecare_procent_sectie1']);
}
if ($('#rezultat').val() == '6'){
zoomLevel = map.getZoom();
if (zoomLevel < 12)
map.setZoom(12);
hideShowLayers(['fiecare_procent_uat', 'fiecare_procent_uat1']);
}
if ($('#rezultat').val() == '7'){
hideShowLayers(['fiecare_procent_judete', 'fiecare_procent_judete1']);
}
});
$('select').on('changed.bs.select',
function(e, clickedIndex, newValue, oldValue) {
if (clickedIndex == '0' && newValue == true)
map.addLayer(sectii_contur);
if (clickedIndex == '0' && newValue == false)
map.removeLayer(sectii_contur);
if (clickedIndex == '1' && newValue == true)
map.addLayer(uat_contur);
if (clickedIndex == '1' && newValue == false)
map.removeLayer(uat_contur);
if (clickedIndex == '2' && newValue == true)
map.addLayer(judete_contur);
if (clickedIndex == '2' && newValue == false)
map.removeLayer(judete_contur);
if (clickedIndex == '3' && newValue == true)
map.addLayer(sectii_punct);
if (clickedIndex == '3' && newValue == false)
map.removeLayer(sectii_punct);
});
$('#slider').on('slidechange', function( event, ui ) {
sectii_rez.setStyle({fillOpacity: $('#slider').slider('value')});
uat_rez.setStyle({fillOpacity: $('#slider').slider('value')});
judete_rez.setStyle({fillOpacity: $('#slider').slider('value')});
pop_rez.setStyle({fillOpacity: $('#slider').slider('value')});
if ($('#rezultat').val() == '5'){
map.removeLayer(fiecare_procent_sectie);
map.addLayer(fiecare_procent_sectie);
}
if ($('#rezultat').val() == '6'){
map.removeLayer(fiecare_procent_uat);
map.addLayer(fiecare_procent_uat);
}
if ($('#rezultat').val() == '7'){
map.removeLayer(fiecare_procent_judete);
map.addLayer(fiecare_procent_judete);
}
});
$('#fundal').change(function () {
if ($('#fundal').val() == '1'){
map.addLayer(lightOSM);
map.removeLayer(normalOSM);
map.removeLayer(blankBasemap);
}
if ($('#fundal').val() == '2'){
map.addLayer(normalOSM);
map.removeLayer(lightOSM);
map.removeLayer(blankBasemap);
}
if ($('#fundal').val() == '3'){
map.addLayer(blankBasemap);
map.removeLayer(lightOSM);
map.removeLayer(normalOSM);
}
});
$('#rezultate_uat_info').css('display', 'none');
}
}
}
</script>
</body>
</html>