这是我的小提琴。http://jsfiddle.net/tp2f74sz/
基本上,我想实现的是,当我点击它时,它会变为绿色,但当我再次点击时,我想再次将其变回黑色现在当我点击关闭图标时它会改变
请帮助
感谢
var infowindow = new google.maps.InfoWindow({
id: this.id,
content:this.html,
pixelOffset: new google.maps.Size(0,-30),
position:this.getPosition({pixelOffset: new google.maps.Size(500,0)})
});
var markerrr = new google.maps.Marker({
position: location,
map: map,
icon: 'https://www.google.com/mapfiles/marker_green.png'
});
google.maps.event.addListenerOnce(infowindow, 'closeclick', function(){
markers[this.id].setVisible(true);
markers[this.id].setIcon('https://www.google.com/mapfiles/marker_black.png');
});
this.setVisible(true);
infowindow.open(map);
this.setIcon('https://www.google.com/mapfiles/marker_green.png');
});
}
在click
侦听器中,检查正在显示的图标,然后使用.setIcon()
将其切换到另一个:http://jsfiddle.net/7zqde3kn/
google.maps.event.addListener(markers[i], 'click', function() {
if (this.icon.includes('black')) {
this.setIcon('https://www.google.com/mapfiles/marker_green.png');
} else {
this.setIcon('https://www.google.com/mapfiles/marker_black.png');
}
...
}