2013-11-14 31 views
1

我的地圖顯示處理器是InfoBoxBuilder gmaps4rails v2的不靈

map_handler = Gmaps.build('Google', { markers: { maxRandomDistance: null }, builders: { Marker: InfoBoxBuilder} }); 

我已經在我的佈局還說:

<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.9/src/infobox_packed.js' type='text/javascript'></script> 

而且我已經添加的文件infoboxbuilder.js.cofee在我的資產與本覆蓋:

class InfoBoxBuilder extends Gmaps.Google.Builders.Marker # inherit from base builder 


# override method 
    create_infowindow: -> 
    return null unless _.isString @args.infowindow 

boxText = document.createElement("div") 
boxText.setAttribute("class", 'yellow') #to customize 
boxText.innerHTML = @args.infowindow 
@infowindow = new InfoBox(@infobox(boxText)) 

@bind_infowindow() 

    infobox: (boxText)-> 
    content: boxText 
    pixelOffset: new google.maps.Size(-140, 0) 
    boxStyle: 
     width: "280px" 

但是,當我加載的網站,我得到這個JavaScript錯誤,沒有地圖:

ReferenceError: InfoBoxBuilder is not defined 
+0

加載訂單事宜在js – apneadiving

+0

它應該是什麼順序?我有我的<%= javascript_include_tag 「應用程序」 %>前頭gmaps scrips我的資產管道 // =需要的jQuery // =需要jquery_ujs // =需要jquery.turbolinks // =需要turbolinks // =要求jquery.remotipart // =要求下劃線 // =要求gmaps/google // = require_tree。 – Core2Juan

+0

map_handler創建應加載所需的js庫後調用 – apneadiving

回答

2

剛剛意識到自己的錯誤

更換

class InfoBoxBuilder 

隨着

class @InfoBoxBuilder 

僅供參考,@告訴CoffeeScript的對象附加到窗口對象。

+0

謝謝,它完全是魔術。我直接從文檔https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Change-handler-behavior獲取該課程。 – Core2Juan

+0

當然,但看看視頻,我在同一個文件中創建地圖,所以這個類是可訪問的 – apneadiving

+0

順便說一句,刪除'@bind_infowindow()'如果你升級到2.1 – apneadiving