Javascript 谷歌地图中的淡入圆圈
在我的地图上,我有这样一个节点/圆是在某个位置绘制的,当点击这个节点时,其他相关的节点就会出现在附近。然而,我希望它们在大约一秒钟后消失,而不是突然出现。我已经看过这个解决方案,但我真的不明白它是如何转化为我的代码的。有没有一个简单的方法可以做到这一点Javascript 谷歌地图中的淡入圆圈,javascript,google-maps-api-3,dom-events,Javascript,Google Maps Api 3,Dom Events,在我的地图上,我有这样一个节点/圆是在某个位置绘制的,当点击这个节点时,其他相关的节点就会出现在附近。然而,我希望它们在大约一秒钟后消失,而不是突然出现。我已经看过这个解决方案,但我真的不明白它是如何转化为我的代码的。有没有一个简单的方法可以做到这一点 ... function initialize() { for(var num = 0; num < lat.length; num++) {
...
function initialize()
{
for(var num = 0; num < lat.length; num++)
{
nodeInfo[num] =
{
center: new google.maps.LatLng(lat[num], lon[num])
}
}
// Styles
var styles = [
{
stylers: [
{
hue: "#2222EE"
},
{
saturation: -40
}
]
},
{
featureType: "road",
elementType: "geometry",
stylers: [
{
lightness: 100
},
{
visibility: "simplified"
}
]
},
{
featureType: "road",
elementType: "labels",
stylers: [
{
visibility: "off"
}
]
},
{
featureType: "transit.station.bus",
elementType: "labels.icon",
stylers: [
{
visibility: "off"
}
]
}
];
var styledMap = new google.maps.StyledMapType(styles,
{name: "Styled Map"});
// Options for map
var mapOptions =
{
center: new google.maps.LatLng(42.35791, -71.063157),
zoom: 17,
mapTypeControlOptions:
{
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
}
};
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
nodeDisplay();
}
function nodeDisplay()
{
var drawNode;
for(var i in nodeInfo)
{
if(i >= 1)
{
if(nodeSelect == true)
{
drawNode = {
strokeColor: '#0000FF',
fillColor: '#0000FF',
strokeWeight: 2,
fillOpacity: 1,
map: map,
center: nodeInfo[i].center,
radius: 4,
visible: true
};
}
else
{
drawNode = {
strokeColor: '#0000FF',
fillColor: '#0000FF',
strokeWeight: 2,
fillOpacity: 1,
map: map,
center: nodeInfo[i].center,
radius: 4,
visible: false
};
}
}
else
{
drawNode = {
strokeColor: '#FF0000',
fillColor: '#FF0000',
strokeWeight: 2,
fillOpacity: 1,
map: map,
center: nodeInfo[i].center,
radius: 6
};
}
node[i] = new google.maps.Circle(drawNode);
attachMessage(i);
}
}
function clearOverlays()
{
for(var i in nodeInfo)
{
if(i > 0)
{
node[i].setMap(null);
}
}
}
function attachMessage(number)
{
var message = "Hello. This is node number " + number + ".";
var infowindow = new google.maps.InfoWindow({
size: new google.maps.Size(50, 50)
});
infowindow.content = message;
google.maps.event.addListener(node[number], 'click', function()
{
//infowindow.open(map, node[number]);
clearOverlays();
nodeSelect = !nodeSelect;
nodeDisplay();
});
}
google.maps.event.addDomListener(window, 'load', initialize);
。。。
函数初始化()
{
for(var num=0;num=1)
{
if(nodeSelect==true)
{
drawNode={
strokeColor:“#0000FF”,
填充颜色:“#0000FF”,
冲程重量:2,
不透明度:1,
地图:地图,
中心:nodeInfo[i]。中心,
半径:4,
可见:正确
};
}
其他的
{
drawNode={
strokeColor:“#0000FF”,
填充颜色:“#0000FF”,
冲程重量:2,
不透明度:1,
地图:地图,
中心:nodeInfo[i]。中心,
半径:4,
可见:假
};
}
}
其他的
{
drawNode={
strokeColor:“#FF0000”,
填充颜色:'#FF0000',
冲程重量:2,
不透明度:1,
地图:地图,
中心:nodeInfo[i]。中心,
半径:6
};
}
node[i]=新的google.maps.Circle(drawNode);
附件(一);
}
}
函数clearOverlays()
{
用于(节点信息中的变量i)
{
如果(i>0)
{
节点[i].setMap(空);
}
}
}
函数附件消息(编号)
{
var message=“你好,这是节点号”+number+”;
var infowindow=new google.maps.infowindow({
大小:新谷歌地图大小(50,50)
});
infowindow.content=消息;
google.maps.event.addListener(节点[number],'click',函数()
{
//打开(地图,节点[编号]);
clearOverlays();
nodeSelect=!nodeSelect;
nodeDisplay();
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
淡入圆圈(从零开始,到一结束):
代码片段:
var nodeSelect=true;
//波士顿42.3584308,-71.0597732
var lat=[42.350542,42.353036
function polygon_fadein(polygon, seconds, callback){
polygon.setOptions({fillOpacity:0, strokeOpacity:0});
// The "fade task" runs every 50 ms, seconds is the total time to fade,
// multiplied by approximately 1000 to turn it into milliseconds.
var fill = 50/(seconds*999);
var stroke = 50/(seconds*999);
var fadein = setInterval(function(){
if((polygon.get("strokeOpacity") > 0.99) && (polygon.get("fillOpacity") > 0.99)){
clearInterval(fadein);
if(typeof(callback) == 'function')
callback();
return;
}
polygon.setOptions({
'fillOpacity': Math.min(1.0, polygon.fillOpacity+fill),
'strokeOpacity': Math.min(1.0, polygon.strokeOpacity+stroke)
});
}, 50);
}