如何在 Google 地图 API v3 中的标记 images/colors 之间切换
How to toggle between marker images/colors in Google Maps API v3
我已经设置好通过颜色替换更改标记的颜色(我使用 Font Awesome markers)
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var symbol = this.getIcon();
symbol.fillColor = 'black';
this.setIcon(symbol);
}
})(marker, i));
但我该如何改回(切换)?
我尝试使用 if
/ else if
闭包,但它不起作用。
一个简单的 if/else-condition 适合我:
google.maps.event.addListener(marker, 'click', function() {
var symbol = this.getIcon();
symbol.fillColor = (symbol.fillColor==='black')
? 'red'//initial fillColor
: 'black';
this.setIcon(symbol);
});
我已经设置好通过颜色替换更改标记的颜色(我使用 Font Awesome markers)
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
var symbol = this.getIcon();
symbol.fillColor = 'black';
this.setIcon(symbol);
}
})(marker, i));
但我该如何改回(切换)?
我尝试使用 if
/ else if
闭包,但它不起作用。
一个简单的 if/else-condition 适合我:
google.maps.event.addListener(marker, 'click', function() {
var symbol = this.getIcon();
symbol.fillColor = (symbol.fillColor==='black')
? 'red'//initial fillColor
: 'black';
this.setIcon(symbol);
});