我有一个标记,我正在尝试添加一个infowindow。首先,我显示一个下拉菜单供用户选择删除操作。当用户单击删除时,我在infowindow中显示删除确认提示。是/否按钮操作被调用但我无法使用_this.close()关闭信息窗口。在调试器中,它显示_这正确指向infowindow但它没有关闭。这是代码,overlayObj [pmid]指向一个google标记。
this.overlayObj[pmId].listenerHandle[i++] =
google.maps.event.addListener(this.overlayObj[pmId], 'rightclick',
function(event) {
var contentString = '<div><select id="overlayAction">' +
'<option value="">Choose Action</option>' +
'<option value="delete">Delete</option>' + // + pmId + '">Delete</option>' +
'</select></div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infowindow.open(_this.overlayObj[pmId].get('map'), _this.overlayObj[pmId]);
google.maps.event.addListener(infowindow, 'domready',
function() {
var _this = this;
// Reference to the DIV which receives the contents of the
// infowindow using jQuery
var iwOuter = $('.gm-style-iw');
//iwOuter.css({'background-color' : 'white'});
// The div we want to change is above the .gm-style-iw div.
// So, we use jQuery to get it using .prev().
//
var iwBackground = iwOuter.prev();
// Remove the background shadow DIV
iwBackground.children(':nth-child(2)').css({
'display': 'none'
});
// Remove the white background DIV
iwBackground.children(':nth-child(4)').css({
'display': 'none'
});
var overlayAction =
document.getElementById("overlayAction");
google.maps.event.addDomListener(overlayAction, "click",
function(event) {
if (this.value == "delete") {
// clear listeners on infowindow
google.maps.event.clearInstanceListeners(_this);
// set infowindow content to delete prompt
var confirmString = '<div class="iw-container">' +
'<p>Delete item?</p>' +
'<button id="deleteIconButton">Yes</button>' +
'<button id="cancelDeleteIconButton">No</button></div>';
_this.setContent(confirmString);
google.maps.event.addListener(_this, 'domready',
function() {
var _this = this;
var deleteIcon =
document.getElementById("deleteIconButton");
var cancelDeleteIcon =
document.getElementById("cancelDeleteIconButton");
google.maps.event.addDomListener(cancelDeleteIcon, "click",
function(event) {
_this.close();
google.maps.event.clearInstanceListeners(_this); // clears infowindow listeners
});
google.maps.event.addDomListener(deleteIcon, "click",
function(event) {
_this.close(); // closes infowindow
google.maps.event.clearInstanceListeners(_this); // clears infowindow listeners
CpC.myMap.deleteIcon(pmId); // removes icon from map and db
});
});
}
});
});
});