Fist Push
This commit is contained in:
parent
dd63653413
commit
cab9de1e90
118 changed files with 364726 additions and 0 deletions
46
public/scripts/overlays/overlaysPlayer.js
Normal file
46
public/scripts/overlays/overlaysPlayer.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import customIcons from '../modules/iconsMap.js';
|
||||
import { map } from "../map.js";
|
||||
// Dictionnaire pour stocker les marqueurs des personnages
|
||||
var characterMarkers = {};
|
||||
// Fonction pour récupérer les positions des personnages
|
||||
export default function fetchCharacterLocations() {
|
||||
fetch("/characterloc") // Effectuer une requête GET vers /characterloc
|
||||
.then((response) => response.json()) // Convertir la réponse en JSON
|
||||
.then((data) => {
|
||||
// Parcourir les données et afficher chaque position de personnage
|
||||
data.forEach((character) => {
|
||||
updateCharacterMarker(
|
||||
character.literalValue,
|
||||
character.locy,
|
||||
character.locx
|
||||
);
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching character locations:", error);
|
||||
});
|
||||
}
|
||||
// Fonction pour créer ou mettre à jour un marqueur de personnage
|
||||
function updateCharacterMarker(characterId, lat, lng) {
|
||||
// Vérifier si le marqueur existe déjà
|
||||
if (characterMarkers[characterId]) {
|
||||
// Mettre à jour la position du marqueur existant
|
||||
characterMarkers[characterId].setLatLng([lat, lng]);
|
||||
} else {
|
||||
// Créer un nouveau marqueur
|
||||
var marker = L.marker([lat, lng], { icon: customIcons.greenPlayer }).bindPopup(characterId).addTo(map);
|
||||
// Stocker le marqueur dans le dictionnaire
|
||||
characterMarkers[characterId] = marker;
|
||||
}
|
||||
}
|
||||
// Fonction pour récupérer les positions des personnages
|
||||
async function getPlayersLocations() {
|
||||
const url = `/characterloc`;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
let data = await response.json();
|
||||
return data;
|
||||
} catch (error) {
|
||||
console.error(`Error fetching ${key} data:`, error);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue