我在InfoWindows打開時遇到問題。代碼調用open函數,但信息窗口不會出現在屏幕上,直到用戶做了其他的事情來與地圖交互,通常是點擊或移動鼠標。InfoWindow不立即打開
這裏是預期的邏輯:當你點擊一個標記時會打開一個信息窗口。如果已經打開了一個信息窗口,它將關閉前一個窗口,然後打開新的信息窗口。如果你點擊地圖,信息窗口關閉。
觀察到的問題:地圖加載。我點擊一個標記並出現一個信息窗口。我通過單擊信息窗口上的x或點擊地圖來關閉它。 A)我點擊不同的標記。什麼都沒發生。我再次點擊,出現信息窗口。 B)我點擊不同的標記。什麼都沒發生。我再次點擊它,信息窗口出現。
無論哪種方式,都需要額外的用戶輸入位才能顯示信息窗口。
我也實現了另一種邏輯:鼠標事件觸發標記後,信息窗口出現。僅在用戶點擊地圖時關閉,關閉信息窗口或在不同的標記上運行光標。
觀測到的行爲:同樣的問題和以前一樣,只是信息窗口有時會只有光標移動後關閉標記出現。
注:
- 這正好多邊形以及標記。
- 僅在Windows中的谷歌瀏覽器中才會觀察到行爲。沒有其他瀏覽器已經過測試。
- 此錯誤已出現在多臺計算機上。
- 如果我使用Chrome的開發人員工具,信息窗口總是出現在斷點之後。
下面是代碼:
var mCurrentOpenInfoWindow;
var mCurrentInfoWindowParent;
function openNewInfoWindowAtLatLon(parent, anchor, infoWindowData) {
if (mCurrentInfoWindowParent !== parent) {
closeCurrentInfoWindow();
var content = createInfoWindowContent(infoWindowData);
if (!mCurrentOpennfoWindow) {
mCurrentOpenInfoWindow = new google.maps.InfoWindow({
content: content,
disableAutoPan: true
});
}
else {
mCurrentOpenInfoWindow.setContent(content);
}
mCurrentOpenInfoWindow.open(mGoogleMap, anchor);
mCurrentInfoWindowParent = parent;
}
}
function closeCurrentInfoWindow() {
if (mCurrentOpenInfoWindow) {
mCurrentOpenInfoWindow.close();
mCurrentInfoWindowParent = null;
}
}
// ... Inside a function which creates an adds a google marker
// in the variable gmarker. displayObject is just an object used to
// keep the info window from opening multiple times for the same
// map item that has been clicked on.
google.maps.event.addListener(gmarker, 'click', function() {
openNewInfoWindowAtAnchor(displayObject, gmarker, infoWindowData);
});
我假設openNewInfoWindowAtAnchor調用openNewInfoWindowAtLatLon?我能看到這種方法嗎?我看不到任何明顯的錯誤。 – Swires