-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_query.html
112 lines (105 loc) · 3.26 KB
/
demo_query.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
<html>
<script src="https://apiv3.geoportail.lu/apiv3loader.js" type="text/javascript"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>
<body>
<div class="container">
<div class="row" style="height:100%;">
<div class="col-8"><div id="map"></div></div>
<div class="col-4">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>Label</th>
<th>Id</th>
</tr>
</thead>
<tbody id="bodyTable">
</tbody>
</table>
</div>
</div>
</div>
</body>
<script>
var map = new lux.Map({
layers: ['359'],
layerOpacities: [0.5],
layerVisibilities: [true],
target: 'map',
bgLayer: 'basemap_2015_global',
zoom: 18,
position: [75977, 75099],
zoomToExtent: true,
search : {
target : 'map',
dataSets : ['Parcelle']
},
showLayerInfoPopup : false,
layerInfoCallback: selectParcelles,
queryableLayers: [359]
});
map.enableShowSelectedFeature(false);
var fillStyle = new ol.style.Fill({
color: [255, 255, 0, 0.6]
});
var strokeStyle = new ol.style.Stroke({
color: [255, 155, 55, 1],
width: 3
});
var vectorStyle = new ol.style.Style({
fill: fillStyle,
stroke: strokeStyle
});
var vectorLayer = map.createVectorLayer(vectorStyle);
function selectParcelles(arrayFeatures) {
if (arrayFeatures === undefined) {
console.log("undefined");
return;
}
arrayFeatures.forEach(function(feature) {
var res = vectorLayer.getSource().getFeatures().filter(function(filter_feature) {
return (filter_feature.getProperties()['id'] == feature.getProperties()['id'])
});
if (res.length > 0) {
// If a feature with the same id is already in the layer the remove it
removeParcel(feature.getProperties()['id']);
} else {
vectorLayer.getSource().addFeatures([feature]);
}
});
refreshTable();
}
function refreshTable() {
var tbody = document.getElementById('bodyTable');
tbody.innerHTML = '';
vectorLayer.getSource().getFeatures().forEach(function(feature){
var tr = document.createElement('tr');
var elem = document.createElement('button');
elem.innerHTML = '<i class="fa fa-trash"></i>';
elem.onclick = function() {
removeParcel(feature.getProperties()['id']);
}
tr.append(elem)
elem = document.createElement('td');
elem.innerHTML = feature.getProperties()['label'];
tr.append(elem)
elem = document.createElement('td');
elem.innerHTML = feature.getProperties()['id'];
tr.append(elem)
tbody.append(tr);
});
map.getShowLayer().getSource().clear();
}
function removeParcel(id) {
vectorLayer.getSource().getFeatures().forEach(function(feature) {
if (feature.get('id') === id) {
vectorLayer.getSource().removeFeature(feature);
}
});
refreshTable();
}
</script>
</html>