mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-06-20 01:44:42 +02:00
up infos habitants sur stats
This commit is contained in:
parent
21d4d5b850
commit
918527e15e
16 changed files with 559 additions and 240 deletions
|
@ -37,6 +37,27 @@
|
|||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{% if stats.population %}
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-4 col-12">
|
||||
<span class="badge bg-info">
|
||||
<i class="bi bi-people"></i> Population : {{ stats.population|number_format(0, '.', ' ') }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-md-4 col-12">
|
||||
<span class="badge bg-secondary">
|
||||
<i class="bi bi-shop"></i> 1 lieu pour
|
||||
{% set ratio = (stats.population and stats.places|length > 0) ? (stats.population / stats.places|length)|round(0, 'ceil') : '?' %}
|
||||
{{ ratio|number_format(0, '.', ' ') }} habitants
|
||||
</span>
|
||||
</div>
|
||||
<div class="col-md-4 col-12">
|
||||
<span class="badge bg-success">
|
||||
<i class="bi bi-pencil-square"></i> {{ stats.getAvecNote() }} / {{ stats.places|length }} commerces avec note
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-md-3 col-12">
|
||||
<span class="badge {% if stats.getCompletionPercent() > 85 %}bg-success{% else %}bg-warning{% endif %}">
|
||||
|
@ -198,28 +219,52 @@
|
|||
function calculateCompletion(element) {
|
||||
let completionCount = 0;
|
||||
let totalFields = 0;
|
||||
let missingFields = [];
|
||||
|
||||
const fieldsToCheck = [
|
||||
'name',
|
||||
'contact:street',
|
||||
'contact:housenumber',
|
||||
'opening_hours',
|
||||
'contact:website',
|
||||
'contact:phone',
|
||||
'wheelchair'
|
||||
{name: 'name', label: 'Nom du commerce'},
|
||||
{name: 'contact:street', label: 'Rue'},
|
||||
{name: 'contact:housenumber', label: 'Numéro'},
|
||||
{name: 'opening_hours', label: 'Horaires d\'ouverture'},
|
||||
{name: 'contact:website', label: 'Site web'},
|
||||
{name: 'contact:phone', label: 'Téléphone'},
|
||||
{name: 'wheelchair', label: 'Accessibilité PMR'}
|
||||
];
|
||||
|
||||
fieldsToCheck.forEach(field => {
|
||||
totalFields++;
|
||||
if (element.tags && element.tags[field]) {
|
||||
if (element.tags && element.tags[field.name]) {
|
||||
completionCount++;
|
||||
} else {
|
||||
missingFields.push(field.label);
|
||||
}
|
||||
});
|
||||
|
||||
return (completionCount / totalFields) * 100;
|
||||
return {
|
||||
percentage: (completionCount / totalFields) * 100,
|
||||
missingFields: missingFields
|
||||
};
|
||||
}
|
||||
|
||||
function showMissingFieldsPopup(element) {
|
||||
const completion = calculateCompletion(element);
|
||||
if (completion.percentage < 100) {
|
||||
const popup = new maplibregl.Popup()
|
||||
.setLngLat(element.geometry.coordinates)
|
||||
.setHTML(`
|
||||
<div class="p-2">
|
||||
<h5>Informations manquantes pour ${element.tags?.name || 'ce commerce'}</h5>
|
||||
<ul class="list-unstyled">
|
||||
${completion.missingFields.map(field => `<li><i class="bi bi-x-circle text-danger"></i> ${field}</li>`).join('')}
|
||||
</ul>
|
||||
</div>
|
||||
`);
|
||||
popup.addTo(map);
|
||||
}
|
||||
}
|
||||
|
||||
function createPopupContent(element) {
|
||||
const completion = calculateCompletion(element);
|
||||
let content = `
|
||||
<div class="mb-2">
|
||||
<a class="btn btn-primary" href="/admin/placeType/${element.type}/${element.id}">
|
||||
|
@ -231,6 +276,17 @@
|
|||
</div>
|
||||
`;
|
||||
|
||||
if (completion.percentage < 100) {
|
||||
content += `
|
||||
<div class="alert alert-warning mt-2">
|
||||
<h6>Informations manquantes :</h6>
|
||||
<ul class="list-unstyled mb-0">
|
||||
${completion.missingFields.map(field => `<li><i class="bi bi-x-circle text-danger"></i> ${field}</li>`).join('')}
|
||||
</ul>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
|
||||
content += '<table class="table table-sm">';
|
||||
|
||||
// Ajouter tous les tags
|
||||
|
@ -250,7 +306,7 @@
|
|||
|
||||
elements.forEach(element => {
|
||||
const completion = calculateCompletion(element);
|
||||
const bucketIndex = Math.floor(completion / 10);
|
||||
const bucketIndex = Math.floor(completion.percentage / 10);
|
||||
buckets[bucketIndex]++;
|
||||
});
|
||||
|
||||
|
@ -356,7 +412,7 @@
|
|||
properties: {
|
||||
id: element.id,
|
||||
name: element.tags?.name || 'Sans nom',
|
||||
completion: completion,
|
||||
completion: completion.percentage,
|
||||
center: [lon, lat]
|
||||
},
|
||||
geometry: {
|
||||
|
@ -400,86 +456,33 @@
|
|||
|
||||
function updateMarkers() {
|
||||
// Supprimer tous les marqueurs existants
|
||||
features.forEach(feature => {
|
||||
const layerId = `marker-${feature.properties.id}`;
|
||||
// Supprimer d'abord la couche
|
||||
if (map.getLayer(layerId)) {
|
||||
map.removeLayer(layerId);
|
||||
}
|
||||
// Puis supprimer la source
|
||||
if (map.getSource(layerId)) {
|
||||
map.removeSource(layerId);
|
||||
}
|
||||
});
|
||||
|
||||
// Supprimer tous les marqueurs en goutte existants
|
||||
dropMarkers.forEach(marker => marker.remove());
|
||||
dropMarkers = [];
|
||||
|
||||
if (currentMarkerType === 'circle') {
|
||||
// Afficher les cercles
|
||||
features.forEach(feature => {
|
||||
const layerId = `marker-${feature.properties.id}`;
|
||||
const circle = turf.circle(
|
||||
feature.properties.center,
|
||||
5/1000,
|
||||
{ steps: 64, units: 'kilometers' }
|
||||
);
|
||||
features.forEach(feature => {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'marker';
|
||||
el.style.backgroundColor = getCompletionColor(feature.properties.completion);
|
||||
el.style.width = '15px';
|
||||
el.style.height = '15px';
|
||||
el.style.borderRadius = '50%';
|
||||
el.style.border = '2px solid white';
|
||||
el.style.cursor = 'pointer';
|
||||
|
||||
map.addSource(layerId, {
|
||||
'type': 'geojson',
|
||||
'data': circle
|
||||
});
|
||||
const marker = new maplibregl.Marker(el)
|
||||
.setLngLat(feature.geometry.coordinates)
|
||||
.addTo(map);
|
||||
|
||||
map.addLayer({
|
||||
'id': layerId,
|
||||
'type': 'fill',
|
||||
'source': layerId,
|
||||
'paint': {
|
||||
'fill-color': getCompletionColor(feature.properties.completion),
|
||||
'fill-opacity': 0.7
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Ajouter les popups sur les cercles
|
||||
map.on('click', function(e) {
|
||||
const clickedFeatures = map.queryRenderedFeatures(e.point, {
|
||||
layers: features.map(f => `marker-${f.properties.id}`)
|
||||
});
|
||||
|
||||
if (clickedFeatures.length > 0) {
|
||||
const feature = clickedFeatures[0];
|
||||
const elementId = feature.layer.id.replace('marker-', '');
|
||||
const element = overpassData[elementId];
|
||||
|
||||
if (element) {
|
||||
// Créer le contenu de la popup
|
||||
const popupContent = createPopupContent(element);
|
||||
|
||||
new maplibregl.Popup()
|
||||
.setLngLat(e.lngLat)
|
||||
.setHTML(popupContent)
|
||||
.addTo(map);
|
||||
}
|
||||
// Ajouter l'événement de clic
|
||||
el.addEventListener('click', () => {
|
||||
const element = overpassData[feature.properties.id];
|
||||
if (element) {
|
||||
showMissingFieldsPopup(element);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// Afficher les marqueurs en goutte
|
||||
features.forEach(feature => {
|
||||
const element = overpassData[feature.properties.id];
|
||||
const popupContent = element ? createPopupContent(element) : `<h1>${feature.properties.name}</h1>`;
|
||||
|
||||
const marker = new maplibregl.Marker({
|
||||
color: getCompletionColor(feature.properties.completion)
|
||||
})
|
||||
.setLngLat(feature.properties.center)
|
||||
.setPopup(new maplibregl.Popup({ offset: 25 })
|
||||
.setHTML(popupContent))
|
||||
.addTo(map);
|
||||
dropMarkers.push(marker);
|
||||
});
|
||||
}
|
||||
|
||||
dropMarkers.push(marker);
|
||||
});
|
||||
}
|
||||
|
||||
function draw_circle_containing_all_features(map) {
|
||||
|
@ -722,6 +725,40 @@
|
|||
});
|
||||
|
||||
sortTable();
|
||||
|
||||
// Initialiser les popovers pour les cellules de complétion
|
||||
const completionCells = document.querySelectorAll('.completion-cell');
|
||||
completionCells.forEach(cell => {
|
||||
new bootstrap.Popover(cell, {
|
||||
trigger: 'hover',
|
||||
html: true
|
||||
});
|
||||
|
||||
// Fermer tous les popovers au clic sur une cellule
|
||||
cell.addEventListener('click', function(e) {
|
||||
e.stopPropagation();
|
||||
completionCells.forEach(otherCell => {
|
||||
if (otherCell !== cell) {
|
||||
const popover = bootstrap.Popover.getInstance(otherCell);
|
||||
if (popover) {
|
||||
popover.hide();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Fermer tous les popovers quand on clique ailleurs
|
||||
document.addEventListener('click', function(e) {
|
||||
if (!e.target.closest('.completion-cell')) {
|
||||
completionCells.forEach(cell => {
|
||||
const popover = bootstrap.Popover.getInstance(cell);
|
||||
if (popover) {
|
||||
popover.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function toggleCompletionInfo() {
|
||||
|
|
|
@ -10,7 +10,37 @@
|
|||
{% endif %}
|
||||
</a>
|
||||
</td>
|
||||
<td class="text-right" style="background : rgba(0,255,0,{{ commerce.getCompletionPercentage() / 100 }})">
|
||||
<td class="text-right completion-cell"
|
||||
style="background : rgba(0,255,0,{{ commerce.getCompletionPercentage() / 100 }})"
|
||||
data-bs-toggle="popover"
|
||||
data-bs-trigger="hover"
|
||||
data-bs-html="true"
|
||||
data-bs-content="
|
||||
<div class='p-2'>
|
||||
<h6>Informations manquantes :</h6>
|
||||
<ul class='list-unstyled mb-0'>
|
||||
{% if not commerce.name %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Nom du commerce</li>
|
||||
{% endif %}
|
||||
{% if not commerce.hasAddress() %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Adresse complète</li>
|
||||
{% endif %}
|
||||
{% if not commerce.hasOpeningHours() %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Horaires d'ouverture</li>
|
||||
{% endif %}
|
||||
{% if not commerce.hasWebsite() %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Site web</li>
|
||||
{% endif %}
|
||||
{# {% if not commerce.phone %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Téléphone</li>
|
||||
{% endif %} #}
|
||||
{% if not commerce.hasWheelchair() %}
|
||||
<li><i class='bi bi-x-circle text-danger'></i> Accessibilité PMR</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
"
|
||||
>
|
||||
{{ commerce.getCompletionPercentage() }}
|
||||
</td>
|
||||
<td class="{{ commerce.mainTag ? 'filled' : '' }}">
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue