【发布时间】:2014-04-25 13:35:18
【问题描述】:
我正在关注 Gmaps4Rails 教程并尝试在引导框架中实现它,但遇到了问题。地图无法正确加载...See here.放大功能不起作用。
I tried the workaround 但它只起到了一点作用。这似乎是如何设置引导程序的问题,或者我的需求树可能不正确。我的相关代码见下文。
视图/布局/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all",
"data-turbolinks-track" => true %>
<%= javascript_include_tag "application",
"data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
<% flash.each do |key, value| %>
<%= content_tag(:div, value, class: "alert alert-#{key}") %>
<% end %>
</head>
...
custom.css.scss --> 这是我的应用程序的主要样式表,我在这里添加了解决方法代码只是为了看看它是否会有所作为,但它没有。
@import "bootstrap";
/*MAP*/
#map img {
max-width: none;
}
#map label {
width: auto; display:inline;
}
...
应用程序.css
...
* You're free to add application-wide styles to this file and they'll appear at the top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*= require_self
*= require_tree .
*/
index.html.erb --> 显示地图的主页
<head><link rel="stylesheet" href="reports.css.scss" /></head>
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/trunk/richmarker/src/richmarker-compiled.js' type='text/javascript'></script>
...
<%= link_to 'New Report', new_report_path %>
<div style='width: 800px;'>
<div id="map" style='width: 800px; height: 400px;'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
markers = handler.addMarkers(<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
});
reports.css.scss --> 我的模型名称是 Reports,而不是 gmaps4rails 演示中的“用户”
// Place all the styles related to the Reports controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
#map img {
max-width: none;
}
#map label {
width: auto; display:inline;
}
应用程序.js
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require underscore
//= require gmaps/google
//= require_tree .
【问题讨论】:
标签: css ruby-on-rails google-maps twitter-bootstrap gmaps4rails