corrections carte interactive

This commit is contained in:
Valentin 2024-11-04 01:11:34 +01:00
parent e6d39d0dc3
commit 018960837d
3 changed files with 97 additions and 53 deletions

View File

@ -14,6 +14,10 @@
top: 0; top: 0;
} }
#projects_icons svg {
position: absolute;
}
#popup { #popup {
background-color: white; background-color: white;
display: none; display: none;

View File

@ -1,9 +1,10 @@
const franceCoordinates = { const franceCoordinates = {
// https://boundingbox.klokantech.com/
metropole: { metropole: {
latTop: 52.0, // Nord-Ouest (coin supérieur gauche) latTop: 51.1, // Nord-Ouest (coin supérieur gauche)
lonLeft: -5, lonLeft: -5.15,
latBottom: 40.0, // Sud-Est (coin inférieur droit) latBottom: 41.3, // Sud-Est (coin inférieur droit)
lonRight: 11.0, lonRight: 9.65,
}, },
guadeloupe: { guadeloupe: {
latTop: 16.5, latTop: 16.5,
@ -30,40 +31,46 @@ const franceCoordinates = {
lonRight: 55.9, lonRight: 55.9,
}, },
saintPierreEtMiquelon: { saintPierreEtMiquelon: {
latTop: 47.1, latTop: 47.15,
lonLeft: -56.4, lonLeft: -56.41,
latBottom: 46.7, latBottom: 46.74,
lonRight: -56.1, lonRight: -56.13,
}, },
mayotte: { mayotte: {
latTop: -12.6, latTop: -12.63,
lonLeft: 44.9, lonLeft: 45.01,
latBottom: -13, latBottom: -13.02,
lonRight: 45.3, lonRight: 45.3,
}, },
saintBarthelemy: { saintBarthelemy: {
latTop: 17.9, latTop: 17.97,
lonLeft: -62.9, lonLeft: -62.94,
latBottom: 17.8, latBottom: 17.87,
lonRight: -62.7, lonRight: -62.78,
}, },
saintMartin: { saintMartin: {
latTop: 18.1, latTop: 18.12,
lonLeft: -63.1, lonLeft: -63.15,
latBottom: 17.9, latBottom: 18,
lonRight: -62.9, lonRight: -62.97,
}, },
wallisEtFutuna: { futuna: {
latTop: -13.1, latTop: -14.23,
lonLeft: -176.2, lonLeft: -178.18,
latBottom: -13.3, latBottom: -14.36,
lonRight: -176.1, lonRight: -177.99,
},
wallis: {
latTop: -13.21,
lonLeft: -176.25,
latBottom: -13.39,
lonRight: -176.15,
}, },
polynesieFrancaise: { polynesieFrancaise: {
latTop: -17.4, latTop: -17.47,
lonLeft: -149.9, lonLeft: -149.91,
latBottom: -17.1, latBottom: -17.89,
lonRight: -149, lonRight: -149.12,
}, },
nouvelleCaledonie: { nouvelleCaledonie: {
latTop: -19.3, latTop: -19.3,
@ -82,61 +89,67 @@ const localisationMapPlacements = {
right: 87.14, right: 87.14,
}, },
guadeloupe: { guadeloupe: {
top: 88.44, top: 87.8,
left: 33.01, left: 33.01,
bottom: 98.77, bottom: 98.77,
right: 46.25, right: 46.25,
}, },
martinique: { martinique: {
top: 88.96, top: 88.3,
left: 53.26, left: 53.26,
bottom: 98.24, bottom: 98.24,
right: 61.99, right: 61.99,
}, },
guyanne: { guyanne: {
top: 88.09, top: 87.5,
left: 69.09, left: 69.09,
bottom: 99.21, bottom: 99.21,
right: 79.07, right: 79.07,
}, },
reunion: { reunion: {
top: 75.48, top: 75,
left: 89.82, left: 89.6,
bottom: 82.04, bottom: 82.04,
right: 97.88, right: 97.88,
}, },
saintPierreEtMiquelon: { saintPierreEtMiquelon: {
top: 75.03, top: 86,
left: 12.85, left: 2,
bottom: 81.61, bottom: 99.6,
right: 17.85, right: 9,
}, },
mayotte: { mayotte: {
top: 88.61, top: 88,
left: 17.08, left: 17.08,
bottom: 98.68, bottom: 98.68,
right: 26.19, right: 26.19,
}, },
saintBarthelemy: { saintBarthelemy: {
top: 74.95, top: 74.5,
left: 44.81, left: 44.81,
bottom: 82.74, bottom: 82.74,
right: 57.58, right: 57.58,
}, },
saintMartin: { saintMartin: {
top: 74.78, top: 74.2,
left: 23.12, left: 23.12,
bottom: 82.92, bottom: 82.92,
right: 36.08, right: 36.08,
}, },
wallisEtFutuna: { futuna: {
top: 74.95, top: 74.2,
left: 0, left: 0,
bottom: 79.50, bottom: 79,
right: 7.58, right: 7.5,
},
wallis: {
top: 75.8,
left: 9.1,
bottom: 82,
right: 13,
}, },
polynesieFrancaise: { polynesieFrancaise: {
top: 90.19, top: 89.5,
left: 85.12, left: 85.12,
bottom: 97.02, bottom: 97.02,
right: 100, right: 100,
@ -152,12 +165,9 @@ const localisationMapPlacements = {
const projectsIcons = document.querySelectorAll('#projects_icons > svg'); const projectsIcons = document.querySelectorAll('#projects_icons > svg');
for (let icon of projectsIcons) { for (let icon of projectsIcons) {
icon.addEventListener('mouseenter', function() { icon.addEventListener('mouseenter', function() {
console.log("mouse over");
displayPopup(icon); displayPopup(icon);
}); });
icon.addEventListener('mouseleave', function() { icon.addEventListener('mouseleave', function() {
console.log("mouse out");
hidePopup(); hidePopup();
}); });
} }
@ -169,11 +179,16 @@ function placeProjectsIcons(projectsIcons) {
projectsIcons.forEach(icon => { projectsIcons.forEach(icon => {
const iconWidth = icon.getBoundingClientRect().width; const iconWidth = icon.getBoundingClientRect().width;
const lat = parseFloat(icon.dataset.geofieldlat); let lat = parseFloat(icon.dataset.geofieldlat);
const lon = parseFloat(icon.dataset.geofieldlon); let lon = parseFloat(icon.dataset.geofieldlon);
if (lat > 180) lat = lat - 360;
if (lon > 180) lon = lon - 360;
const territory = findTerritory(lat, lon); const territory = findTerritory(lat, lon);
console.log(icon.dataset.title, territory);
if (territory && localisationMapPlacements[territory]) { if (territory && localisationMapPlacements[territory]) {
const territoryBounds = localisationMapPlacements[territory]; const territoryBounds = localisationMapPlacements[territory];
const territoryCoords = franceCoordinates[territory]; const territoryCoords = franceCoordinates[territory];
@ -193,6 +208,8 @@ function placeProjectsIcons(projectsIcons) {
function findTerritory(lat, lon) { function findTerritory(lat, lon) {
for (const [territory, coords] of Object.entries(franceCoordinates)) { for (const [territory, coords] of Object.entries(franceCoordinates)) {
if (lat > 180) lat = lat - 360;
if (lon > 180) lon = lon - 360;
if ( if (
lat <= Math.max(coords.latTop, coords.latBottom) && lat <= Math.max(coords.latTop, coords.latBottom) &&
lat >= Math.min(coords.latTop, coords.latBottom) && lat >= Math.min(coords.latTop, coords.latBottom) &&
@ -205,6 +222,8 @@ function findTerritory(lat, lon) {
return "Unknown territory"; return "Unknown territory";
} }
let isPopupVisible = false;
function displayPopup(icon) { function displayPopup(icon) {
const container = document.querySelector('#sites-map-container'); const container = document.querySelector('#sites-map-container');
@ -216,7 +235,6 @@ function displayPopup(icon) {
popup.querySelector('h3').innerText = icon.dataset.title; popup.querySelector('h3').innerText = icon.dataset.title;
popup.querySelector('p').innerText = icon.dataset.place; popup.querySelector('p').innerText = icon.dataset.place;
popup.style.top = 0; popup.style.top = 0;
popup.style.left = 0; popup.style.left = 0;
@ -227,6 +245,8 @@ function displayPopup(icon) {
setTimeout(() => { setTimeout(() => {
popup.style.opacity = 1; popup.style.opacity = 1;
}, 10); }, 10);
isPopupVisible = true;
} }
function hidePopup(){ function hidePopup(){
@ -234,10 +254,30 @@ function hidePopup(){
popup.style.opacity = 0; popup.style.opacity = 0;
setTimeout(() => { setTimeout(() => {
popup.style.display = 'none'; if (!isPopupVisible) popup.style.display = 'none';
isPopupVisible = false;
}, 300); }, 300);
} }
placeProjectsIcons(projectsIcons); placeProjectsIcons(projectsIcons);
// debugMapPlacement();
window.addEventListener('resize', placeProjectsIcons(projectsIcons)); window.addEventListener('resize', placeProjectsIcons(projectsIcons));
function debugMapPlacement() {
const container = document.querySelector('#sites-map-container');
for (let territory of Object.keys(localisationMapPlacements)) {
const debugDiv = document.createElement('div');
debugDiv.style.position = 'absolute';
debugDiv.innerText = territory;
debugDiv.style.fontSize = '10px';
debugDiv.style.top = localisationMapPlacements[territory].top + '%';
debugDiv.style.left = localisationMapPlacements[territory].left + '%';
debugDiv.style.width = (localisationMapPlacements[territory].right - localisationMapPlacements[territory].left) + '%';
debugDiv.style.height = (localisationMapPlacements[territory].bottom - localisationMapPlacements[territory].top) + '%';
debugDiv.style.backgroundColor = 'rgba(255, 0, 0, 0.5)';
debugDiv.style.pointerEvents = 'none';
container.appendChild(debugDiv);
}
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 80 KiB