1

我是 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?如何向 JS 提供来自我的@gmaps 的数据?

有小费吗?

抱歉,如果这是一个幼稚的问题,我仍然习惯于 RoR 和 Gmaps4Rails gem。在此先感谢您的时间。

问候

4

1 回答 1

0

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

实际上,创建地图所​​需的全部代码在您的 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();
于 2012-06-02T21:52:51.217 回答