在谷歌地图javascript api上显示/隐藏圆圈
试图在用户将鼠标悬停在谷歌地图上时显示谷歌地图圆圈,并在用户鼠标滑出时将其隐藏。这段代码用于隐藏mouseout上的圆,但不重新显示mouseover上的圆。我还尝试了circle.setMap(null)和circle.setMap(map),这就是我将map作为参数传递给showHide函数的原因在谷歌地图javascript api上显示/隐藏圆圈,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,试图在用户将鼠标悬停在谷歌地图上时显示谷歌地图圆圈,并在用户鼠标滑出时将其隐藏。这段代码用于隐藏mouseout上的圆,但不重新显示mouseover上的圆。我还尝试了circle.setMap(null)和circle.setMap(map),这就是我将map作为参数传递给showHide函数的原因 var buildings = {}; buildings['Tinsley'] = { center: new google.maps.LatLng(30.512028, -90.466
var buildings = {};
buildings['Tinsley'] = {
center: new google.maps.LatLng(30.512028, -90.466363),
radius: 20,
description: "<div>Tinsley Hall</div>",
desMaxWidth: 500,
};
buildings['Pottle'] = {
center: new google.maps.LatLng(30.513184, -90.467562),
radius: 40,
description: "<div>Pottle Hall</div>",
desMaxWidth: 500,
};
function initialize() {
var southeastern = new google.maps.LatLng(30.5153382,-90.4676681);
var mapOptions = {
zoom: 17,
center: southeastern
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var ctaLayer = new google.maps.KmlLayer({
url: 'http://www.southeastern.edu/_new-resources/includes/slu.kml'
});
ctaLayer.setMap(null);
var counter = 0;
for (var building in buildings) {
var buildingCircle = {
strokeColor: 'darkgreen',
strokeOpacity: 0.3,
strokeWeight: 3,
clickable: true,
fillColor: 'gold',
fillOpacity: 0.35,
map: map,
visible: true,
center: buildings[building].center,
radius: buildings[building].radius,
};
markerCircle = new google.maps.Circle(buildingCircle);
attachInfoWindow(map, markerCircle, buildings[building].description);
showHideCircle(map, markerCircle);
counter++
}
}
function attachInfoWindow(map, circle, info){
var infowindow = new google.maps.InfoWindow({
content: info
});
google.maps.event.addListener(circle, 'click', function(ev) {
infowindow.setPosition(circle.getCenter());
infowindow.open(map);
});
}
function showHideCircle(map, circle){
google.maps.event.addListener(circle, 'mouseover', function(){
circle.setVisible(true);
});
google.maps.event.addListener(circle, 'mouseout', function(){
circle.setVisible(false);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
var-buildings={};
建筑物['Tinsley']={
中心:新google.maps.LatLng(30.512028,-90.466363),
半径:20,
描述:“廷斯利大厅”,
最大宽度:500,
};
建筑物['Pottle']={
中心:新google.maps.LatLng(30.513184,-90.467562),
半径:40,
描述:“波特大厅”,
最大宽度:500,
};
函数初始化(){
var Southwestern=new google.maps.LatLng(30.5153382,-90.4676681);
变量映射选项={
缩放:17,
中心:东南部
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var ctaLayer=new google.maps.KmlLayer({
网址:'http://www.southeastern.edu/_new-resources/includes/slu.kml'
});
ctaLayer.setMap(空);
var计数器=0;
用于(建筑物中的var建筑物){
var buildingCircle={
strokeColor:“暗绿色”,
笔划不透明度:0.3,
冲程重量:3,
可点击:正确,
fillColor:“金色”,
不透明度:0.35,
地图:地图,
可见:对,
中心:建筑物[建筑物]。中心,
半径:建筑物[建筑物]。半径,
};
markerCircle=newgoogle.maps.Circle(buildingCircle);
附件窗口(地图、标记圆、建筑物[建筑物]。说明);
showHideCircle(地图、标记圆);
柜台++
}
}
功能附件FOWindow(地图、圆圈、信息){
var infowindow=new google.maps.infowindow({
内容:信息
});
google.maps.event.addListener(圆圈,'click',函数(ev){
infowindow.setPosition(circle.getCenter());
打开(地图);
});
}
函数showHideCircle(地图、圆){
google.maps.event.addListener(圆圈'mouseover',function(){
circle.setVisible(true);
});
google.maps.event.addListener(圈出'mouseout',function(){
圆形。设置可见(假);
});
}
google.maps.event.addDomListener(窗口“加载”,初始化);
如果要使用鼠标悬停/out,则不能使用“可见”或从地图中删除圆。将fillOpacity和stokeOpacity设置为0以隐藏圆
function showHideCircle(map, circle) {
google.maps.event.addListener(circle, 'mouseout', function () {
circle.setOptions({fillOpacity:0, strokeOpacity:0});
});
google.maps.event.addListener(circle, 'mouseover', function () {
circle.setOptions({fillOpacity: 0.35, strokeOpacity:0.3});
});
}
代码段:
var-buildings={};
建筑物['Tinsley']={
中心:新google.maps.LatLng(30.512028,-90.466363),
半径:20,
描述:“廷斯利大厅”,
最大宽度:500,
};
建筑物['Pottle']={
中心:新google.maps.LatLng(30.513184,-90.467562),
半径:40,
描述:“波特大厅”,
最大宽度:500,
};
函数初始化(){
var Southwestern=new google.maps.LatLng(30.5153382,-90.4676681);
变量映射选项={
缩放:17,
中心:东南部
}
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
var ctaLayer=new google.maps.KmlLayer({
网址:'http://www.southeastern.edu/_new-resources/includes/slu.kml'
});
ctaLayer.setMap(空);
var计数器=0;
用于(建筑物中的var建筑物){
var buildingCircle={
strokeColor:“暗绿色”,
笔划不透明度:0.3,
冲程重量:3,
可点击:正确,
fillColor:“金色”,
不透明度:0.35,
地图:地图,
可见:对,
中心:建筑物[建筑物]。中心,
半径:建筑物[建筑物]。半径,
};
markerCircle=newgoogle.maps.Circle(buildingCircle);
附件窗口(地图、标记圆、建筑物[建筑物]。说明);
showHideCircle(地图、标记圆);
柜台++
}
}
功能附件FOWindow(地图、圆圈、信息){
var infowindow=new google.maps.infowindow({
内容:信息
});
google.maps.event.addListener(圆圈,'click',函数(ev){
infowindow.setPosition(circle.getCenter());
打开(地图);
});
}
函数showHideCircle(地图、圆){
google.maps.event.addListener(圈出'mouseout',function(){
circle.setOptions({
不透明度:0,
笔划不透明度:0
});
});
google.maps.event.addListener(圆圈'mouseover',function(){
circle.setOptions({
不透明度:0.35,
笔划不透明度:0.3
});
});
}
google.maps.event.addDomListener(窗口“加载”,初始化)代码>
html,
身体,
#地图画布{
身高:100%;
宽度:100%;
边际:0px;
填充:0px
}