我似乎無法使infowindows與咖啡標記一起工作。我的初始化代碼使用構造函數創建一個Class來創建一個Google地圖,然後根據用戶界面的需求,如果需要,我使用類'addSingleMarkers'這樣的類的方法在地圖上放置標記。標記正常工作,他們beig正確顯示在地圖上,但是當我嘗試爲每個標記放置infoWindows時,它會失敗。使用此代碼一次且僅在第一次單擊任何標記時顯示infoWindow,並顯示標記的正確信息,如果此infoWindow已關閉,則無法再次打開。我有紅色系列的帖子在這個JavaScript的,但只是不能讓它與咖啡腳本工作。我究竟做錯了什麼 ?Google地圖與CoffeeScript的多個InfoWindows
class window.GoogleMap
constructor: (@canvasID = "#google_map",
@searchID = "#google_map_search",
@rectBounds = "#google_map_rect") ->
mapOptions = {
center: new google.maps.LatLng(38, 23.5),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
@gmap = new google.maps.Map($(@canvasID)[0], mapOptions) if $(@canvasID).length
true
addSingleMarkers: (data) ->
for coordinates, text of data
point_length = coordinates.length
data_array =
coordinates.substring(6,point_length).
replace('(','').replace(')','').split(" ")
point = new google.maps.LatLng(data_array[1],data_array[0])
marker = new google.maps.Marker(
position: point
map: @gmap
title: text)
@bindInfoW marker, text
bindInfoW : (marker, contentString) ->
google.maps.event.addListener marker, "click", ->
infowindow = new google.maps.InfoWindow
infowindow.setContent contentString
infowindow.open @gmap, marker