Google-Maps-for-Rails - 如何使用 gmap4rails 设置地图图像的大小?
问候。
我在部署到 Heroku 时遇到了 Cartographer 插件的问题。 我尝试了 Google-Maps-for-Rails (gmaps4rails gem),它看起来非常有前途。但我一直无法弄清楚如何设置地图图像大小。
使用 Cartographer,我可以使用如下标记设置地图图像大小。
<div id="map-right">
<%= raw Cartographer::Header.new.to_s %>
<%= raw @map.to_html %>
<div id="map" style="width:658px;height:348px;">[Map]</div>
</div>
如何使用 gmaps4rails 获得类似的行为?我正在尝试这个。
<div id="map-right">
<div id="map" style="width:658px;height:348px;"><%= gmaps4rails(@events_map) %></div>
</div>
这会绘制地图但不会设置图像大小。什么是明智的做法?
谢谢。
Greetings.
I've had trouble with the Cartographer plugin when deploying to Heroku.
I tried Google-Maps-for-Rails (gmaps4rails gem) and it looks very promising. But I've not been able to figure out how to set the map image size.
With Cartographer, I can set the map image size using markup like the following.
<div id="map-right">
<%= raw Cartographer::Header.new.to_s %>
<%= raw @map.to_html %>
<div id="map" style="width:658px;height:348px;">[Map]</div>
</div>
How do I get similar behavior using gmaps4rails? I'm trying this.
<div id="map-right">
<div id="map" style="width:658px;height:348px;"><%= gmaps4rails(@events_map) %></div>
</div>
That draws the map but does not set image size. What's a sensible approach?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
让我们更准确地说。
在 gmaps4rails 中,加载了一个 css 文件,其中包含地图容器和地图本身的属性。默认值可在此处查看:
https:/ /github.com/apneadiving/Google-Maps-for-Rails/blob/master/public/stylesheets/gmaps4rails.css
所以你有两个选择:
基本:覆盖这个 css(效果很好)< /p>
更好的选择是按照您想要的方式重新定义 css + 取消默认 css 文件的加载。您可以通过传递
false
作为gmaps
或gmaps4rails
视图帮助器的第二个参数来实现这一点。请参阅此处:https://github.com/apneadiving/Google-Maps- for-Rails/wiki/MiscellaneousLet's be even more precise.
In
gmaps4rails
, a css file is loaded containing the properties of the map container and the map itself. The default are visible here:https://github.com/apneadiving/Google-Maps-for-Rails/blob/master/public/stylesheets/gmaps4rails.css
So you have two choices:
basic: override this css (which works fine)
A better alternative is to redefine the css the way you want + cancel the loading of the default css file. You could achieve that by passing
false
as second argument of thegmaps
orgmaps4rails
view helper. See here : https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Miscellaneous您可以通过 css 设置它:
请参阅 gem 作者的答案: Gmaps4rails : 设置地图宽度和高度
You can set it via css:
See the gem author's answer here: Gmaps4rails : Setting map width and height
我正在遵循 apneadiving 的方法,尽管我的实现可能有点尴尬,即天真。
在我看来,我有以下标记。
我加载自己的 gmaps4rails_welcome.css 并通过传递“false”作为第二个参数来避免加载默认的 gmas4rails css。
我的 gmaps4rails_welcome.css 文件包含以下代码。
对于每个地图
渲染,我都有一个特定的样式表。这有效。
谢谢!
I'm following apneadiving's approach, though my implementation may be a bit awkward, i.e., naive.
In my view I have the following markup.
I load my own gmaps4rails_welcome.css and avoid loading the default gmas4rails css by passing 'false' as the second argument.
My gmaps4rails_welcome.css file contains the following code.
}
For each map rendering I have a specific stylesheet. This works.
Thanks!
我有同样的问题并以不同的方式解决。我注释掉了 gmaps4rails.css 中的宽度,并将 Google 地图包装在具有宽度设置的 div 中。通过此,地图可以调整大小,例如当使用响应式方法、网格系统等时。
我将其与 Twitter Bootstrap 一起使用,效果很好。请注意,到目前为止我已经修复了高度。
希望有帮助。
I had the same issue and solved it differently. I commented out the width from gmaps4rails.css and wrapped the Google map in a div which has the width-setting. Through this, the map is resizeable, e.g. when using a responsive approach, grid system, etc.
I use this with Twitter Bootstrap and it works fine. Note that I fix the height so far.
Hope that helps.