gmaps4rails single marker auto zoom

后端 未结 1 886
春和景丽
春和景丽 2021-01-14 07:02

I am trying to follow the answer here to zoom out a bit (by default) when a single marker is displayed on the map. I have tried the code below, and have a working map genera

相关标签:
1条回答
  • 2021-01-14 07:43

    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 %>
    
    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题