Animating Symbols
HTML
<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap">
</script>
CSS
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html,
body {
height: 100%;
margin: 0;
padding: 0;
}
JavaScript
// This example adds an animated symbol to a polyline.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 20.291,
lng: 153.027
},
zoom: 5,
mapTypeId: 'terrain'
});
// Define the symbol, using one of the predefined paths ('CIRCLE')
// supplied by the Google Maps JavaScript API.
var lineSymbol = {
path: svgTrans(0),
fillColor: '#ffe5ad',
fillOpacity: 1,
scale: .5,
anchor: google.maps.Point(1, 21),
strokeColor: '#ffe5ad',
strokeWeight: 8
};
// Create the polyline and add the symbol to it via the 'icons' property.
var line = new google.maps.Polyline({
path: [{
lat: 22.291,
lng: 153.027
}, {
lat: 12.291,
lng: 153.027
}, {
lat: 12.291,
lng: 143.027
}, {
lat: 22.291,
lng: 143.027
}, {
lat: 22.291,
lng: 153.027
}],
icons: [{
icon: lineSymbol,
offset: '0%'
}],
geodesic: true,
strokeColor: "#feca57",
strokeOpacity: 1,
strokeWeight: 8,
map: map
});
animateCircle(line);
}
// Use the DOM setInterval() function to change the offset of the symbol
// at fixed intervals.
function animateCircle(line) {
var remove = window.setInterval(function() {
var count = 0;
let refreshRate = 20;
let countFunc = EasingFunctions.easeInOutQuint;
let perc = 0
var now, before = new Date();
var move = window.setInterval(function() {
now = new Date();
var elapsedTime = (now.getTime() - before.getTime());
var icons = line.get('icons');
if (elapsedTime > refreshRate + 5000) {
// reset if navigate away from tab
count = 0.005
window.clearInterval(move)
} else {
count = count < 1 ? (count + 0.005) : 0;
}
perc = countFunc(count) * 100 <= 100 ? countFunc(count) * 100 : countFunc(count) * 100 - 100
perc = perc >= 0 ? perc : 100 + perc
perc === 0...