gmaps4rails single marker auto zoom

本秂侑毒 提交于 2019-12-01 08:17:18

Ok, the interface changed a lot since I posted the answer you quote.

<%= gmaps("markers" => {"data" => @json, "options" => {"auto_zoom" => false} }) %>

<% content_for :scripts do %>
    <script type="text/javascript" charset="utf-8">
      Gmaps.map.callback = function() {
        if (Gmaps.map.markers.length == 1) {
         //only one marker, choose the zoom level you expect
         setTimeout(function() { Gmaps.map.serviceObject.setZoom(5);}, 50);
        }
        else{
         //more than one marker, let's auto_zoom
         Gmaps.map.map_options.auto_zoom = true;
         Gmaps.map.adjustMapToBounds();
        }
      }
    </script>
<% end %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!