in this javascript for leaflet.js I'm trying to animate a marker along a polyline -…
Jump to turn (6)
- 1in this javascript for leaflet.js I'm trying to animate a marker along a polylin
- 2the updated line is missing
- 3the line with the updates is still missing
- 4here is your answer 'My apologies for the oversight. Here is the corrected line
- 5my animated marker isn't working. I get an error that the 'marker is not defined
- 6I no get an error 'Uncaught TypeError: Cannot read properties of undefined (read
- User
in this javascript for leaflet.js I'm trying to animate a marker along a polyline - 'trainButton.addEventListener("click", function () { if (isLineDrawn) { // Check if a line is drawn before animating the marker // Create a marker (if it doesn't exist already) if (!marker) { marker = L.marker(clickedPoints[0].getLatLng()).addTo(map); }
codeconst animationFunction = function(progress) { let currentLatLng = marker.getLatLng(); const nextLatLng = clickedPoints[Math.round(progress * (clickedPoints.length - 1))].getLatLng(); marker.setLatLng(L.latLngLinear interpolate(currentLatLng, nextLatLng, progress)); // Fixed missing closing parenthesis here }; let animation = new L.LinearAnimation(marker, [0, 1], animationFunction, { duration: 2000 }); // Adjust duration as needed in milliseconds animation.play();} else { console.log("Please draw a line first by clicking on two cities."); } });' however it has an error