Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 3 gmaps4rails更改地图id_Ruby On Rails 3_Google Maps_Coffeescript_Gmaps4rails - Fatal编程技术网

Ruby on rails 3 gmaps4rails更改地图id

Ruby on rails 3 gmaps4rails更改地图id,ruby-on-rails-3,google-maps,coffeescript,gmaps4rails,Ruby On Rails 3,Google Maps,Coffeescript,Gmaps4rails,我有一个Rails 3.2.x应用程序,我正在使用gmaps4rails 2.0.0.pre(是的,我知道这是一个旧版本)。我用它在gps视图/控制器的地图上绘制不同的车辆(单位)。现在我正试图利用gmaps4rails在不同的视图/控制器中显示地图,以便在“设施显示”视图中显示建筑(设施)位置 在初始页面加载时,我在地图上的适当位置显示设施的标记。然而,过了一会儿,这个标记将完全消失。我知道为什么会发生这种情况,但不知道如何解决 我有以下Coffeescript,它查找#map的ID,并调用/

我有一个Rails 3.2.x应用程序,我正在使用
gmaps4rails 2.0.0.pre
(是的,我知道这是一个旧版本)。我用它在gps视图/控制器的地图上绘制不同的车辆(单位)。现在我正试图利用
gmaps4rails
在不同的视图/控制器中显示地图,以便在“设施显示”视图中显示建筑(设施)位置

在初始页面加载时,我在地图上的适当位置显示设施的标记。然而,过了一会儿,这个标记将完全消失。我知道为什么会发生这种情况,但不知道如何解决

我有以下
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显示视图。我想找出一种生成gmaps4rails映射并更改
ID
的方法

facility.rb

  acts_as_gmappable process_geocoding: false
<div class="well">
  <%= gmaps(markers: {data: @marker, options: {rich_marker: true, "auto_zoom" => false}}) %>
</div>
设施\u控制器

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
facility show.html.erb

  acts_as_gmappable process_geocoding: false
<div class="well">
  <%= gmaps(markers: {data: @marker, options: {rich_marker: true, "auto_zoom" => false}}) %>
</div>

假}})%>
有没有办法生成gmaps4rails地图,并覆盖
#map
的默认
ID
,这样我就可以防止标记消失,并继续在GPS视图中使用我的咖啡脚本

如果有人有任何建议,请告诉我。我将不胜感激


如果我的问题让人困惑或者需要更多解释,我会很乐意更新它。

我想我找到了如何在
gmaps4rails
中覆盖
#map
ID

通过将
:map_options
设置为
设施地图
ID
,我的咖啡脚本不会在此视图上启动,并且标记器会按照我的要求保持静态

<div class="well">
  <%= gmaps(markers: {data: @marker, options: {rich_marker: true}}, :map_options => {:id => "facility_map"}) %>
</div>

{:id=>“设施地图”})%>
如果你们有更好的方法,请告诉我。但到目前为止,这似乎对我有效