我基本上想到的是Google在this示例中所做的事情
每一秒我想在某些坐标处添加圆圈然后慢慢淡出它们。我已设法在地图中添加圈子:
var citymap = {};
citymap['chicago'] = {
center: new google.maps.LatLng(41.878113, -87.629798),
population: 100
};
citymap['amsterdam'] = {
center: new google.maps.LatLng(52.878113, 5.629798),
population: 40
};
citymap['paris'] = {
center: new google.maps.LatLng(48.9021449, 2.4699208),
population: 100
};
citymap['moscow'] = {
center: new google.maps.LatLng(56.021369, 37.9650909),
population: 100
};
citymap['newyork'] = {
center: new google.maps.LatLng(40.9152414, -73.70027209999999),
population: 80
};
citymap['losangeles'] = {
center: new google.maps.LatLng(34.3373061, -118.1552891),
population: 65
}
for (var city in citymap) {
var populationOptions = {
strokeColor: "#900057",
strokeOpacity: 1,
strokeWeight: 1,
fillColor: "#900057",
fillOpacity: 0.35,
map: map,
clickable: false,
center: citymap[city].center,
radius: citymap[city].population * 2000
};
cityCircle = new google.maps.Circle(populationOptions);
}
但是我找不到如何在任何地方淡出它们。已经尝试过浏览Google Maps API文档甚至示例代码,但也许我错过了一些东西。
答案 0 :(得分:4)
要淡出它们,您需要降低填充和笔触的不透明度,直到它为0.0。
setInterval(fadeCityCircles,1000);
function fadeCityCircles() {
for (var city in citymap) {
var fillOpacity = citymap[city].cityCircle.get("fillOpacity");
fillOpacity -= 0.02;
if (fillOpacity < 0) fillOpacity =0.0;
var strokeOpacity = citymap[city].cityCircle.get("strokeOpacity");
strokeOpacity -= 0.05;
if (strokeOpacity < 0) strokeOpacity =0.0;
citymap[city].cityCircle.setOptions({fillOpacity:fillOpacity, strokeOpacity:strokeOpacity});
}
}