1 回答

TA貢獻1856條經驗 獲得超17個贊
我能夠在(存檔的)信息框庫中找到解決方案:https : //github.com/googlemaps/v3-utility-library/blob/master/archive/infobox/src/infobox.js#L231
看起來我在第一次嘗試時就很接近了,但應該設置 event.cancelBubble = true;
最終解決方案:
Popup.prototype.onAdd = function () {
this.getPanes().floatPane.appendChild(this.containerDiv);
// This handler allows right click events on anchor tags within the popup
var allowAnchorRightClicksHandler = function (e) {
if (e.target.nodeName === "A") {
e.cancelBubble = true;
if (e.stopPropagation) {
e.stopPropagation();
}
}
};
this.contextListener_ = google.maps.event.addDomListener(this.containerDiv, "contextmenu", allowAnchorRightClicksHandler);
};
Popup.prototype.onRemove = function () {
if (this.contextListener_) {
google.maps.event.removeListener(this.contextListener_);
this.contextListener_ = null;
}
if (this.containerDiv.parentElement) {
this.containerDiv.parentElement.removeChild(this.containerDiv);
}
};
有關彈出代碼的其余部分,請參閱https://developers-dot-devsite-v2-prod.appspot.com/maps/documentation/javascript/examples/overlay-popup
添加回答
舉報