3

我正在使用谷歌地图作为轨道,并且我已经正确设置了所有内容,但我似乎无法弄清楚如何设置默认缩放数字。我尝试在 gmaps4rails.base.js.coffee 中设置它:

@default_map_options = 
      id: 'map'
      draggable: true
      detect_location: false  # should the browser attempt to use geolocation detection features of HTML5?
      center_on_user: false   # centers map on the location detected through the browser
      center_latitude: 0
      center_longitude: 0 
      zoom: 7
      maxZoom: null
      minZoom: null
      auto_adjust : true      # adjust the map to the markers if set to true
      auto_zoom: true         # zoom given by auto-adjust
      bounds: []              # adjust map to these limits. Should be [{"lat": , "lng": }]    
      raw: {}                  # raw json to pass additional options

但我认为这不能正常工作。创建地图时有没有办法添加缩放数字:

<%= gmaps(:markers => {:data => @json, 
                      :options => {:raw => '{ animation: google.maps.Animation }' } },
                      :map_options => { :raw => '{ disableDefaultUI: false, 
                                                   scrollwheel: true }' }) %>

我所做的一切似乎都没有做任何事情,它总是一直放大。谢谢!

4

3 回答 3

2

这是我的解决方案,它有效(注意我使用haml.<%= %>用于erb):

= gmaps("map_options" => { "detect_location" => true, "center_on_user" => true, "auto_zoom" => false, "zoom" => 16},"markers" => { "data" => @json })
于 2012-10-26T16:43:13.090 回答
1

你需要设置 :auto_zoom => false, :zoom => value

<%= gmaps(:markers => {:data => @json, 
                  :options => {:raw => '{ animation: google.maps.Animation }' } },
                  :map_options => { :raw => '{ disableDefaultUI: false, 
                                               scrollwheel: true,
                                               auto_zoom => false,
                                               zoom => 10 }' }) %>
于 2012-03-14T13:04:46.520 回答
0

不确定您到底要完成什么,但我的挑战是,使用自动缩放它会放大到目前为止,视角都是错误的。我的解决方案是更改基本咖啡脚本中的最大缩放值。片段如下。请注意,自动保持为真。

  center_longitude: 0
  zoom: 7
  maxZoom: 18
  minZoom: null
  auto_adjust : true      # adjust the map to the markers if set to true
  auto_zoom: true         # zoom given by auto-adjust
  bounds: []              # adjust map to these limits. Should be [{"lat": , "lng": }]
  raw: {}                  # raw json to pass additional options

答案中提到的另一个haml解决方案也适用于单页。

于 2013-04-17T13:27:56.247 回答