我如何淡出的谷歌地图了一圈,x秒我已经把它添加到地图后?(How do I fade out a c

2019-07-17 15:22发布

我基本上脑子里想的是什么谷歌在做这个例子

每一秒钟我想在某些坐标的社交圈,然后他们慢慢淡出。 我已经成功地圆添加到地图:

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);
}

但我怎么也找不到他们淡出的任何地方。 已经尝试通过谷歌地图API文档,甚至在这个例子的代码去,但也许我错过了什么。

Answer 1:

为了淡化出来,你需要减少填充不透明度和行程,直到它是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});
  }
}  



文章来源: How do I fade out a circle in a Google Map, x seconds after I've added it to the map?