-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
711 lines (697 loc) · 25.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
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
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<title>Apiscore - Quel est votre environnement apicole ?</title>
<meta name="description" content="Evaluez votre environnement apicole">
<!-- scripts -->
<script src="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.3/proj4.js"></script>
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="assets/js/jquery.cookie.js"></script>
<script src="assets/js/chartjs-plugin-colorschemes.min.js"></script>
<script src='https://unpkg.com/@turf/turf/turf.min.js'></script>
<script src="https://riversun.github.io/jsframe/jsframe.js"></script>
<script src="https://cdn.jsdelivr.net/vue/latest/vue.min.js"></script>
<script src="https://unpkg.com/botui/build/botui.min.js"></script>
<script src="assets/js/botui_settings.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<!-- stylesheets -->
<link href="https://api.mapbox.com/mapbox-gl-js/v1.9.0/mapbox-gl.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="assets/css/styles.css">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/botui/build/botui.min.css">
<link rel="stylesheet" type="text/css" href="https://unpkg.com/botui/build/botui-theme-default.css">
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" rel="stylesheet" >
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
<style>
body { margin: 0; padding: 0; }
#map { position: absolute; top: 0; bottom: 0; width: 100%; }
</style>
<!-- Mail Chimp integration -->
<script id="mcjs">!function(c,h,i,m,p){m=c.createElement(h),p=c.getElementsByTagName(h)[0],m.async=1,m.src=i,p.parentNode.insertBefore(m,p)}(document,"script","https://chimpstatic.com/mcjs-connected/js/users/dd6851bcf491dd2d710030c75/6744a84fd5cace56fbf73bf8f.js");</script>
<!-- end of Mail Chimp integration -->
</head>
<body>
<!-- Exit Modal -->
<div class="modal fade " id="important-msg" tabindex="-1" role="dialog" aria-labelledby="important-msg-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
<h4 class="modal-title" id="important-msg-label">Message Title!</h4>
</div>
<div class="modal-body">
<p>Message text</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="dont-show-again">Don't Show Again</button>
</div>
</div>
</div>
</div>
<!-- end of exit modal -->
<div id="map"></div>
<nav id="menu"></nav>
<div class='map-overlay' id='legend'></div>
<div class="waiting"></div>
<div id="chat-circle" class="btn btn-raised" title="Question ? Suggestion ?">
<div id="chat-overlay"></div>
<i class="material-icons">contact_support</i>
</div>
<div id="graph-circle" class="btn btn-raised" title="Ouvrir le graphe de statistiques">
<i class="material-icons">leaderboard</i>
</div>
<div class="chat-box">
<div class="chat-box-header">
Question / Commentaire ?
<span class="chat-box-toggle"><i class="material-icons">close</i></span>
</div>
<div class="chat-box-body">
<div class="chat-box-overlay">
<div id="my-botui-app">
<bot-ui></bot-ui></div>
</div>
</div>
</div>
<script>
// Initiate animation on each ajax request
$body = $("body");
$(document).on({
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }
});
const jsFrame = new JSFrame();
function openModal() {
const modalFrame = jsFrame.create({
title: 'Bienvenue !',
left: 0, top: 0, width: window.innerWidth * 0.8, height: window.innerHeight * 0.8,
url: 'modal_content.html',
urlLoaded: (frame) => {
// add event on button to close the modal window
modalFrame.on('#bt_close', 'click', (_frame, e) => {
_frame.closeFrame();
});
}
});
modalFrame.showModal(_frame => {
//Callback when modal window is closed.
});
modalFrame.setPosition(window.innerWidth / 2, window.innerHeight / 2, 'CENTER_CENTER');
modalFrame.requestFocus();
var parentElement = jsFrame.windowManager.parentElement;
parentElement.style.zIndex = "1000";
};
const frame = jsFrame.create({
title: 'Statistiques sur 3 km',
left: 20, top: 20, width: 600, height: 450,
appearanceName: 'material',
movable: true,
resizable: true,
style: {
backgroundColor: 'rgba(220,220,220,0.95)',
overflow: 'auto',
},
appearanceParam: {
border: {
shadow: '2px 2px 10px rgba(0, 0, 0, 0.5)',
width: 0,
radius: 6,
},
titleBar: {
color: 'white',
background: '#255c96',
leftMargin: 40,
height: 30,
fontSize: 14,
buttonWidth: 36,
buttonHeight: 16,
buttonColor: 'white',
buttons: [
{
fa: 'fas fa-times',
name: 'closeButton',
visible: true
},
{
fa: 'fas fa-window-minimize',
name: 'minimizedButton',
visible: true
},
{
fa: 'fas fa-window-minimize',
name: 'deminimizeButton',
visible: false
}
],
buttonsOnLeft: [
{
fa: 'fas fa-bars',
name: 'menu',
visible: true,
childMenuHTML: '<div class="list-group">' +
' <div name="menu_layer" class="list-group-item list-group-item-action py-2">Stats sur couches</div>' +
' <div name="menu_hedgerow" class="list-group-item list-group-item-action py-2">Stats haies</div>' +
'</div>',
childMenuWidth: 500
},
],
},
},
html: '<canvas id="myChart" width="100%" height="70%" style="background-color: #ffffff00;"><p></p></canvas><canvas id="myLines" width="100%" height="70%" style="background-color: #ffffff00; display:none"><p></p></canvas>'
}).show();
frame.setControl({
styleDisplay:'inline',
minimizeButton: 'minimizedButton',
deminimizeButton: 'deminimizeButton',
hideButton: 'closeButton',
animation: true,
animationDuration: 150,
maximizeWithoutTitleBar: false
});
$("[component-id=closeButton]").unbind("click");
$("[component-id=closeButton]").attr("onclick", "");
frame.on("closeButton", "click", (_frame, _evt) => {
frame.hide();
$grbtn = $("#graph-circle");
$grbtn.addClass("closed");
});
frame.on('menu', 'click', (_frame, evt, info) => {
const name = evt.target.getAttribute('name');
if (name == 'menu_layer') {
document.getElementById("myLines").style.display = "none";
document.getElementById("myChart").style.display = "block";
} else if (name == 'menu_hedgerow') {
document.getElementById("myChart").style.display = "none";
document.getElementById("myLines").style.display = "block";
}
});
$("#graph-circle").click(function(){
frame.show()
$(this).removeClass("closed");
});
function showToast() {
jsFrame.showToast({
align: 'top', html: 'Sélectionnez une couche pour afficher les Statistiques',duration: 4000,
});
}
var ctx = document.getElementById('myChart');// Initialize Pie Chart (for layers stats)
var options = {
responsive: true,
tooltips: {
callbacks: {
label: function(tooltipItem, data) {
var dataset = data.datasets[tooltipItem.datasetIndex];
var meta = dataset._meta[Object.keys(dataset._meta)[0]];
var total = meta.total;
var currentValue = parseFloat((dataset.data[tooltipItem.index])*0.0001).toFixed(1);
var percentage = parseFloat((currentValue/total*100/0.0001).toFixed(1));
return currentValue + 'ha (' + percentage + '%)';
},
title: function(tooltipItem, data) {
return data.labels[tooltipItem[0].index];
}
}
},
title: {
display: false
},
legend: {
display: true,
position: "top",
labels: {
fontColor: "#333",
fontSize: 16
}
},
plugins: {
colorschemes: {
scheme: 'brewer.Paired12'
}
}
};
var chartdata = {
labels: [""],
datasets : [
{
data: []
}
]
};
var pieGraph = new Chart(ctx, {
type: 'pie',
data: chartdata,
options: options
});
var ctx = document.getElementById('myLines');// Initialize Horizontal bar chart
var HB_options = {
responsive: true,
scales: {
xAxes: [{
ticks: {
max: 500000,
min: 0,
callback: function(value, index, values) {
if (value == 0) {
return '0';
} else if (value == 100000) {
return 'faible';
} else if (value == 200000) {
return 'moyen';
} else if (value == 300000) {
return 'elevé';
}
}
}
}]
},
title: {
display: false
},
legend: {
display: false
}
};
var HbarData = {
labels:[],
datasets:[{
data:[],
fill:false,
backgroundColor:["rgba(255, 99, 132, 0.2)"],
borderColor:["rgb(255, 99, 132)"],
borderWidth:1
}]
};
var HbarGraph = new Chart(ctx, {
type: 'horizontalBar',
data: HbarData,
options: HB_options
});
// Variables for buffer zone around points and markers
var buffer_options = {steps: 30, units: 'kilometers'};
var buffer_radius = 3;
var selectedMarker = [];
var data_buffer = {};
// setup mapbox content
mapboxgl.accessToken = 'pk.eyJ1Ijoibm1hdHRvbiIsImEiOiJja2wxMzRzc3MwY2FzMnFvNGJ6a2FvZmFhIn0.iZJi560O2CEzv-zaNlvYOg';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/nmatton/ck87gtqj011g91iqgb3lcn0p8',
center: [4.6, 50.6], // starting position
zoom: 9 // starting zoom
});
// graph related functions
function addData(chart, label, data) {
chart.data.labels.push(label);
chart.data.datasets.forEach((dataset) => {
dataset.data.push(data);
});
chart.update();
}
function removeData(chart) {
chart.data.labels= [];
chart.data.datasets[0]["data"] = [];
chart.update();
}
// Ajout cercle, calcul stats et MAJ pie chart au CLICK!
map.on('click', function(e) {
// remove markers if already present on the map
if (selectedMarker!==null) {
for (var i = selectedMarker.length - 1; i >= 0; i--) {
selectedMarker[i].remove();
}
}
var circlesColl = turf.featureCollection([]);
// add marker to clicked position
window.lngLat = new Array(e.lngLat.toArray()[0],e.lngLat.toArray()[1]);
var marker = new mapboxgl.Marker(e).setLngLat(lngLat).addTo(map);
selectedMarker.push(marker);
// add circle around marker
circlesColl.features.push(turf.circle(lngLat, buffer_radius, buffer_options));
map.getSource('circleData').setData(circlesColl);
// zoom to clicked point
var zoom_coords = [[e.lngLat.toArray()[0] - 0.04235, e.lngLat.toArray()[1] + 0.015654],[e.lngLat.toArray()[0] + 0.04235, e.lngLat.toArray()[1] - 0.015654]]
map.fitBounds(zoom_coords, {padding: 50});
// clean data on the graph
removeData(pieGraph)
removeData(HbarGraph)
var selectedLayer = 0;
// update the graph
if (layers.children[0].className == 'active') {
// ecotopes (lifewatch)
selectedLayer = 3;
}
else if (layers.children[1].className == 'active') {
//occsol
selectedLayer = 2;
}
else if (layers.children[2].className == 'active') {
//agric
selectedLayer = 1;
}
else {
// display a popup to ask to select a layer first
selectedLayer = 0;
showToast();
}
if (selectedLayer != 0) {
jQuery.ajax({
// fetch data
url: "assets/php/data.php?x=" + e.lngLat.toArray()[0] + "&y=" + e.lngLat.toArray()[1] + "&epsg=4326&year=2018&layer=" + selectedLayer,
method: "GET",
success: function(data) {
var cult = data.map(function(v){ return v[0] });
var area = data.map(function(v){ return v[1] });
data_buffer[e.lngLat.toArray()[0] + e.lngLat.toArray()[1]] = {
[selectedLayer] : {'label': cult, 'data' : area}
};
for(var i in data) {
addData(pieGraph, data[i][0], data[i][1])
}
}
});
}
// compute PICC stats and update Line graph
jQuery.ajax({
// fetch data
url: "assets/php/data.php?x=" + e.lngLat.toArray()[0] + "&y=" + e.lngLat.toArray()[1] + "&epsg=4326&year=2018&layer=4",
method: "GET",
success: function(data) {
console.log(data)
// if location key already exists (layer already selected when click on new location)
// no need to create a nex key, just add the layer 4 with data
if (Object.keys(data_buffer).includes((e.lngLat.toArray()[0] + e.lngLat.toArray()[1]).toString())) {
data_buffer[e.lngLat.toArray()[0] + e.lngLat.toArray()[1]][4] = {
'label': 'haies', 'data' : data[0][0]
};
} else { // if the location key does not exists, create it and add layer 4 data
data_buffer[e.lngLat.toArray()[0] + e.lngLat.toArray()[1]] = {
4 : {'label': 'haies', 'data' : data[0][0]}
};
}
for(var i in data) {
addData(HbarGraph, "haies", data[i][0])
}
}
});
}); // end of "click" event
// Hacked trick to add non-3857 wms layer
function createTexture(context, canvas) {
let gl = context.gl;
let texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, canvas);
gl.generateMipmap(gl.TEXTURE_2D);
return texture;
}
map.on('load', function() {
map.addSource('wms-picc_toponym', {
'type': 'raster',
'tiles': [
'https://geoservices.wallonie.be/arcgis/services/TOPOGRAPHIE/PICC_VDIFF/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bbox-epsg-3857}&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&LAYERS=29&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE'
],
'tileSize': 256,
'attribution': 'SPW'
});
map.addLayer(
{
'id': 'toponymie',
'type': 'raster',
'source': 'wms-picc_toponym',
'paint': {},
'layout' : {'visibility': 'none'}
}
);
//Set up dummy tile layer for listening tiles.
map.addSource( "dummy-lifewatch", {
'type': 'raster',
'tiles': [
'https://upload.wikimedia.org/wikipedia/commons/4/48/BLANK_ICON.png'
],
'tileSize': 256,
'attribution': '<a href="https://maps.elie.ucl.ac.be/lifewatch/ecotopes.html" target="_blank">© UCL-geomatics</a>'
});
map.addLayer(
{
'id': "ecotopes",
'type': 'raster',
'source': "dummy-lifewatch",
'paint': {},
'layout' : {'visibility': 'none'}
}, 'toponymie');
proj4.defs("EPSG:3812","+proj=lcc +lat_1=49.83333333333334 +lat_2=51.16666666666666 +lat_0=50.797815 +lon_0=4.359215833333333 +x_0=649328 +y_0=665262 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
ol.proj.proj4.register(proj4);
// Set up hidden ol map
let wmslayer = new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'https://maps.elie.ucl.ac.be/cgi-bin/mapserv72?map=/maps_server/lifewatch/mapfiles/v3.10/LW_Belgium_ecotopes_lc_raster.map&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=lccs&TILED=true&date_db=2015&WIDTH=256&HEIGHT=256&CRS=EPSG:3812&STYLES=',
crossOrigin: '',
projection: 'EPSG:3812'
})
});
let olmap = new ol.Map({
layers: [wmslayer],
target: 'hiddenolmap',
view: new ol.View({
projection: 'EPSG:3857'
})
});
map.on('dataloading', function(tile) {
if(tile.sourceId == "dummy-lifewatch" )
{
let x = tile.tile.tileID.canonical.x;
let z = tile.tile.tileID.canonical.z;
let y = tile.tile.tileID.canonical.y;
let oltile = wmslayer.getSource().getTile(z,x,y,1,ol.proj.get("EPSG:3857")).load();
let interval = window.setInterval(function(){
let canvas = wmslayer.getSource().getTile(z,x,y,1,ol.proj.get("EPSG:3857")).getImage();
if(canvas && tile.tile.texture)
{ window.clearInterval(interval);
tile.tile.texture.texture = createTexture(map.painter.context,canvas)
map.triggerRepaint()
}
},200);
}
});
// add cosw WMS layer
map.addSource('wms-sigec18', {
'type': 'raster',
'tiles': [
'https://geoservices.wallonie.be/arcgis/services/AGRICULTURE/SIGEC_PARC_AGRI_ANON__2018/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bbox-epsg-3857}&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&LAYERS=0&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE'
],
'tileSize': 256,
'attribution': '<a href="https://geoportail.wallonie.be/" target="_blank">© SPW</a>'
});
map.addLayer(
{
'id': 'parcelles agric.',
'type': 'raster',
'source': 'wms-sigec18',
'paint': {},
'layout' : {'visibility': 'none'}
}
);
// Walous - occupation du sol
map.addSource('wms-walous-ocu', {
'type': 'raster',
'tiles': [
'https://geoservices.wallonie.be/arcgis/services/SOL_SOUS_SOL/WALOUS_OCCUPATION_SOL/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bbox-epsg-3857}&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&LAYERS=0&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE'
],
'tileSize': 256,
'attribution': '<a href="https://geoportail.wallonie.be/" target="_blank">© SPW</a>'
});
map.addLayer(
{
'id': 'occupation du sol',
'type': 'raster',
'source': 'wms-walous-ocu',
'paint': {},
'layout' : {'visibility': 'none'}
},
'parcelles agric.'
);
map.addSource('wms-picc_lignes', {
'type': 'raster',
'tiles': [
'https://geoservices.wallonie.be/arcgis/services/TOPOGRAPHIE/PICC_VDIFF/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bbox-epsg-3857}&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&LAYERS=16&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE'
],
'tileSize': 256,
'attribution': '<a href="https://geoportail.wallonie.be/" target="_blank">© SPW</a>'
});
map.addLayer(
{
'id': 'haies',
'type': 'raster',
'source': 'wms-picc_lignes',
'paint': {},
'layout' : {'visibility': 'none'}
},
'occupation du sol'
);
map.addSource('wms-ortho', {
'type': 'raster',
'tiles': [
'https://geoservices.wallonie.be/arcgis/services/IMAGERIE/ORTHO_2019/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&BBOX={bbox-epsg-3857}&CRS=EPSG:3857&WIDTH=256&HEIGHT=256&LAYERS=0&STYLES=&FORMAT=image/png&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE'
],
'tileSize': 256,
'attribution': '<a href="https://geoportail.wallonie.be/" target="_blank">© SPW</a>'
});
map.addLayer(
{
'id': 'orthophoto',
'type': 'raster',
'source': 'wms-ortho',
'paint': {},
'layout' : {'visibility': 'none'}
},
'haies'
);
// add internal source for creating circle around click position
map.addSource('circleData', {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [],
},
});
map.addLayer({
id: 'data_fill',
type: 'fill',
source: 'circleData',
paint: {
'fill-color': '#00b7bf',
'fill-opacity': 0.2,
'fill-outline-color': 'red',
'fill-antialias': true
},
});
map.addLayer({
id: 'data_line',
type: 'line',
source: 'circleData',
paint: {
'line-color': 'orange',
'line-width': 3
},
});
}); // end of "load"
var popup = new mapboxgl.Popup({
closeButton: false,
closeOnClick: false
});
var toggleableLayerIds = ['ecotopes', 'occupation du sol', 'parcelles agric.' , 'orthophoto'];
var legend = 'http://locla.be/apiscore/legend_lccs.png'
var legends={
"ecotopes":'assets/img/legend_lccs.png',
"occupation du sol":'assets/img/legend_walous_ocu.png',
"parcelles agric.":'assets/img/legend_sigec.png',
"utilisation du sol":'assets/img/legend_walous_util.png',
'orthophoto':'https://upload.wikimedia.org/wikipedia/commons/4/48/BLANK_ICON.png'
};
for (var i = 0; i < toggleableLayerIds.length; i++) {
// creation du contenu
var id = toggleableLayerIds[i];
var link = document.createElement('a');
link.href = '#';
link.className = '';
link.textContent = id;
link.onclick = function(e) {
var clickedLayer = this.textContent;
e.preventDefault();
e.stopPropagation();
var isHide = false;
for (var j = 0; j < toggleableLayerIds.length; j++) {
if (clickedLayer === toggleableLayerIds[j] && layers.children[j].className === '') {
layers.children[j].className = 'active';
map.setLayoutProperty(toggleableLayerIds[j], 'visibility', 'visible');
}
else if (clickedLayer === toggleableLayerIds[j] && layers.children[j].className === 'active') {
layers.children[j].className = '';
map.setLayoutProperty(toggleableLayerIds[j], 'visibility', 'none');
isHide = true;
}
else {
layers.children[j].className = '';
map.setLayoutProperty(toggleableLayerIds[j], 'visibility', 'none');
}
if (clickedLayer == 'orthophoto') {map.setLayoutProperty('haies', 'visibility', 'visible');}
}
// update legend
ctx = document.getElementById('legend');
if (clickedLayer == 'orthophoto' || isHide) {ctx.innerHTML = "";} else {ctx.innerHTML = "<b>Légende</b> <br> <img src=" + legends[clickedLayer] +" alt='légende'>";}
// update graph content
// clean data on the graph
removeData(pieGraph)
// update the graph
var selectedLayer = 0;
switch (clickedLayer) {
case 'ecotopes':
selectedLayer = 3;
break;
case 'occupation du sol':
selectedLayer = 2;
break;
case 'parcelles agric.':
selectedLayer = 1;
break;
default:
selectedLayer = 0;
break;
};
if (selectedLayer != 0) {
//if (Object.keys(data_buffer).includes((window.lngLat[0] + window.lngLat[1]).toString()) ) {
if (Object.keys(data_buffer[window.lngLat[0] + window.lngLat[1]]).includes(selectedLayer.toString())) {
data = data_buffer[window.lngLat[0]+ window.lngLat[1]][selectedLayer]['data'];
label = data_buffer[window.lngLat[0]+ window.lngLat[1]][selectedLayer]['label'];
for(var i in data) {
addData(pieGraph, label[i], data[i])
}
} else {
jQuery.ajax({
// fetch data
url: "assets/php/data.php?x=" + window.lngLat[0] + "&y=" + window.lngLat[1] + "&epsg=4326&year=2018&layer=" + selectedLayer,
method: "GET",
success: function(data) {
console.log(data);
var cult = data.map(function(v){ return v[0] });
var area = data.map(function(v){ return v[1] });
data_buffer[window.lngLat[0] + window.lngLat[1]][selectedLayer] = {
'label': cult, 'data' : area
};
for(var i in data) {
addData(pieGraph, data[i][0], data[i][1])
}
}
});
}
}
};
var layers = document.getElementById('menu');
layers.appendChild(link);
}
map.addControl(new mapboxgl.NavigationControl());
$(document).ready(openModal());
// Start the DOM ready
jQuery( document ).ready( function( $ ) {
$("html").mouseleave(function() {
// Show Modal
//CODE NEEDED FOR THE IMPORTANT MESSAGE MODAL POPUP
//Check to see if the cookie exists for the Don't show again option
if (!$.cookie('focusmsg')) {
//Launch the modal when you first visit the site
$('#important-msg').modal('show');
}
//Don't show again mouse click
$("#dont-show-again").click( function() {
//Create a cookie that lasts 14 days
$.cookie('focusmsg', '1', { expires: 14 });
$('#important-msg').modal('hide');
}); //end the click function for don't show again
});
});
</script>
</body>
</html>