【问题标题】:Ruby on Rails - Gmap4Rails popup for a bigger mapRuby on Rails - 用于更大地图的 Gmap4Rails 弹出窗口
【发布时间】:2012-06-01 10:25:45
【问题描述】:

我是 Rails 初学者,正在使用 rails 3.2.3。

在我的应用程序中,我通过 apneadiving 使用了很棒的 Google-Maps-for-Rails(真是太棒了)

一切都很好,但我遇到了一个问题,在这里和那里没有找到我想做的任何答案。

基本上,我正在显示一张小地图,并希望在其下方有一个按钮,当用户单击它时,将显示该位置的更大地图。 (基本上是同一张地图,只是尺寸更大)

类似这样的:

<input type="button" onclick="myFunction()" value="Show a bigger map" />

但我的问题是在那个 javascript 函数中放什么,我该如何说应该显示带有 @gmaps 值的更大地图?

在 gmaps css 中创建一个更大的 With 和 Height 的新 id? 如何将我的@gmaps 中的数据提供给 JS?

有什么建议吗?

对不起,如果这是一个幼稚的问题,我仍然习惯于 RoR 和 Gmaps4Rails gem。 提前感谢您的宝贵时间。

问候

【问题讨论】:

    标签: javascript ruby-on-rails ruby-on-rails-3 google-maps gmaps4rails


    【解决方案1】:

    我不太确定你想做什么,但我想说将一张地图的参数复制到另一张地图真的很容易。

    确实,创建地图所​​需的全部代码在您的 html 中可见,只需重现这些步骤即可。

    gmaps_helper 将为您的小地图完成这项工作。基本上,它遵循以下步骤:

    Gmaps.map = new Gmaps4RailsGoogle();
    //mandatory
    Gmaps.map.initialize();
    // then some code depending on your options
    Gmaps.map.markers = some_array;
    Gmaps.map.create_markers();
    

    只要您想复制地图,您只需按照相同的步骤操作即可:

    Gmaps.bigmap = new Gmaps4RailsGoogle();
    //mandatory to have the map created in the proper place
    Gmaps.bigmap.map_options.id = the_id_of_your_html_div;
    //still mandatory
    Gmaps.bigmap.initialize();
    
    //copy the specific parameters from the other map
    Gmaps.bigmap.markers = Gmaps.map.markers;
    Gmaps.bigmap.create_markers();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-18
      • 2012-09-23
      • 1970-01-01
      • 1970-01-01
      • 2010-11-21
      • 1970-01-01
      • 2015-04-10
      相关资源
      最近更新 更多