Skip to content

Commit 3bc3347

Browse files
authored
Right dock that show data from a layer (#75)
* Create README.md * Add files via upload * Update README.md Added driver_tutorial to the main Readme * Update tour.css * Update tour.js * Update tour.js Update tour.js with shepherd.js * Update tour.css Update tour.css with shepherd classes * Update README.md Update readme for shepherd.js * Create README.md * Add transparency script Enable you to change the transparency of all checked layers * Update README.md Add change_opacity * Update README.md * Delete library/ui/change_opacity directory * Update README.md * Create data_table.js Enable user to add a table of a specific layer and statistics * Create README.md Creation of readme for data_table * Update README.md Update readme and add "Dispaly a right-docked table of data" * Update README.md * Add demo.gif Add demo.gif * Update README.md Add ![guided-tour](./demo.gif) * Update README.md Change on Popup Metadata * Update tour.js Remove french text to english text * Add demo.png * Update README.md Add demo.png * Create README.md This UI can enable user to map data from an excel table * Create table-dock.js Main UI * Create table-dock.css * Create table-XY.js Enable user to map data from X and Y field * Update table-XY.js * Update table-dock.js * Create table-style.js Change the style of layers * Update README.md * Update README.md * Update README.md * Update table-XY.js Update for the worker * Create workerXY.js * Update table-dock.js Update with current bootstrap for lizmap * Update table-XY.js Add the workerXY * Update README.md * Delete library/ui/map-excel directory * Delete library/ui/driver_tutorial directory * Update data_table.js Translate some texte from french to english.
1 parent f7d270e commit 3bc3347

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ the script was written.
7272
### UI
7373

7474
* [Add documentation](./library/ui/add_documentation) with buttons and a dock
75+
* [Display a right-docked table of data](./library/ui/data_table)
7576
* [Background selector](./library/ui/background_selector), like on Google Maps
7677
* [Hide value popup](./library/ui/hide_value_popup)
7778
* [Measure tool custom style](./library/ui/measure_tool_custom_style)

library/ui/data_table/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Data Display
2+
3+
![donnees](./demo.png)
4+
5+
This script retrieves data from a given URL containing GeoJSON data, dynamically creates an HTML table with the fetched data, and displays it in a Lizmap user interface.

library/ui/data_table/data_table.js

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
lizMap.events.on({
2+
'uicreated': function () {
3+
4+
// Change the URL from your own data
5+
const URL = 'https://url/index.php/lizmap/service/?repository=your_repositoryu&project=your_project&SERVICE=WFS&REQUEST=GetFeature&VERSION=your_version&TYPENAME=your_layerOUTPUTFORMAT=GeoJSON';
6+
const NAME = "Nom de la couche"
7+
8+
var html = '<div id="statistic_content"></div>';
9+
lizMap.addDock(
10+
'table_dock',
11+
`Table of ${NAME}`,
12+
'right-dock',
13+
html,
14+
'icon-signal'
15+
);
16+
17+
try {
18+
const promise = getData(URL);
19+
20+
// Handle promise resolution
21+
promise.then(features =>{
22+
// Extract property names from the first feature
23+
const propertyNames = Object.keys(features[0].properties);
24+
const tableRows = [];
25+
26+
// Create table header using property names
27+
const tableHeader = `
28+
<thead>
29+
<tr>
30+
${propertyNames.map(propertyName => `<th>${propertyName}</th>`).join('')}
31+
</tr>
32+
</thead>
33+
`;
34+
35+
// Add rows to the table
36+
features.forEach(feature => {
37+
const row = `
38+
<tr>
39+
${propertyNames.map(propertyName => `<td>${feature.properties[propertyName]}</td>`).join('')}
40+
</tr>
41+
`;
42+
tableRows.push(row);
43+
});
44+
45+
// Update the style of your table
46+
const tableStyle = `
47+
<style>
48+
table#table-data {
49+
width: 100%;
50+
border-collapse: collapse;
51+
border: 1px solid;
52+
color:white;
53+
}
54+
#table-data th, #table-data td {
55+
padding: 8px;
56+
text-align: left;
57+
border-bottom: 1px solid #ddd;
58+
}
59+
table#table-data th {
60+
background-color: grey;
61+
}
62+
</style>
63+
`;
64+
65+
// Get to the table container
66+
const tableContainer = $('#statistic_dock');
67+
68+
// Add the content of the table
69+
tableContainer.html(`
70+
${tableStyle}
71+
<table id="table-data">
72+
${tableHeader}
73+
${tableRows.join('')}
74+
</table>
75+
`);
76+
77+
})
78+
}catch (error) {
79+
console.error('An error occurred during processing: ', error);
80+
}
81+
82+
}
83+
})
84+
85+
// Asynchronous function to get data
86+
async function getData(url) {
87+
try {
88+
const response = await fetch(url);
89+
90+
if (!response.ok) {
91+
throw new Error(`HTTP Error! Status: ${response.status}`);
92+
}
93+
94+
const data = await response.json();
95+
return data.features;
96+
97+
} catch (error) {
98+
console.error('An error occurred while retrieving the data', error);
99+
throw error;
100+
}
101+
};

library/ui/data_table/demo.png

1.01 MB
Loading

0 commit comments

Comments
 (0)