-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom.js
3539 lines (3372 loc) · 115 KB
/
custom.js
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
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// FOR DEBUG PURPOSE
//window.onerror = function (msg, url, line) {
// alert("An error is detected, try to reload the page or make a synchronization with WG (Message : " + msg +"url : " + url + "Line number : " + line + ")" );
// };
// WAITING until site was ready.
var preloader = $('#preloader');
//$('#preloaderPage').show();
// GLOBAL VARIABLE
var languages = ["afrikaans", "arabic", "basque", "belarusian", "bulgarian", "catalan", "croatian", "czech", "danish", "dutch", "english", "esperanto", "estonian", "faroese", "finnish", "french", "galician", "german", "greek", "hebrew", "hindi", "hungarian", "icelandic", "indonesian", "irish", "italian", "japanese", "khmer", "korean", "latvian", "lithuanian", "luxembourgish", "malay", "mongolian", "norwegian", "persian", "polish", "portuguese", "romanian", "russian", "serbian", "slovak", "slovene", "spanish", "swedish", "turkish", "ukrainian", "vietnamese", "wargaming"];
//var listclanunknow = new Array;
var clanTable;
var oTable;
var seasonTable;
var maptobuildprogress = 0;
var flagdir = "tools/flags/"
var cartecomplete;
var clanselected = "";
var fullscreen = false;
var layers;
var vector;
var varlayersource;
var chargedgeojson;
// Creating datatable, they are charged after the loading data from php, in order season, clan, province.
showLogSeason();
showLogClan();
showLogTab9('#tabs-9tab');
// Prepare BUTTON CONTROL on map : image / kml
// -------------------------------------------
// Button image : Blob/canvas export dont work due to CORS problems, just an alert....
window.app = {};
var app = window.app;
app.pdf = function () {
var button = document.createElement('button');
button.innerHTML = '<img src="tools/images/pdf_icon.png" />';
button.title = 'Save Image : plz do right click on map';
var fonctionexport = function () {
alert('Right click on map and make save image.');
};
button.addEventListener('click', fonctionexport, false);
var element = document.createElement('div');
element.className = 'pdfbutton ol-control';
element.appendChild(button);
ol.control.Control.call(this, {
element : element
});
};
// BUTTON EXPORT KML : prepare data to format KML, then blob it in a file for download.
app.google = function () {
var button = document.createElement('button');
button.innerHTML = '<img src="tools/images/Google_Maps_Icon.png" />';
button.title = 'Export format Google Earth';
var fonctionexportgoogle = function () {
var kmlFormat = new ol.format.KML();
var kmllayer = new String('');
var layers = map.getLayers();
var features = new Array;
layers.forEach(function (layer) {
if (layer.get('idbase') == 'TileWMS') {
// on ne fait rien
}
if (layer.get('idbase') == 'wargaming' || layer.get('idbase') == 'batailles' || layer.get('idbase') == 'texte') {
var varlayersource = layer.getSource();
features = $.merge(features, varlayersource.getFeatures());
}
if (layer.get('idbase') == 'icone' || layer.get('idbase') == 'texte2' || layer.get('idbase') == 'texte3') {
var varlayersource = layer.getSource();
features = $.merge(features, varlayersource.getFeatures());
}
});
kmllayer = kmlFormat.writeFeatures(features, {
featureProjection : 'EPSG:3857'
});
xmlDoc = $.parseXML(kmllayer);
xml = $(xmlDoc);
xml.find("scale").each(function () {
var $this = $(this);
$this.prop({
textContent : 1
});
});
xml.find("Icon").each(function () {
var $this = $(this);
$this.children().each(function () {
var $this = $(this);
if ($this.prop("nodeName") != 'href') {
$this.remove();
}
});
});
var xmlString = (new XMLSerializer()).serializeToString(xmlDoc);
var blob = new Blob([xmlString], {
type : "text/xml;charset=utf-8"
});
saveAs(blob, "WOTclanwar.kml");
};
button.addEventListener('click', fonctionexportgoogle, false);
var element = document.createElement('div');
element.className = 'googlebutton ol-control';
element.appendChild(button);
ol.control.Control.call(this, {
element : element
});
};
ol.inherits(app.pdf, ol.control.Control);
ol.inherits(app.google, ol.control.Control);
// OPEN LAYER MAP PREPARE
var map = new ol.Map({
RendererType : 'canvas',
controls : ol.control.defaults().extend([
new app.pdf(),
new app.google(),
varFullscreen = new ol.control.FullScreen()
]),
layers : [
new ol.layer.Tile({
idbase : "TileWMS",
title : 'Global Imagery',
source : new ol.source.TileWMS({
url : 'http://demo.opengeo.org/geoserver/wms',
params : {
LAYERS : 'ne:NE1_HR_LC_SR_W_DR',
VERSION : '1.1.1'
}
})
})
],
target : 'map',
view :
new ol.View({
center : [0, 0],
zoom : 3,
minZoom : 3,
maxZoom : 8
})
});
// LOADING Data
var seasondata;
var annuaireclan;
var listesaveresult;
var listturnbattles;
var dernieresave = 'extraction.json';
// prepare database from Loki
db_data = new loki('data.json', { env: 'BROWSER'})
db_map = new loki('map.json', { env: 'BROWSER'});
db_save = new loki('save.json', { env: 'BROWSER'});
// var datedernieresave;
// affichageclanproperty("SEASONDATA", " ", true);
// affichageclanproperty("CLANLIST", " ", true);
// affichageclanproperty("ALLSAVE", " ", true);
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=SEASONLIST";
$.getJSON(urlwebapp, function(data) {
seasondata = data;
if (!db_data.getCollection("SEASONLIST")) {
var seasonColl = db_data.addCollection('SEASONLIST', { unique: ['season_id']});
var arrseasondata = Object.keys(seasondata).map(function(k) { return seasondata[k] });
seasonColl.insert(arrseasondata);
} else {
var seasonColl = db_data.getCollection('SEASONLIST');
};
loadLogSeason();
});
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=CLANLIST";
$.getJSON(urlwebapp, function(data) {
annuaireclan = data;
if (!db_data.getCollection("CLANLIST")) {
var clanColl = db_data.addCollection('CLANLIST', { unique: ['id']});
var arrannuaireclan = Object.keys(annuaireclan).map(function(k) { return annuaireclan[k] });
clanColl.insert(arrannuaireclan);
} else {
var clanColl = db_data.getCollection('CLANLIST');
};
loadLogClan();
});
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=ALLSAVE";
$.getJSON(urlwebapp, function(data) {
listesaveresult = data;
if (!db_data.getCollection("ALLSAVE")) {
var saveColl = db_data.addCollection('ALLSAVE', { unique: ['fichier']});
saveColl.insert(listesaveresult);
} else {
var saveColl = db_data.getCollection('ALLSAVE');
};
chargerlalistesave();
//chargerlasave('extraction.json');
});
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=LOADSAVE&save="+ "extraction.json";
$.getJSON(urlwebapp, function(data) {
var listeinfosColl = db_save.addCollection("extraction.json");
listeinfosColl.insert(data);
listeinfos = listeinfosColl.chain( ).data()[0];
layers = map.getLayers().getArray();
vector = getLayerwarg(layers, "wargaming");
chargedgeojson = listeinfos['season_id'];
map.removeLayer(vector);
var masource = new ol.source.Vector({
format: new ol.format.GeoJSON()
});
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=MAP&seasonid=" + chargedgeojson;
$.getJSON(urlwebapp, function(data) {
var listemapColl = db_map.addCollection(chargedgeojson);
listemapColl.insert(data);
var mamap = listemapColl.chain( ).data()[0];
datastring = JSON.stringify(mamap);
var geojsonFormat = new ol.format.GeoJSON();
var features = geojsonFormat.readFeatures(datastring,
{featureProjection: 'EPSG:3857'});
masource.addFeatures(features);
cartecomplete = new ol.layer.Vector({
idbase : "wargaming",
source : masource
});
map.addLayer(cartecomplete);
layers = map.getLayers().getArray();
vector = getLayerwarg(layers, "wargaming");
varlayersource = vector.getSource();
ModeAffichage("Clan");
chargerlalog();
})
})
// affichageclanproperty("NAMELASTSAVE", " ", true);
// affichageclanproperty("DATELASTSAVE", " ", true);
$(document).ajaxError(function (event, xhr, settings) {
// if the HOST limit the cpu or error on page request
alert("my HOST refuse the REQUEST due to limit, reload plz (message from server =" + xhr.status + ")")
//throw new Error(xhr.responseText)
});
/* $(document).ajaxSuccess(function (event, xhr, settings) {
if (settings.data.includes("SEASONDATA")) {
seasondata = JSON.parse(xhr.responseText);
loadLogSeason();
}
if (settings.data.includes("CLANLIST")) {
annuaireclan = JSON.parse(xhr.responseText);
loadLogClan();
}
if (settings.data.includes("ALLSAVE")) {
listesaveresult = JSON.parse(xhr.responseText);
if ($("#choixSave").val() === null) {
$("#choixSave").val('extraction.json').change();
chargerlasave('extraction.json');
}
//ordered desc by php
chargerlalistesave();
}
if (settings.data.includes("NAMELASTSAVE")) {
dernieresavestr = $.extend( true, {}, xhr);
dernieresave = dernieresavestr.responseText;
// On page load, we use the most recent save.
// does not work, push to ajax stop with condition...
}
if (settings.data.includes("DATELASTSAVE")) {
datedernieresavestr = $.extend( true, {}, xhr);
datedernieresave = datedernieresavestr.responseText;
}
if (settings.data.includes("BATTLETURNINFO")) {
listturnbattles = JSON.parse(xhr.responseText);;
}
}); */
// when all AJAX are stopped or started.
$(document).ajaxStop(function () {
// Creating datatable, they are charged after the loading data from php
// season and clan are loaded at start only, province is loaded when a save is loaded only.
// really poor code , maybe better to do
// due to ajax async, i can try to put lastsave while select save was empty, so the select is void on first load of page
//$('#preloaderPage').hide();
});
/* $(document).ajaxStart(function () {
$('#preloaderPage').show();
}) */;
// ----------------------EVENT ------------------------>>
// change save selection
$("#choixSave").change(function () {
chargerlasave($(this).val());
})
// click et double click sur la carte
var selectEuropa = new ol.style.Style({
stroke : new ol.style.Stroke({
color : '#ff0000',
width : 6
}),
zIndex : 1
});
// mouse move sur la carte
var selectEuropa2 = new ol.style.Style({
stroke : new ol.style.Stroke({
color : '#ff0000',
width : 2
}),
zIndex : 1
});
// create trigger for map interaction on pointer and select (pointer is not activated), select is used to change style of selected province.
var selectInteraction = new ol.interaction.Select({
layers : function (layer) {
return layer.get('idbase') == 'wargaming';
}
});
var mouseInteraction = new ol.interaction.Pointer({
layers : function (layer) {
return layer.get('idbase') == 'wargaming';
}
});
map.getInteractions().extend([selectInteraction]);
// Overlay prepare need to be used when MAP is fullscreen. Not used yet but to finish
var featureOverlay = new ol.layer.Vector({
map : map,
source : new ol.source.Vector({
useSpatialIndex : false // optional, might improve performance
}),
style : selectEuropa2,
updateWhileAnimating : true, // optional, for instant visual feedback
updateWhileInteracting : true // optional, for instant visual feedback
});
// click on map
var keyclik = map.on('click', function (evt) {
$("html").addClass("wait");
setTimeout(function () {
var pixel = evt.pixel;
var provcoord = evt.coordinate;
displayFeature(pixel, provcoord);
// if is not fullscreen
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement && !document.msFullscreenElement) {
$('#provinceInfo').modal('show');
$("html").removeClass("wait");
} else {
// il faut passer en mode overlay pour afficher la fenetre
var popup = new ol.Overlay({
element : document.getElementById('provinceInfo')
});
popup.setPosition(provcoord);
map.addOverlay(popup);
$('#provinceInfo').modal('show');
$("html").removeClass("wait");
};
}, 100);
});
map.getView().on('propertychange', function (e) {
// when the view of map change , for exemple change of zoom level
// we need to compute the image scale
switch (e.key) {
case 'resolution':
var layers = map.getLayers().getArray();
var vector1 = getLayerwarg(layers, "icone");
var vector2 = getLayerwarg(layers, "tournoi");
var vector3 = getLayerwarg(layers, "encheres");
var vector = [vector1, vector2, vector3];
$.each(vector, function (index, vector) {
if (vector) {
var mesfeatures = vector.getSource().getFeatures();
var filtrefeatures = $.grep(mesfeatures, function (n, i) {
return (n.getProperties().ceciestunicone == true);
});
$.each(filtrefeatures, function (index, province) {
var scale = getScaleZoom();
province.getStyle().getImage().setScale(scale);
});
};
});
break;
}
});
// button Fullscreen linked to the fullscreen function on map
$("#inputFullscreen").click(function () {
$('.ol-full-screen-false').click();
});
// button resync Clan
// $("#clanunknow").click(function () {
// setTimeout(function () {
// $('#preloadersync').show();
// affichageclanproperty("REFRESHCLANONSAVE", JSON.stringify(listclanunknow), false);
// affichageclanproperty("CLANLIST", " ", false);
// $('#preloadersync').hide();
// chargerlasave($("#choixSave").val());
// }, 100);
// });
// button sync/ reload to reload last save, or build a new save.
// the choice depend of timing (no build if last has less than 5 min or next automatic save scheduled in 5 min)
$("#reactualisation").click(function () {
$("#choixSave").val('extraction.json').change();
});
// clik on MAnager Filter button => new window to show
$(function () {
$("#Manage_filters").click(function () {
$('#filterlist').modal('show')
});
});
// ---------------------END -EVENT ------------------------>>
// ----------------------FUNCTIONS ------------------------>>
function chargerlalistesave() {
$.each(listesaveresult, function (save) {
$('#choixSave')
.append($("<option></option>")
.attr("value", listesaveresult[save].fichier)
.text(listesaveresult[save].dateshow));
});
};
function chargerlasave(save) {
// when page is loaded this function was called with parameter lastsave, unless this method was called
// when a new date is selected by user.
// until LOAD is not finished we show the preloader
setTimeout(function () {
if (save == dernieresave) {
$('#ModeAffichage option[value="Batailles"]').removeAttr('disabled');
$('#ModeAffichage option[value="Batailles2"]').removeAttr('disabled');
} else {
if ($('#ModeAffichage').val() == "Batailles" || $('#ModeAffichage').val() == "Batailles2") {
$('#ModeAffichage').val("Clan");
};
$('#ModeAffichage option[value="Batailles"]').attr("disabled", "disabled");
$('#ModeAffichage option[value="Batailles2"]').attr("disabled", "disabled");
}
if (save) {
if (!db_save.getCollection(save)) {
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=LOADSAVE&save="+ save;
$.getJSON(urlwebapp, function(data) {
var listeinfosColl = db_save.addCollection(save);
listeinfosColl.insert(data);
listeinfos = listeinfosColl.chain( ).data()[0];
chargerlasave2(listeinfos);
})
}
else {
listeinfosColl = db_save.getCollection(save);
listeinfos = listeinfosColl.chain( ).data()[0];
chargerlasave2(listeinfos);
};
}
console.log('fin de chargerlasave', new Date());
}, 100);
};
function chargerlasave2(listeinfos) {
layers = map.getLayers().getArray();
vector = getLayerwarg(layers, "wargaming");
// optimization : reload geojson map only if change
if (chargedgeojson != listeinfos['season_id']) {
chargedgeojson = listeinfos['season_id'];
map.removeLayer(vector);
var masource = new ol.source.Vector({
format: new ol.format.GeoJSON()
});
if (!db_map.getCollection(chargedgeojson)) {
var urlwebapp = "https://script.google.com/macros/s/AKfycbxJmYTHBXM-_urMpk94iXv06jgCOjhGi7mljc39GYfhIZzq9Yo/exec?typeSelection=MAP&seasonid=" + chargedgeojson;
$.getJSON(urlwebapp, function(data) {
var listemapColl = db_map.addCollection(chargedgeojson);
listemapColl.insert(data);
var mamap = listemapColl.chain( ).data()[0];
datastring = JSON.stringify(mamap);
var geojsonFormat = new ol.format.GeoJSON();
var features = geojsonFormat.readFeatures(datastring,
{featureProjection: 'EPSG:3857'});
masource.addFeatures(features);
chargerlasave3(masource);
})
}
else {
listemapColl = db_map.getCollection(chargedgeojson);
var mamap = listemapColl.chain( ).data()[0];
datastring = JSON.stringify(mamap);
var geojsonFormat = new ol.format.GeoJSON();
var features = geojsonFormat.readFeatures(datastring,
{featureProjection: 'EPSG:3857'});
masource.addFeatures(features);
chargerlasave3(masource);
};
} else {
vector = getLayerwarg(layers, "wargaming");
varlayersource = vector.getSource();
chargerlalog();
console.log('fin de charger log sans changement de carte', new Date());
//Filterprovinceonmap();
console.log('debut de filteron province sans changement de carte', new Date());
var modAff = $('#ModeAffichage').val();
ModeAffichage(modAff);
console.log('fin de Mode affichage', new Date());
};
};
function chargerlasave3(masource) {
cartecomplete = new ol.layer.Vector({
idbase : "wargaming",
source : masource
});
map.addLayer(cartecomplete);
layers = map.getLayers().getArray();
vector = getLayerwarg(layers, "wargaming");
varlayersource = vector.getSource();
var listenerchangelayer = varlayersource.once('change', function (e) {
if (varlayersource.getState() === 'ready') {
// carte chargée
map.unByKey(listenerchangelayer);
chargerlalog();
Filterprovinceonmap();
var modAff = $('#ModeAffichage').val();
ModeAffichage(modAff);
try {
vector2 = getLayerwarg(layers, "TileWMS");
extentWARN = varlayersource.getExtent();
center2Layers = ol.extent.getCenter(extentWARN);
//alert(center2Layers);
} catch (e) {
alert(e.message);
}
map.getView().setCenter(center2Layers);
};
});
varlayersource.changed();
}
function ModeAffichage(mode) {
// this function analyse which display mode was choosen ,then
// call the function needed.
setTimeout(function () {
//preloader.show();
switch (mode) {
case 'Clan':
effacericone();
effacerbatailles();
affichageclancolor();
afficherlesicones();
break;
case 'Front':
effacericone();
effacerbatailles();
affichagefront();
break;
case 'Horaire':
effacericone();
effacerbatailles();
affichagehoraires();
break;
case 'Revenu':
effacericone();
effacerbatailles();
affichagerevenu();
break;
case 'Infrastructure':
effacericone();
effacerbatailles();
affichagelevel();
break;
case 'Batailles':
effacericone();
effacerbatailles();
affichageclancolor();
affichagebatailles();
break;
case 'Langage':
effacericone();
effacerbatailles();
affichagelangagecolor();
break;
case 'Province':
effacericone();
effacerbatailles();
affichageProvince();
break;
case 'ClanELO6':
effacericone();
effacerbatailles();
affichageclanELO('elo_rating_6');
break;
case 'ClanELO8':
effacericone();
effacerbatailles();
affichageclanELO('elo_rating_8');
break;
case 'ClanELO10':
effacericone();
effacerbatailles();
affichageclanELO('elo_rating_10');
break;
case 'ClanELOF':
effacericone();
effacerbatailles();
affichageclanELO('fine_level');
break;
case 'Batailles2':
effacericone();
effacerbatailles();
affichageclanbattles();
break;
case 'accepts_join_requests':
effacericone();
effacerbatailles();
affichageaccepts_join_requests();
break;
case 'battles':
effacericone();
effacerbatailles();
affichagestat('battles');
break;
case 'battles_6_level':
effacericone();
effacerbatailles();
affichagestat('battles_6_level');
break;
case 'battles_8_level':
effacericone();
effacerbatailles();
affichagestat('battles_8_level');
break;
case 'battles_10_level':
effacericone();
effacerbatailles();
affichagestat('battles_10_level');
break;
case 'battles_6_percent':
effacericone();
effacerbatailles();
affichagestat('battles_6_percent');
break;
case 'battles_8_percent':
effacericone();
effacerbatailles();
affichagestat('battles_8_percent');
break;
case 'battles_10_percent':
effacericone();
effacerbatailles();
affichagestat('battles_10_percent');
break;
case 'members_count':
effacericone();
effacerbatailles();
affichagestat('members_count');
break;
case 'wins':
effacericone();
effacerbatailles();
affichagestat('wins');
break;
case 'winspercent':
effacericone();
effacerbatailles();
affichagestat('winspercent');
break;
case 'losses':
effacericone();
effacerbatailles();
affichagestat('losses');
break;
case 'lossespercent':
effacericone();
effacerbatailles();
affichagestat('lossespercent');
break;
case 'wins_6_level':
effacericone();
effacerbatailles();
affichagestat('wins_6_level');
break;
case 'wins_8_level':
effacericone();
effacerbatailles();
affichagestat('wins_8_level');
break;
case 'wins_10_level':
effacericone();
effacerbatailles();
affichagestat('wins_10_level');
break;
case 'provinces_count':
effacericone();
effacerbatailles();
affichagestat('provinces_count');
break;
default:
break;
};
//preloader.hide();
}, 100);
};
function affichageclancolor() {
// DISPLAY mode CLAN : search color choosen by clan and put it on the map
var vector = getLayerwarg(layers, "wargaming");
var varlayersource = vector.getSource();
var layerfeatures = new ol.source.Vector();
layerfeatures.addFeatures(varlayersource.getFeatures());
map.removeLayer(vector);
var features = layerfeatures.getFeatures()
var layer = new ol.layer.Vector({
idbase : "wargaming",
source : layerfeatures
});
map.addLayer(layer);
// recherche des infos
var stylecache = new Array;
// boucle sur les fronts //
var clancolor;
var color;
$.each(listeinfos['provinces'], function (index, province) {
var provinceatraiter = listeinfos['provinces'][index];
var couleurhexa = '#000000';
if (provinceatraiter['owner_clan_id'] !== null) {
var leclantrouve = provinceatraiter['owner_clan_id'];
if (annuaireclan[leclantrouve]) {
couleurhexa = annuaireclan[leclantrouve].color;
clancolor = hexToRgb1(couleurhexa);
color = [clancolor[0], clancolor[1], clancolor[2], 0.8];
} else {
couleurhexa = '#000000';
clancolor = hexToRgb1(couleurhexa);
color = [clancolor[0], clancolor[1], clancolor[2], 1];
}
} else {
couleurhexa = '#F8F8FF';
clancolor = hexToRgb1(couleurhexa);
color = [clancolor[0], clancolor[1], clancolor[2], 0.1];
}
if (!stylecache[couleurhexa]) {
stylecache[couleurhexa] = new ol.style.Style({
fill : new ol.style.Fill({
color : color
}),
stroke : new ol.style.Stroke({
color : '#FFFFFF',
width : 1
})
});
};
var result3 = $.grep(features, function (e) {
return e.getProperties().province_id == provinceatraiter['province_id']
});
if (result3[0]) {
result3[0].setStyle(stylecache[couleurhexa]);
};
});
};
function affichageclanELO(ELO) {
// old method for display ELO... maybe can be rewrite by the new method Stat more simple and efficient...
var vector = getLayerwarg(layers, "wargaming");
var varlayersource = vector.getSource();
var layerfeatures = new ol.source.Vector();
layerfeatures.addFeatures(varlayersource.getFeatures());
map.removeLayer(vector);
var features = layerfeatures.getFeatures()
var layer = new ol.layer.Vector({
idbase : "wargaming",
source : layerfeatures
});
map.addLayer(layer);
var layer2 = new ol.layer.Vector({
idbase : "texte2",
source : new ol.source.Vector({})
});
map.addLayer(layer2);
var nouvellesource = layer2.getSource();
var stylecache = new Array;
var styleELO = new Array;
var maxELO6 = 0;
var maxELO8 = 0;
var maxELO10 = 0;
var maxELOF = 0;
var minELO6 = 999999999;
var minELO8 = 999999999;
var minELO10 = 999999999;
var minELOF = 999999999;
$.each(listeinfos['provinces'], function (index, province) {
if (listeinfos['provinces'][index]['owner_clan_id'] !== null && annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]) {
var valELO6 = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_6'];
var valELO8 = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_8'];
var valELO10 = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_10'];
var valELOF = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['fine_level'];
if (valELO6 > maxELO6) {
maxELO6 = valELO6;
};
if (valELO6 < minELO6) {
minELO6 = valELO6;
};
if (valELO8 > maxELO8) {
maxELO8 = valELO8;
};
if (valELO8 < minELO8) {
minELO8 = valELO8;
};
if (valELO10 > maxELO10) {
maxELO10 = valELO10;
};
if (valELO10 < minELO10) {
minELO10 = valELO10;
};
if (valELOF > maxELOF) {
maxELOF = valELOF;
};
if (valELOF < minELOF) {
minELOF = valELOF;
};
};
});
var color1 = [255, 255, 255];
var color2 = [0, 125, 0];
var nbgradient = 20;
var colorlist = generateGradient(color1, color2, nbgradient);
var clancolor;
var color;
$.each(listeinfos['provinces'], function (index, province) {
var provinceatraiter = listeinfos['provinces'][index];
var couleurhexa = '#000000';
if (provinceatraiter['owner_clan_id'] !== null) {
var leclantrouve = provinceatraiter['owner_clan_id'];
if (annuaireclan[leclantrouve]) {
ponderation = 0;
var elovalue = 0;
switch (ELO) {
case 'elo_rating_6':
elovalue = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_6']
ponderation = Math.ceil((elovalue - minELO6) * nbgradient / (maxELO6 - minELO6));
break;
case 'elo_rating_8':
elovalue = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_8']
ponderation = Math.ceil((elovalue - minELO8) * nbgradient / (maxELO8 - minELO8));
break;
case 'elo_rating_10':
elovalue = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['elo_rating_10']
ponderation = Math.ceil((elovalue - minELO10) * nbgradient / (maxELO10 - minELO10));
break;
case 'fine_level':
elovalue = annuaireclan[listeinfos['provinces'][index]['owner_clan_id']]['fine_level']
ponderation = Math.ceil((elovalue - minELOF) * nbgradient / (maxELOF - minELOF));
break;
default:
elovalue = 0;
ponderation = 0;
break;
}
if (ponderation > 19) {
ponderation = 19;
};
} else {
elovalue = 0;
ponderation = 0;
}
} else {
elovalue = 0;
ponderation = 0;
}
if (isNaN(ponderation)) {
elovalue = 0;
ponderation = 0;
};
if (!stylecache[ponderation]) {
stylecache[ponderation] = new ol.style.Style({
fill : new ol.style.Fill({
color : [colorlist[ponderation][0], colorlist[ponderation][1], colorlist[ponderation][2], 1]
}),
stroke : new ol.style.Stroke({
color : '#FFFFFF',
width : 1
})
});
};
if (!styleELO[elovalue]) {
styleELO[elovalue] = new ol.style.Style({
text : new ol.style.Text({
text : elovalue.toString(),
fill : new ol.style.Fill({
color : '#000'
}),
stroke : new ol.style.Stroke({
color : '#fff'
})
})
});
};
var result3 = $.grep(features, function (e) {
return e.getProperties().province_id == provinceatraiter['province_id']
});
if (result3[0]) {
result3[0].setStyle(stylecache[ponderation]);
var geometry = result3[0].getGeometry();
var point = getCenterOf(geometry);
newFeature = new ol.Feature({
ceciestunicone : true,
geometry : new ol.geom.Point(point)
});
newFeature.setStyle(styleELO[elovalue]);
nouvellesource.addFeature(newFeature);
};
});
};
function affichageaccepts_join_requests() {
// DISPLAY clan recruit : green if accepted, black if not.
// get all province in a new layer, and delete old layer.
var vector = getLayerwarg(layers, "wargaming");
var varlayersource = vector.getSource();
var layerfeatures = new ol.source.Vector();
layerfeatures.addFeatures(varlayersource.getFeatures());
map.removeLayer(vector);
var features = layerfeatures.getFeatures()
var layer = new ol.layer.Vector({
idbase : "wargaming",
source : layerfeatures
});
map.addLayer(layer);
// new layer to put text (clan name)
var layer2 = new ol.layer.Vector({
idbase : "texte2",
source : new ol.source.Vector({})
});
map.addLayer(layer2);
var nouvellesource = layer2.getSource();
var styleclan = new Array;
styleaccept = new ol.style.Style({
fill : new ol.style.Fill({
color : [0, 125, 0, 1]
}),
stroke : new ol.style.Stroke({
color : '#FFFFFF',
width : 1
})
});
styleacceptno = new ol.style.Style({
fill : new ol.style.Fill({
color : [0, 0, 0, 1]
}),
stroke : new ol.style.Stroke({
color : '#FFFFFF',
width : 1
})
});
var accepts_join_requests;
var nomclan;
var emblem;
// each province on map is read, then mapped with the clan to get back "join request property".
$.each(listeinfos['provinces'], function (index, province) {
var provinceatraiter = listeinfos['provinces'][index];
var couleurhexa = '#000000';