2025-05-26 23:51:46 +02:00
|
|
|
{% extends 'base.html.twig' %}
|
|
|
|
|
|
|
|
{% block title %}{{ 'display.stats'|trans }}{% endblock %}
|
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
{% block stylesheets %}
|
|
|
|
{{ parent() }}
|
2025-06-03 14:58:23 +02:00
|
|
|
<link href='{{ asset('js/maplibre/maplibre-gl.css') }}' rel='stylesheet' />
|
2025-06-01 19:52:56 +02:00
|
|
|
{% endblock %}
|
|
|
|
|
2025-05-26 23:51:46 +02:00
|
|
|
{% block body %}
|
|
|
|
<div class="container">
|
2025-05-29 16:50:25 +02:00
|
|
|
<div class="mt-4 p-4">
|
|
|
|
<h1 class="title">{{ 'display.stats'|trans }}</h1>
|
2025-05-26 23:51:46 +02:00
|
|
|
<p>
|
|
|
|
{{ stats.zone }}
|
2025-06-03 12:51:20 +02:00
|
|
|
{{ stats.name }}
|
2025-05-26 23:51:46 +02:00
|
|
|
</p>
|
2025-06-03 12:51:20 +02:00
|
|
|
<a href="{{ path('app_admin_labourer', {'zip_code': stats.zone}) }}" class="btn btn-primary" id="labourer">Labourer les mises à jour</a>
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
{{ stats.getCompletionPercent() }} % complété sur les critères donnés.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-building"></i> {{ stats.getPlacesCount() }} commerces dans la zone.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-clock"></i> {{ stats.getAvecHoraires() }} commerces avec horaires.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-map"></i> {{ stats.getAvecAdresse() }} commerces avec adresse.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-globe"></i> {{ stats.getAvecSite() }} commerces avec site web renseigné.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-arrow-up-right"></i>
|
|
|
|
{{ stats.getAvecAccessibilite() }} commerces avec accessibilité PMR renseignée.
|
|
|
|
</div>
|
|
|
|
<div class="col-md-3 col-12">
|
|
|
|
<i class="bi bi-chat-dots"></i> {{ stats.getAvecNote() }} commerces avec note renseignée.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
<div id="map" style="height: 400px;"></div>
|
2025-06-03 12:51:20 +02:00
|
|
|
|
|
|
|
{# <div id="query" style="height: 400px;"> #}
|
|
|
|
{# <pre>
|
|
|
|
{{query_places|raw}}
|
|
|
|
</pre> #}
|
|
|
|
</div>
|
2025-05-26 23:51:46 +02:00
|
|
|
<div class="card mt-4">
|
2025-06-03 12:51:20 +02:00
|
|
|
<h1 class="card-title">Tableau des {{ stats.getPlacesCount() }} lieux</h1>
|
|
|
|
<a href="{{ path('app_admin_export_csv', {'zip_code': stats.zone}) }}" class="btn btn-primary">Exporter en CSV</a>
|
|
|
|
<table class="table table-bordered table-striped table-hover table-responsive">
|
2025-06-03 11:37:27 +02:00
|
|
|
{% include 'admin/stats/table-head.html.twig' %}
|
2025-05-26 23:51:46 +02:00
|
|
|
<tbody>
|
|
|
|
{% for commerce in stats.places %}
|
2025-06-03 11:37:27 +02:00
|
|
|
{% include 'admin/stats/row.html.twig' %}
|
2025-05-26 23:51:46 +02:00
|
|
|
{% endfor %}
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
2025-06-03 12:51:20 +02:00
|
|
|
|
|
|
|
<h2>requête overpass</h2>
|
|
|
|
<pre>
|
|
|
|
{{query_places|raw}}
|
|
|
|
</pre>
|
|
|
|
</div>
|
2025-05-26 23:51:46 +02:00
|
|
|
</div>
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-03 14:58:23 +02:00
|
|
|
<script src='{{ asset('js/maplibre/maplibre-gl.js') }}'></script>
|
2025-06-01 19:52:56 +02:00
|
|
|
<script>
|
2025-06-03 12:51:20 +02:00
|
|
|
const request = `{{query_places|raw}}`;
|
|
|
|
const zip_code = `{{stats.zone}}`;
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
async function fetchland() {
|
2025-06-03 12:51:20 +02:00
|
|
|
// Requête pour obtenir le contour administratif
|
|
|
|
const boundaryQuery = `[out:json][timeout:25];
|
|
|
|
area["postal_code"="${zip_code}"]->.searchArea;
|
|
|
|
(
|
|
|
|
relation["boundary"="postal_code"]["postal_code"="${zip_code}"](area.searchArea);
|
|
|
|
);
|
|
|
|
out body;
|
|
|
|
>;
|
|
|
|
out skel qt;`;
|
|
|
|
|
|
|
|
const encodedBoundaryRequest = encodeURIComponent(boundaryQuery);
|
|
|
|
const boundaryResponse = await fetch(`https://overpass-api.de/api/interpreter?data=${encodedBoundaryRequest}`);
|
|
|
|
const boundaryData = await boundaryResponse.json();
|
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
const encodedRequest = encodeURIComponent(request);
|
|
|
|
const overpassUrl = `https://overpass-api.de/api/interpreter?data=${encodedRequest}`;
|
|
|
|
const response = await fetch(overpassUrl);
|
|
|
|
const data = await response.json();
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
const map = new maplibregl.Map({
|
|
|
|
container: 'map',
|
|
|
|
style: 'https://api.maptiler.com/maps/basic-v2/style.json?key={{ maptiler_token }}',
|
|
|
|
center: [2.3488, 48.8534],
|
|
|
|
zoom: 12
|
|
|
|
});
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
map.on('load', () => {
|
2025-06-03 12:51:20 +02:00
|
|
|
// Ajouter le contour administratif
|
|
|
|
if (boundaryData.elements && boundaryData.elements.length > 0) {
|
|
|
|
const boundary = boundaryData.elements[0];
|
|
|
|
if (boundary.members) {
|
|
|
|
const coordinates = boundary.members.map(member => {
|
|
|
|
if (member.type === 'node') {
|
|
|
|
return [member.lon, member.lat];
|
|
|
|
}
|
|
|
|
}).filter(coord => coord);
|
|
|
|
|
|
|
|
map.addSource('boundary', {
|
|
|
|
'type': 'geojson',
|
|
|
|
'data': {
|
|
|
|
'type': 'Feature',
|
|
|
|
'geometry': {
|
|
|
|
'type': 'Polygon',
|
|
|
|
'coordinates': [coordinates]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
map.addLayer({
|
|
|
|
'id': 'boundary-layer',
|
|
|
|
'type': 'fill',
|
|
|
|
'source': 'boundary',
|
|
|
|
'paint': {
|
|
|
|
'fill-color': '#088',
|
|
|
|
'fill-opacity': 0.1,
|
|
|
|
'fill-outline-color': '#000'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-01 23:35:15 +02:00
|
|
|
console.log('map chargé',data.elements);
|
2025-06-01 19:52:56 +02:00
|
|
|
data.elements.forEach(element => {
|
2025-06-01 23:35:15 +02:00
|
|
|
if(element.tags){
|
|
|
|
|
|
|
|
console.log('element', element.tags['name'] , element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element.lat && element.lon && element.tags && element.tags['name']) {
|
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
const el = document.createElement('div');
|
|
|
|
el.className = 'marker';
|
|
|
|
let tagstable = '<table class="table table-bordered"><tr><th>Clé</th><th>Valeur</th></tr>';
|
|
|
|
if (element.tags) {
|
|
|
|
for (const tag in element.tags) {
|
|
|
|
tagstable += `<tr><td>${tag}</td><td>${element.tags[tag]}</td></tr>`;
|
|
|
|
}
|
2025-06-01 18:56:01 +02:00
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
tagstable += '</table>';
|
|
|
|
|
2025-06-01 23:35:15 +02:00
|
|
|
// Créer un élément div pour le texte du nom
|
|
|
|
const nameDiv = document.createElement('div');
|
|
|
|
nameDiv.className = 'marker-name';
|
2025-06-03 12:51:20 +02:00
|
|
|
nameDiv.textContent = element.tags?.name || '(Sans nom)';
|
2025-06-01 23:35:15 +02:00
|
|
|
el.appendChild(nameDiv);
|
2025-06-03 12:51:20 +02:00
|
|
|
|
2025-06-01 23:35:15 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
new maplibregl.Marker(el)
|
|
|
|
.setLngLat([element.lon, element.lat])
|
2025-06-03 12:51:20 +02:00
|
|
|
.setPopup(new maplibregl.Popup({
|
|
|
|
offset: 25,
|
|
|
|
anchor: 'bottom'
|
|
|
|
})
|
2025-06-01 23:35:15 +02:00
|
|
|
.setHTML(
|
|
|
|
`<a href="/admin/placeType/${element.type}/${element.id}" ><h3>${element.tags?.name || 'Sans nom'}</h3></a> <br><a href="https://openstreetmap.org/${element.type}/${element.id}" target="_blank">OSM</a> ${tagstable}`
|
2025-06-03 12:51:20 +02:00
|
|
|
)
|
|
|
|
)
|
2025-06-01 19:52:56 +02:00
|
|
|
.addTo(map);
|
2025-06-01 18:56:01 +02:00
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
});
|
|
|
|
});
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
// Calculer les limites (bounds) à partir des marqueurs
|
|
|
|
const bounds = new maplibregl.LngLatBounds();
|
|
|
|
data.elements.forEach(element => {
|
|
|
|
if (element.lat && element.lon) {
|
|
|
|
bounds.extend([element.lon, element.lat]);
|
2025-05-28 16:24:34 +02:00
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
});
|
2025-05-28 16:24:34 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
// Centrer et zoomer la carte pour inclure tous les marqueurs
|
|
|
|
if (!bounds.isEmpty()) {
|
|
|
|
map.fitBounds(bounds, {
|
|
|
|
padding: 50 // Ajoute une marge autour des marqueurs
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2025-06-01 18:56:01 +02:00
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
const headers = document.querySelectorAll('th');
|
|
|
|
headers.forEach(header => {
|
|
|
|
const text = header.textContent;
|
|
|
|
const match = text.match(/\((\d+)\s*\/\s*(\d+)\)/);
|
|
|
|
if (match) {
|
|
|
|
const [_, completed, total] = match;
|
|
|
|
const ratio = completed / total;
|
|
|
|
const alpha = ratio.toFixed(2);
|
|
|
|
header.style.backgroundColor = `rgba(154, 205, 50, ${alpha})`;
|
2025-06-01 18:56:01 +02:00
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
});
|
2025-06-01 18:56:01 +02:00
|
|
|
|
|
|
|
fetchland();
|
2025-06-01 19:52:56 +02:00
|
|
|
|
|
|
|
sortTable();
|
|
|
|
});
|
|
|
|
</script>
|
2025-05-26 23:51:46 +02:00
|
|
|
{% endblock %}
|