// Créer la carte
var map = L.map('map').setView([48.864716, 2.294694], 13);
// Ajouter une couche de tuiles
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
}).addTo(map);
// Définir les nœuds (positions)
var nodes = [
[48.864716, 2.294694], // Nœud 1
[48.865572, 2.296447], // Nœud 2
[48.866207, 2.299029], // Nœud 3
[48.865046, 2.302393] // Nœud 4
];
// Créer des cercles pour représenter les nœuds
var nodeMarkers = nodes.map(function(latlng) {
return L.circleMarker(latlng, { radius: 8, color: 'blue' }).addTo(map);
});
// Fonction pour animer le cercle représentant le robot
function animateRobot(robotMarker, path, index) {
// Convertir les coordonnées du chemin en points de la carte
var pos = map.latLngToLayerPoint(path[index]);
pos.y -= 12; // Ajustez la position pour le centre du cercle
// Créer une animation de position
var fx = new L.PosAnimation();
fx.once('end', function() {
// Vérifier si l'index a atteint la fin du chemin
if (index < path.length - 1) {
// Passer au prochain nœud
animateRobot(robotMarker, path, index + 1);
} else {
// Redémarrer l'animation à partir du premier nœud
animateRobot(robotMarker, path, 0);
}
});
// Récupérer l'élément SVG du cercle
var circle = robotMarker._path;
if (circle) {
fx.run(circle, pos, 0.5); // 0.5 est la durée de l'animation
}
}
// Créer un cercle pour représenter le robot
var robotMarker = L.circleMarker(nodes[0], { radius: 12, color: 'red' }).addTo(map);
// Démarrer l'animation
animateRobot(robotMarker, nodes, 0);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.