refacto fonctions
This commit is contained in:
parent
1b0d2d425d
commit
9b09b0d59d
8 changed files with 191 additions and 163 deletions
|
@ -61,16 +61,6 @@ const genererCouleurPastel = () => {
|
|||
};
|
||||
|
||||
|
||||
function updateMapHeightForLargeScreens() {
|
||||
|
||||
const mapFound = document.querySelector('#map');
|
||||
if (mapFound && window.innerHeight > 800 && window.innerWidth > 800) {
|
||||
mapFound.style.height = '80vh';
|
||||
} else {
|
||||
console.log('window.innerHeight', window.innerHeight);
|
||||
}
|
||||
}
|
||||
|
||||
async function searchInseeCode(query) {
|
||||
try {
|
||||
|
||||
|
@ -90,4 +80,86 @@ async function searchInseeCode(query) {
|
|||
console.error('Erreur lors de la recherche du code INSEE:', error);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function updateMapHeightForLargeScreens() {
|
||||
|
||||
const mapFound = document.querySelector('#map');
|
||||
if (mapFound && window.innerHeight > 800 && window.innerWidth > 800) {
|
||||
|
||||
mapFound.style.height = window.innerWidth * 0.8 + 'px';
|
||||
} else {
|
||||
console.log('window.innerHeight', window.innerHeight);
|
||||
}
|
||||
}
|
||||
|
||||
// lister les changesets de l'utilisateur osm-commerces
|
||||
async function listChangesets() {
|
||||
// Ajouter le header Accept pour demander du JSON
|
||||
const options = {
|
||||
headers: {
|
||||
'Accept': 'application/json'
|
||||
}
|
||||
};
|
||||
const changesets = await fetch('https://api.openstreetmap.org/api/0.6/changesets?display_name=osm-commerce-fr', options);
|
||||
const data = await changesets.json();
|
||||
console.log(data.changesets.length);
|
||||
|
||||
// Grouper les changesets par période
|
||||
const now = new Date();
|
||||
const last24h = new Date(now - 24 * 60 * 60 * 1000);
|
||||
const last7days = new Date(now - 7 * 24 * 60 * 60 * 1000);
|
||||
const last30days = new Date(now - 30 * 24 * 60 * 60 * 1000);
|
||||
|
||||
const stats = {
|
||||
last24h: 0,
|
||||
last7days: 0,
|
||||
last30days: 0
|
||||
};
|
||||
|
||||
data.changesets.forEach(changeset => {
|
||||
const changesetDate = new Date(changeset.closed_at);
|
||||
|
||||
if (changesetDate >= last24h) {
|
||||
stats.last24h++;
|
||||
}
|
||||
if (changesetDate >= last7days) {
|
||||
stats.last7days++;
|
||||
}
|
||||
if (changesetDate >= last30days) {
|
||||
stats.last30days++;
|
||||
}
|
||||
});
|
||||
|
||||
// Afficher les statistiques
|
||||
const historyDiv = document.getElementById('userChangesHistory');
|
||||
if (historyDiv) {
|
||||
historyDiv.innerHTML = `
|
||||
<div id="changesets_history">
|
||||
<p>Changesets créés :</p>
|
||||
<div class="row">
|
||||
<div class="col-6">Dernières 24h :</div> <div class="col-6 text-right">${stats.last24h}</div>
|
||||
<div class="col-6">7 derniers jours :</div> <div class="col-6 text-right">${stats.last7days}</div>
|
||||
<div class="col-6">30 derniers jours :</div> <div class="col-6 text-right">${stats.last30days}</div>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function openInPanoramax() {
|
||||
const center = map.getCenter();
|
||||
const zoom = map.getZoom();
|
||||
const panoramaxUrl = `https://api.panoramax.xyz/?focus=map&map=${zoom}/${center.lat}/${center.lng}`;
|
||||
window.open(panoramaxUrl);
|
||||
}
|
||||
|
||||
window.openInPanoramax = openInPanoramax;
|
||||
window.listChangesets = listChangesets;
|
||||
window.updateMapHeightForLargeScreens = updateMapHeightForLargeScreens;
|
||||
window.searchInseeCode = searchInseeCode;
|
||||
window.genererCouleurPastel = genererCouleurPastel;
|
||||
window.check_validity = check_validity;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue