2014-04-29 35 views
0

我似乎無法使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 

回答

0

的問題是與線:google.maps.event.addListener marker, "click", ->,它應該已經google.maps.event.addListener marker, "click", =>此外,我創建了一個單獨的方法調用只能創建一個信息窗口的實例。 - >和=>之間有區別。後者創建一個臨時變量var _this = this,稍後將其用於infoWindow

相關問題