我有一個Rails 3.2.x應用程序,我正在使用gmaps4rails 2.0.0.pre
(是的,我知道它是舊版本)。我正在使用它在GPS視圖/控制器中繪製地圖上的不同車輛(單位)。現在我試圖利用gmaps4rails
在不同的視圖/控制器中顯示地圖,以在設施顯示視圖中顯示建築物(設施)位置。gmaps4rails更改地圖ID
在初始頁面加載時,我在正確的位置在地圖上顯示設施的標記。但過了一會兒,標記就會完全消失。我知道爲什麼會發生這種情況,但不知道如何解決。
我有以下Coffeescript
它看起來爲#map
一個ID
並調用/units
和/gps
路徑更新準實時GPS的視圖/地圖。
gps.js.coffee
$ ->
if $("#map").length > 0
setInterval (->
$.getScript "/units"
# Get all current locations, find each marker in the map, and update it's position
$.getJSON "/gps", (data) ->
$.each(data, (i, val) ->
marker = $.grep Gmaps.map.markers, (e) ->
e.id is val.id
marker[0].setPosition(val.lat, val.lng) if marker[0]?
)
), 5000
$('.marker-link').on 'click', ->
id = $(this).data("marker-id")
marker = $.grep Gmaps.map.markers, (e) ->
e.id is id
marker[0].showInfowindow() if marker[0]?
所以問題是,gmaps4rails地圖默認ID
是#map
。我試圖弄清楚如何使用不同的ID
插件創建一個新地圖,以便我可以顯示設施位置,而不用調用咖啡文字刷新。
這是我的設施模型/視圖/控制器的樣子。一切正常,但由於咖啡腳本調用#map
,標記消失。我不想失去這個coffeescript功能,因爲它正確地用標記更新我的gps show view。我想找出一種方法來生成gmaps4rails地圖並更改ID
。
facility.rb
acts_as_gmappable process_geocoding: false
facilities_controller
def show
@facility = Facility.find(params[:id])
@marker = @facility.to_gmaps4rails do |facility, marker|
#marker.infowindow render_to_string(partial: "unit_infowindow", locals: {unit: unit})
marker.json({id: facility.id})
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @marker }
end
end
設施show.html.erb
<div class="well">
<%= gmaps(markers: {data: @marker, options: {rich_marker: true, "auto_zoom" => false}}) %>
</div>
是否有辦法生成gmaps4rails地圖,並覆蓋的默認ID
,以便我可以防止標記消失並繼續在我的GPS視圖中使用我的咖啡標記?
如果有人有任何建議,請讓我知道。我將不勝感激。
如果我的問題很混亂或需要更多解釋,我會很樂意更新它。