我正在使用谷歌地图的轨道,我已经正确设置了一切,但我似乎无法弄清楚如何设置默认的缩放数量。我尝试在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 }' }) %>
我所做的一切似乎什么都没做,它总是一直放大。谢谢!
答案 0 :(得分:2)
这是我的解决方案,有效(请注意,我使用haml
。<%= %>
使用erb
):
= gmaps("map_options" => { "detect_location" => true, "center_on_user" => true, "auto_zoom" => false, "zoom" => 16},"markers" => { "data" => @json })
答案 1 :(得分:1)
您需要设置:auto_zoom =&gt; false,:zoom =&gt;值
<%= gmaps(:markers => {:data => @json,
:options => {:raw => '{ animation: google.maps.Animation }' } },
:map_options => { :raw => '{ disableDefaultUI: false,
scrollwheel: true,
auto_zoom => false,
zoom => 10 }' }) %>
答案 2 :(得分: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解决方案也适用于单个页面。