Javascript 地图图标不显示';单击一个新的时,不会返回到正常大小
单击新标记时,我的单击功能不会将地图图标返回到其原始大小,我似乎不明白为什么。以下是我使用的代码:Javascript 地图图标不显示';单击一个新的时,不会返回到正常大小,javascript,html,google-maps,Javascript,Html,Google Maps,单击新标记时,我的单击功能不会将地图图标返回到其原始大小,我似乎不明白为什么。以下是我使用的代码: var infowindow = new google.maps.InfoWindow({ disableAutoPan: true, isHidden:false, closeBoxURL: "", pane: "mapPane", enableEventPropagation: true }); var marke
var infowindow = new google.maps.InfoWindow({
disableAutoPan: true,
isHidden:false,
closeBoxURL: "",
pane: "mapPane",
enableEventPropagation: true
});
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng( locations[i][1], locations[i][2] ),
map: map,
id: (locations[i][3]),
icon: (locations[i][4]),
optimize: false,
title: (locations[i][0]),
description: (locations[i][6])
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0], locations[i][6]);
infowindow.open(map, marker);
map.setCenter(marker.getPosition());
sidebar.open('destination' + [i]);
marker.setIcon(locations[i][5]);
};
})(marker, i));
markers.push(marker);
}
var infowindow=new google.maps.infowindow({
是的,
伊希登:错,
closeBoxURL:“”,
窗格:“地图窗格”,
enableEventPropagation:true
});
var标记,i;
对于(i=0;i
单击时,图标会像我希望的那样放大,并显示“信息”窗口。当我单击另一个图标时,信息窗口关闭上一个标记并移动到新标记,但上一个标记仍然很大
地图上有多个不同类别的标记图像,所以我不能只指定一个图标并更改大小。在数据库中,每个标记有2个图像大小,较小的称为“(位置[I][4]),较大的称为“(位置[I][5])
有什么建议吗?您可以尝试做的是在构建每个标记时为它们设置进一步的自定义属性,这些属性将在
单击处理程序中作为该标记的属性提供。在某种程度上,您已经通过包括自定义属性(如优化
)开始了这一过程,这一过程又向前推进了一步,尽管可能是这样的(完全未经测试的)方法:
var infowindow = new google.maps.InfoWindow({
disableAutoPan: true,
isHidden:false,
closeBoxURL: '',
pane: 'mapPane',
enableEventPropagation: true
});
var clickhandler=function(e){
/* set properties of the InfoWindow */
infowindow.setContent( this.content );
infowindow.open( map, this );
map.setCenter( this.getPosition() );
/* Custom tasks */
sidebar.open('destination' + this.index );
/* inspect the marker `images` property to get new image - large */
this.setIcon( this.images.large );
};
var toggleimages=function(){
markers.forEach( mkr=>{
mkr.setIcon( mkr.images.small )
})
};
var marker,properties;
for ( var i = 0; i < locations.length; i++ ) {
/*
Create the standard markr properties with a few "custom" properties
added to aid the icon swapping.
New properties:
images
content
index
Moved outwith the new Marker constructor for easier reading only
*/
properties={
index:i,
position: new google.maps.LatLng( locations[i][1], locations[i][2] ),
map: map,
id:locations[i][3],
icon:locations[i][4],
optimize:false,
title:locations[i][0],
description:locations[i][6],
images:{
large:locations[i][5],
small:locations[i][4]
},
content:[ locations[i][0], locations[i][6] ].join(', ')
};
/* create the marker */
marker = new google.maps.Marker( properties );
google.maps.event.addListener( marker, 'click', function(e){
toggleimages.call(this,e); // modify any other markers that have the large icon before
clickhandler.call(this,e); // invoke clickhandler and set new large icon
}.bind( marker ));
markers.push( marker );
}
var infowindow=new google.maps.infowindow({
是的,
伊希登:错,
closeBoxURL:“”,
窗格:“地图窗格”,
enableEventPropagation:true
});
var clickhandler=函数(e){
/*设置信息窗口的属性*/
infowindow.setContent(this.content);
打开(地图,这个);
map.setCenter(this.getPosition());
/*自定义任务*/
侧栏打开('destination'+this.index);
/*检查标记“images”属性以获取新图像-大*/
this.setIcon(this.images.large);
};
var toggleimages=函数(){
markers.forEach(mkr=>{
mkr.setIcon(mkr.images.small)
})
};
var标记,属性;
对于(变量i=0;i