Adjust Zoom Gmaps4Rails

2019-03-31 02:32发布

I'm using the Gmaps4Rails gem and cannot figure out how to adjust the default zoom settings. In my view I have the following code:

<%= gmaps({
   "map_options" => {"auto_adjust" => false, "auto_zoom" => false, "zoom" => 15 },
   "markers"     => {"data" => @json }
  })
%>

I know this has been asked and answered many times, but maybe I'm just not seeing something...any advice? Am i missing something completely obvious? I apologize for reposting this question.

Thanks, Kevin

EDIT

I failed to properly comment out the default instance of gmaps and it overrode my customized settings. Thanks for all the help @apneadiving!

3条回答
Viruses.
2楼-- · 2019-03-31 03:02

I'm on gmaps4rails 1.3.2 and these are the best settings I could find:

<%= gmaps({
  "map_options" => {"auto_zoom" => false, "zoom" => 10 },
  "markers" => {"data" => @json }
})
%>
  • I did not set auto_adjust to false, because the map would not be centered on the marker anymore.

  • The 10 value for the zoom is nice to display approximatively a 50km-wide map.

查看更多
再贱就再见
3楼-- · 2019-03-31 03:11

You're simply missing that seeing the whole map means providing a very small number, not a big one!

<%= gmaps({
  "map_options" => {"auto_adjust" => false, "zoom" => 0 },
  "markers"     => {"data" => @json }
 })
%>
查看更多
别忘想泡老子
4楼-- · 2019-03-31 03:24

what helped me in this case was this:

Gmaps4Rails.callback = function() {
    setTimeout("Gmaps4Rails.map.setZoom(13);", 100);
};
查看更多
登录 后发表回答