forked from can-luckyshot/IMSpoorViewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableBuilder.js
98 lines (93 loc) · 2.87 KB
/
tableBuilder.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
var tableTypeMap;
function setTableTypeMap(typeMap) {
tableTypeMap = typeMap;
}
function loadDataTables() {
console.log('loadDataTables');
if (tableTypeMap) {
buildDataTables(tableTypeMap);
tableTypeMap = undefined; // load only once;
}
else{
console.log('no data yet');
}
}
function buildDataTables(typeMap) {
$('#tableLegend').empty();
$('#tableContent').empty();
var first = true;
$.each(typeMap, function (type, entry) {
var color = entry.color;
var renderableObjects = entry.list;
//console.log(type + ' ' + renderableObjects.length + ' items');
var tableDiv = $('<div></div>').attr('id', type);
var table = $('<table></table>').addClass('table table-bordered');
var thead = $('<thead></thead>');
var tr = $('<tr></tr>');
var headers = new Object();
$.each(renderableObjects, function (index, dataObject) {
$.each(dataObject.attributes, function (index,attrib) {
headers[attrib.nodeName] = attrib.nodeName;
});
});
$.each(headers, function (header, value) {
tr.append($('<th>' + header + '</th>'));
});
thead.append(tr);
table.append(thead);
var tbody = $('<tbody></tbody>');
for (var i = 0; i < renderableObjects.length; i++) {
var row = $('<tr></tr>');
$.each(headers, function (header, value) {
var value = $(renderableObjects[i]).attr(header);
if (header.toLowerCase().indexOf('puic') > -1) {
var link = $('<a></a>').text(value).on('click', jumpToFeature);
var rowData = $('<td></td>').append(link);
row.append(rowData);
} else {
var rowData = $('<td></td>').text(value);
row.append(rowData);
}
});
tbody.append(row);
}
table.append(tbody);
var title = $('<h1>' + type + ' (' + renderableObjects.length + ')</h1>');
var legendItem = $('<li></li>').append('<a href="#' + type + '">' + type + '</a>');
if (first) {
legendItem.addClass('active');
first = false;
}
$('#tableLegend').append(legendItem);
tableDiv.append(title);
var par = $('<p></p>');
par.append(table);
tableDiv.append(par);
$('#tableContent').append(tableDiv);
});
}
function jumpToFeature(evt) {
var puic = event.target.text;
console.log('jump to puic: ' + puic);
var layers = vectorLayers.getLayers().getArray();
console.log('layers: ' + layers.length);
for (var i = 0; i < layers.length; i++) {
var subLayers = layers[i].getLayers().getArray();
console.log('subLayers: ' + subLayers.length);
for (var j = 0; j < subLayers.length; j++) {
console.log('subLayer: ' + subLayers[j].get('title'));
var feature = subLayers[j].getSource().getFeatureById(puic);
if (feature) {
console.log('gevonden: ' + feature);
map.getView().fit(feature.getGeometry(), map.getSize());
var zoom = map.getView().getZoom();
if (zoom >= 20) {
map.getView().setZoom(20);
}
console.log('show tab mapviewer')
$('.navbar-nav a[href="#mapviewer"]').tab('show');
break;
}
}
};
}