var tl_data = []; var intersections_geojson = {}; const intersectionsgeojsonloader = new GeojsonLoader(); const intersections_layer_def = { 'id': 'traffic-lights', 'type': 'circle', 'source': 'traffic-lights', 'filter': [ 'all', ['!', ['coalesce', ['get', 'is_radar'], false]] ], 'paint': { 'circle-radius': [ 'interpolate', ['linear'], ['zoom'], 10, 2, 13, 4, 16, 7, 19, 10 ], 'circle-color': [ 'case', ['boolean', ['feature-state', 'highlighted'], false], '#ffeb3bbf', // Highlight color '#0094ff' // Default color ], 'circle-opacity': 0.7 } }; const intersections_radar_outline_layer_def = { 'id': 'traffic-lights-radar-outline', 'type': 'symbol', 'source': 'traffic-lights', 'filter': ['coalesce', ['get', 'is_radar'], false], 'layout': { 'icon-image': 'cross-sdf-border', 'icon-size': ['interpolate', ['linear'], ['zoom'], 10, 0.22, 13, 0.35, 16, 0.6, 19, 0.85], 'icon-allow-overlap': true, 'icon-ignore-placement': true, }, 'paint': { 'icon-color': [ 'case', ['boolean', ['feature-state', 'highlighted'], false], '#ffeb3b', '#ffffff' ] } }; const intersections_radar_layer_def = { 'id': 'traffic-lights-radar', 'type': 'symbol', 'source': 'traffic-lights', 'filter': ['coalesce', ['get', 'is_radar'], false], 'layout': { 'icon-image': 'cross-sdf', 'icon-size': ['interpolate', ['linear'], ['zoom'], 10, 0.22, 13, 0.35, 16, 0.6, 19, 0.85], 'icon-allow-overlap': true, 'icon-ignore-placement': true, }, 'paint': { 'icon-color': [ 'case', ['boolean', ['feature-state', 'highlighted'], false], '#ffeb3bbf', // Highlight color '#0094ff' // Default color ] } }; const intersections_layers = [intersections_layer_def, intersections_radar_outline_layer_def, intersections_radar_layer_def]; handleGeojsonMapLoading(init=true, intersectionsgeojsonloader, 'traffic-lights', intersections_layers); // Reset table if error occurs when loading GeoJSON intersectionsgeojsonloader.addEventListener("geojsonError", event => { loadDataIntoIntersectionsTable([]); }); // Load data into table when GeoJSON is loaded intersectionsgeojsonloader.addEventListener("geojsonLoaded", event => { var geojson_data = event.detail; loadDataIntoIntersectionsTable(geojson_data.features); intersections_geojson = geojson_data; }); var assets_geojson = {}; const assetsgeojsonloader = new GeojsonLoader(); const assets_layer_def = { 'id': 'traffic-lights-assets', 'type': 'circle', 'source': 'traffic-lights-assets', 'paint': { 'circle-radius': [ 'interpolate', ['linear'], ['zoom'], 13, 1, 22, 10 ], 'circle-color': [ 'case', ['boolean', ['feature-state', 'highlighted'], false], '#ffeb3bbf', // Highlight color '#f24141' // Default color ], 'circle-opacity': 0.7 }, minzoom: 15 } handleGeojsonMapLoading(init=true, assetsgeojsonloader, 'traffic-lights-assets', [assets_layer_def]); assetsgeojsonloader.addEventListener("geojsonError", event => { loadDataIntoAssetsTable([]); }); assetsgeojsonloader.addEventListener("geojsonLoaded", event => { var geojson_data = event.detail; loadDataIntoAssetsTable(geojson_data.features); assets_geojson = geojson_data; }); // Load Map maploader.loadMap("map"); // Map layers events registerLayerMouseEnter(map, 'traffic-lights', popup, 'code', 13); registerLayerMouseLeave(map, 'traffic-lights', popup); registerLayerMouseEnter(map, 'traffic-lights-radar', popup, 'code', 13); registerLayerMouseLeave(map, 'traffic-lights-radar', popup); registerLayerMouseEnter(map, 'traffic-lights-assets', popup, 'name', 17); registerLayerMouseLeave(map, 'traffic-lights-assets', popup); var intersectionshighlightState = { previousId: null }; // Track the previously highlighted feature const handleIntersectionClick = (e) => { const featureId = e.features[0].id; const currentZoom = map.getZoom(); if (currentZoom > 13) { // Highlight the corresponding row in the Bootstrap table highlightRow('#intersections-table', 'id', featureId); // Update feature highlight on the map highlightMapFeature(map, 'traffic-lights', featureId, intersectionshighlightState); highlightMapFeature(map, 'traffic-lights-radar', featureId, intersectionshighlightState); // Load assets GeoJSON for the selected intersection const intersectionId = featureId; const intersectionAssetsGeojsonUrl = `${assetsgeojsonUrl}?intersection=${intersectionId}`; assetsgeojsonloader.loadGeojson(intersectionAssetsGeojsonUrl); } }; map.on('click', 'traffic-lights', handleIntersectionClick); map.on('click', 'traffic-lights-radar', handleIntersectionClick); var assetshighlightState = { previousId: null }; // Track the previously highlighted feature map.on('click', 'traffic-lights-assets', (e) => { const featureId = e.features[0].id; const currentZoom = map.getZoom(); if (currentZoom > 13) { //window.open(trafficlightintersectionsurl+e.features[0].id+"/","_self"); // Highlight the corresponding row in the Bootstrap table highlightRow('#assets-table', 'id', featureId); // Update feature highlight on the map highlightMapFeature(map, 'traffic-lights-assets', featureId, assetshighlightState); } }); // Charger les données initiales const params = new URLSearchParams(window.location.search).toString(); intersectionsgeojsonloader.loadGeojson(intersectionsgeojsonUrl+`?${params}`); assetsgeojsonloader.loadGeojson(assetsgeojsonUrl); function actionsFormatter(value, row, index) { resp = ``; if (row.lon) { resp = resp + ``; } if (preventive_draft_id && preventive_draft_id !== "None") { // If we are in the context of a preventive draft, we add the button to select the intersection if (selected_intersections_set.has(row.id)) { icon_select = 'bi-check-square-fill'; } else { icon_select = 'bi-square'; } resp = resp + ``; } return resp; } function actionsFormatterAssets(value, row, index) { resp = ``; if (row.lon) { resp = resp + ``; } if (intervention_id) { resp = resp + ``; } return resp; } // Loads features into the intersections table function loadDataIntoIntersectionsTable(features) { const tableData = features.map((feature) => { return { actions: '', // Column for the icons, manipulated by the formatter id: feature.id, code: feature.properties.code, name: feature.properties.name, status: '', lon: feature.geometry && feature.geometry.coordinates ? feature.geometry.coordinates[0] : null, // Longitude lat: feature.geometry && feature.geometry.coordinates ? feature.geometry.coordinates[1] : null // Latitude }; }); $('#intersections-spinner').hide(); $('#intersections-table-container').show(); $('#intersections-table').bootstrapTable('load', tableData); } // Loads features into the assets table function loadDataIntoAssetsTable(features) { const tableData = features.map((feature) => { return { actions: '', // Colonne pour l'icône, manipulée par le formatter id: feature.id, asset_type: feature.properties.asset_type, code: feature.properties.code, name: feature.properties.name, model: feature.properties.model || '', status: '', lon: feature.geometry && feature.geometry.coordinates ? feature.geometry.coordinates[0] : null, // Longitude lat: feature.geometry && feature.geometry.coordinates ? feature.geometry.coordinates[1] : null // Latitude }; }); $('#assets-spinner').hide(); $('#assets-table-container').show(); $('#assets-table').bootstrapTable('load', tableData); } function redirectToThematic() { const select = document.getElementById('theme-select'); const selectedValue = select.value; if (selectedValue) { // Rediriger vers l'URL sélectionnée window.location.href = selectedValue; } } $( document ).ready(function() { function calculateTableHeight() { const windowHeight = $(window).height(); // Total window height const offsetTop = 285; // Y position of the table const footerHeight = $('.footer').outerHeight() || 0; return windowHeight - offsetTop - footerHeight - 20; } $('#intersections-table').bootstrapTable({ columns: [ { field: 'actions', title: '', formatter:'actionsFormatter', width:'130' }, { field: 'code', title: 'Code' }, { field: 'name', title: 'Nom' }, { field: 'status', title: 'Statut', align: 'center' } ], height: calculateTableHeight(), // Apply computed height onClickRow: function (row, $element) { // Remove highlight from all previously highlighted cells $('#intersections-table').find('tbody td').removeClass('rowhighlight'); // Apply the highlight class to all `