2012-10-26 58 views
6

我有一個頁面,上面有InfoWindows標記,我點擊打開。我決定寧願打開正在工作的MouseOver上的InfoWindows。谷歌地圖:在鼠標懸停時打開InfoWindow,關閉並重新打開點擊

但我發現不得不將鼠標移動到InfoWindow的十字架上以關閉它,這對這些懶惰的互聯網訪問者來說有點苛刻。所以我在點擊標記上添加了一個關閉事件,它也在工作。

我想不出的工作是能夠重新打開標記上的InfoWindow單擊而不必鼠標移動以便能夠在標記上重新進行鼠標懸停。

我的代碼:

google.maps.event.addListener(CalMarker, 'mouseover', function() { 
    infowindow.setContent(contentStringCal); 
    infowindow.open(map,CalMarker); 
}); 
google.maps.event.addListener(CalMarker, 'click', function() { 
    infowindow.close(map,CalMarker); 
}); 

誰能幫助我通過點擊標記重新打開窗口?

在此先感謝

PS:無法管理想說聲「嗨」的帖子的beggining,這是不可思議。

回答

8

試試這個:

google.maps.event.addListener(CalMarker, 'mouseover', function() { 
    //open the infowindow when it's not open yet 
    if(contentStringCal!=infowindow.getContent()) 
    { 
     infowindow.setContent(contentStringCal); 
     infowindow.open(map,CalMarker); 
    } 
}); 

google.maps.event.addListener(CalMarker, 'click', function() { 
    //when the infowindow is open, close it an clear the contents 
    if(contentStringCal==infowindow.getContent()) 
    { 
     infowindow.close(map,CalMarker); 
     infowindow.setContent(''); 
    } 
    //otherwise trigger mouseover to open the infowindow 
    else 
    { 
     google.maps.event.trigger(CalMarker, 'mouseover'); 
    } 
}); 

//clear the contents of the infwindow on closeclick 
google.maps.event.addListener(infowindow, 'closeclick', function() { 
     infowindow.setContent(''); 
}); 

演示:http://jsfiddle.net/doktormolle/JXqLa/

+0

工作,非常感謝;-) – Tsokoa

相關問題