2025-05-26 23:51:46 +02:00
|
|
|
{% extends 'base.html.twig' %}
|
|
|
|
|
2025-06-04 00:16:56 +02:00
|
|
|
{% block title %}{{ 'display.stats'|trans }}- {{ stats.zone }}
|
|
|
|
{{ stats.name }} {% endblock %}
|
2025-05-26 23:51:46 +02:00
|
|
|
|
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-06 11:50:37 +02:00
|
|
|
<style>
|
|
|
|
.completion-circle {
|
|
|
|
fill-opacity: 0.6;
|
|
|
|
stroke: #fff;
|
|
|
|
stroke-width: 3;
|
|
|
|
}
|
|
|
|
</style>
|
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">
|
2025-06-04 00:16:56 +02:00
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6 col-12">
|
|
|
|
<h1 class="title">{{ 'display.stats'|trans }} - {{ stats.zone }}
|
|
|
|
{{ stats.name }} - {{ stats.completionPercent }}% complété</h1>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-6 col-12">
|
|
|
|
<a href="{{ path('app_admin_labourer', {'zip_code': stats.zone}) }}" class="btn btn-primary" id="labourer">Labourer les mises à jour</a>
|
2025-06-06 11:50:37 +02:00
|
|
|
<button id="openInJOSM" class="btn btn-secondary ms-2">
|
|
|
|
<i class="bi bi-map"></i> Ouvrir dans JOSM
|
|
|
|
</button>
|
2025-06-04 00:16:56 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2025-06-03 12:51:20 +02:00
|
|
|
<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">
|
2025-06-04 00:46:46 +02:00
|
|
|
<i class="bi bi-building"></i> {{ stats.places | length}} commerces dans la zone.
|
2025-06-03 12:51:20 +02:00
|
|
|
</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-04 00:16:56 +02:00
|
|
|
<div id="maploader">
|
|
|
|
<div class="spinner-border" role="status">
|
|
|
|
<i class="bi bi-load bi-spin"></i>
|
|
|
|
<span class="visually-hidden">Chargement de la carte...</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-06-04 00:46:46 +02:00
|
|
|
<div id="map" class="mt-4" style="height: 400px;"></div>
|
2025-06-04 00:16:56 +02:00
|
|
|
|
2025-06-03 12:51:20 +02:00
|
|
|
</div>
|
2025-05-26 23:51:46 +02:00
|
|
|
<div class="card mt-4">
|
2025-06-04 00:16:56 +02:00
|
|
|
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6 col-12">
|
|
|
|
<h1 class="card-title p-4">Tableau des {{ stats.places |length }} lieux</h1>
|
|
|
|
</div>
|
|
|
|
<div class="col-md-6 col-12">
|
2025-06-04 00:46:46 +02:00
|
|
|
<a class="btn btn-primary pull-right mt-4" href="{{ path('app_admin_export_csv', {'zip_code': stats.zone}) }}" class="btn btn-primary">
|
2025-06-04 00:16:56 +02:00
|
|
|
<i class="bi bi-filetype-csv"></i>
|
|
|
|
Exporter en CSV
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
2025-06-03 12:51:20 +02:00
|
|
|
<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>
|
2025-06-04 00:16:56 +02:00
|
|
|
<pre class="p-4 bg-light">
|
2025-06-03 12:51:20 +02:00
|
|
|
{{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-06 11:50:37 +02:00
|
|
|
<script src='{{ asset('js/turf/turf.min.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-06 11:50:37 +02:00
|
|
|
let mapElements = [];
|
|
|
|
|
|
|
|
function getCompletionColor(completion) {
|
|
|
|
if (completion === undefined || completion === null) {
|
|
|
|
return '#808080'; // Gris pour pas d'information
|
|
|
|
}
|
|
|
|
// Convertir le pourcentage en couleur verte (0% = blanc, 100% = vert foncé)
|
|
|
|
const intensity = Math.floor((completion / 100) * 255);
|
|
|
|
return `rgb(0, ${intensity}, 0)`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function calculateCompletion(element) {
|
|
|
|
let completed = 0;
|
|
|
|
let total = 0;
|
|
|
|
|
|
|
|
// Critères à vérifier
|
|
|
|
const criteria = [
|
|
|
|
'name',
|
|
|
|
'addr:street',
|
|
|
|
'addr:housenumber',
|
|
|
|
'addr:postcode',
|
|
|
|
'addr:city',
|
|
|
|
'opening_hours',
|
|
|
|
'website',
|
|
|
|
'wheelchair',
|
|
|
|
'phone'
|
|
|
|
];
|
|
|
|
|
|
|
|
criteria.forEach(criterion => {
|
|
|
|
if (element.tags && element.tags[criterion]) {
|
|
|
|
completed++;
|
|
|
|
}
|
|
|
|
total++;
|
|
|
|
});
|
|
|
|
|
|
|
|
return total > 0 ? (completed / total) * 100 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
function createPopupContent(element) {
|
|
|
|
console.log("createPopupContent",element);
|
|
|
|
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>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
tagstable += '</table>';
|
|
|
|
|
|
|
|
return `
|
|
|
|
<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-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];
|
2025-06-05 15:09:28 +02:00
|
|
|
area["ref:INSEE"="${zip_code}"]->.searchArea;
|
2025-06-03 12:51:20 +02:00
|
|
|
(
|
2025-06-05 15:09:28 +02:00
|
|
|
relation["boundary"="postal_code"]["ref:INSEE"="${zip_code}"](area.searchArea);
|
2025-06-03 12:51:20 +02:00
|
|
|
);
|
|
|
|
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 16:19:07 +02:00
|
|
|
console.log('map 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-04 00:46:46 +02:00
|
|
|
}else{
|
|
|
|
console.log('pas de contour administratif trouvé');
|
2025-06-03 12:51:20 +02:00
|
|
|
}
|
|
|
|
|
2025-06-01 23:35:15 +02:00
|
|
|
console.log('map chargé',data.elements);
|
2025-06-06 11:50:37 +02:00
|
|
|
mapElements = data.elements;
|
2025-06-04 00:16:56 +02:00
|
|
|
|
|
|
|
document.getElementById('maploader').classList.add('d-none');
|
|
|
|
|
2025-06-06 11:50:37 +02:00
|
|
|
// Créer une source pour les cercles
|
|
|
|
map.addSource('completion-circles', {
|
|
|
|
'type': 'geojson',
|
|
|
|
'data': {
|
|
|
|
'type': 'FeatureCollection',
|
|
|
|
'features': []
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajouter une couche pour les cercles
|
|
|
|
map.addLayer({
|
|
|
|
'id': 'completion-circles',
|
|
|
|
'type': 'fill',
|
|
|
|
'source': 'completion-circles',
|
|
|
|
'paint': {
|
|
|
|
'fill-color': ['get', 'color'],
|
|
|
|
'fill-opacity': 0.6,
|
|
|
|
'fill-outline-color': '#fff'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// Ajouter une couche pour la bordure
|
|
|
|
map.addLayer({
|
|
|
|
'id': 'completion-circles-outline',
|
|
|
|
'type': 'line',
|
|
|
|
'source': 'completion-circles',
|
|
|
|
'paint': {
|
|
|
|
'line-color': '#0f0',
|
|
|
|
'line-width': 3
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const features = [];
|
2025-06-01 19:52:56 +02:00
|
|
|
data.elements.forEach(element => {
|
2025-06-03 16:19:07 +02:00
|
|
|
const lat = element.lat || (element.center && element.center.lat);
|
|
|
|
const lon = element.lon || (element.center && element.center.lon);
|
2025-06-01 23:35:15 +02:00
|
|
|
|
2025-06-06 11:50:37 +02:00
|
|
|
if (lat && lon) {
|
|
|
|
const completion = calculateCompletion(element);
|
|
|
|
const color = getCompletionColor(completion);
|
|
|
|
|
|
|
|
// Créer un cercle de 20 mètres de rayon (plus petit)
|
|
|
|
const circle = turf.circle([lon, lat], 0.04, { steps: 64, units: 'kilometers' });
|
|
|
|
circle.properties = {
|
|
|
|
color: color,
|
|
|
|
completion: completion,
|
|
|
|
name: element.tags?.name || 'Sans nom',
|
|
|
|
popupContent: createPopupContent(element),
|
|
|
|
center: [lon, lat] // Stocker le centre comme un tableau [lon, lat]
|
|
|
|
};
|
|
|
|
features.push(circle);
|
2025-06-01 18:56:01 +02:00
|
|
|
}
|
2025-06-01 19:52:56 +02:00
|
|
|
});
|
2025-06-06 11:50:37 +02:00
|
|
|
|
|
|
|
// Mettre à jour la source des cercles
|
|
|
|
map.getSource('completion-circles').setData({
|
|
|
|
'type': 'FeatureCollection',
|
|
|
|
'features': features
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fonction pour recalculer les cercles en fonction du zoom
|
|
|
|
function updateCircles() {
|
|
|
|
const zoom = map.getZoom();
|
|
|
|
const newFeatures = [];
|
|
|
|
|
|
|
|
features.forEach(feature => {
|
|
|
|
// Ajuster la taille du cercle en fonction du zoom
|
|
|
|
// Plus le zoom est élevé, plus le cercle est petit
|
|
|
|
const radius = 0.02 / Math.pow(1.5, zoom - 12); // 12 est le niveau de zoom de référence
|
|
|
|
const newCircle = turf.circle(feature.properties.center, radius, { steps: 64, units: 'kilometers' });
|
|
|
|
newCircle.properties = feature.properties;
|
|
|
|
newFeatures.push(newCircle);
|
|
|
|
});
|
|
|
|
|
|
|
|
map.getSource('completion-circles').setData({
|
|
|
|
'type': 'FeatureCollection',
|
|
|
|
'features': newFeatures
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mettre à jour les cercles lors du zoom
|
|
|
|
map.on('zoom', updateCircles);
|
|
|
|
|
|
|
|
// Ajouter les popups sur les cercles
|
|
|
|
map.on('click', 'completion-circles', (e) => {
|
|
|
|
const properties = e.features[0].properties;
|
|
|
|
|
|
|
|
new maplibregl.Popup()
|
|
|
|
.setLngLat(e.lngLat)
|
|
|
|
.setHTML(properties.popupContent)
|
|
|
|
.addTo(map);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Changer le curseur au survol des cercles
|
|
|
|
map.on('mouseenter', 'completion-circles', () => {
|
|
|
|
map.getCanvas().style.cursor = 'pointer';
|
|
|
|
});
|
|
|
|
|
|
|
|
map.on('mouseleave', 'completion-circles', () => {
|
|
|
|
map.getCanvas().style.cursor = '';
|
|
|
|
});
|
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-06 11:50:37 +02:00
|
|
|
function openInJOSM() {
|
|
|
|
if (mapElements.length === 0) {
|
|
|
|
alert('Aucun élément à ouvrir dans JOSM');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nodeIds = [];
|
|
|
|
const wayIds = [];
|
|
|
|
const relationIds = [];
|
|
|
|
|
|
|
|
mapElements.forEach(element => {
|
|
|
|
switch(element.type) {
|
|
|
|
case 'node':
|
|
|
|
nodeIds.push(element.id);
|
|
|
|
break;
|
|
|
|
case 'way':
|
|
|
|
wayIds.push(element.id);
|
|
|
|
break;
|
|
|
|
case 'relation':
|
|
|
|
relationIds.push(element.id);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
let josmUrl = 'http://localhost:8111/load_and_zoom?';
|
|
|
|
const params = [];
|
|
|
|
|
|
|
|
if (nodeIds.length > 0) {
|
|
|
|
params.push(`node${nodeIds.join(',')}`);
|
|
|
|
}
|
|
|
|
if (wayIds.length > 0) {
|
|
|
|
params.push(`way${wayIds.join(',')}`);
|
|
|
|
}
|
|
|
|
if (relationIds.length > 0) {
|
|
|
|
params.push(`relation${relationIds.join(',')}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
josmUrl += params.join('&');
|
|
|
|
window.open(josmUrl, '_blank');
|
|
|
|
}
|
|
|
|
|
2025-06-01 19:52:56 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
2025-06-03 16:19:07 +02:00
|
|
|
console.log('DOMContentLoaded');
|
2025-06-01 19:52:56 +02:00
|
|
|
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
|
|
|
|
2025-06-06 11:50:37 +02:00
|
|
|
document.getElementById('openInJOSM').addEventListener('click', openInJOSM);
|
|
|
|
|
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 %}
|