I'm developing a script to encourage the growth / reduction of the radius of a circle in the Google Maps API. But only 1 circle is the one that is animated, first I scroll the array drawing the circles in the map followed by I give animation (reduction and enlargement) of the radius. The solution might be to include an interval within the loop. I look forward to your help, thank you.
function initialize() {
var _radius = 500;
var rMin = _radius * 4/5;
var rMax = _radius;
var direction = 1;
var citymap = { chicago: { center: {lat: -12.008711, lng: -77.053376} }, newyork: { center: {lat: -12.01075, lng: -77.070083} }, losangeles: { center: {lat: -12.005359, lng: -77.06835} }, vancouver: { center: {lat: -11.990886, lng: -77.068101} }};
var mapOptions = {
center: {lat: -12.004129, lng: -77.056904},
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
for (var city in citymap) {
var circleOption = {
center: citymap[city].center,
fillColor: '#3878c7',
fillOpacity: 0.6,
map: map,
radius: 500,
strokeColor: '#3878c7',
strokeOpacity: 1,
strokeWeight: 0.5
};
var circle = new google.maps.Circle(circleOption);
}
var circleTimer = setInterval(function(){
var radius = circle.getRadius();
if ((radius > rMax) || (radius < rMin)) {
direction *= -1;
}
var _par = (radius/_radius)-0.7;
circleOption.radius = radius + direction * 10;
circleOption.fillOpacity = 0.6 * _par;
circle.setOptions(circleOption);
}, 20);
}
google.maps.event.addDomListener(window, 'load', initialize);
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map { height: 90%; width: 90% }
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<!--script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script-->
<script type="text/javascript">
</script>
</head>
<body>
<div id='map'></div>
</body>
</html>
Thank You Regards