Ruby on Rails - Gmap4Rails弹出更大的地图

Ruby on Rails - Gmap4Rails popup for a bigger map

本文关键字:地图 on Rails Gmap4Rails Ruby      更新时间:2023-09-26

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

在我的应用程序中,我正在使用很棒的Google-Maps-for-Rails通过呼吸暂停潜水(这太棒了)

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

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

像这样:

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

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

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

有什么提示吗?

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

问候

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

事实上,创建地图所需的整个代码在您的 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();