4

我在 gmap3 插件上使用“autoFit”,因此它可以缩放到地图上对象的最佳水平。问题是当只有 1 个对象时,它会放大到太远的最大级别。我怎样才能让它不超过缩放级别 14?

谢谢。

4

3 回答 3

7

您可以使用 maxZoom,但这会设置地图的最大缩放而不是自动调整功能。这意味着如果用户愿意,他们将无法进一步放大地图。

map:{
      center: true,
      zoom: 10,
      maxZoom: 18
    }

相反,我为每个点添加了一个隐藏的圆圈或半径,其大小可以使地图缩小到我想要的缩放级别。这样,用户仍然可以根据需要进一步放大。

$('#test').gmap3(
    { 
        action: 'addMarker',
        latLng: "your data input for markers",
        map:{
            center: true,
            zoom: 10
        }
    },
    { 
        action: 'addCircle',
        latLng: "your data input for markers",
        options: {
            radius : 75,
            strokeOpacity: 0,
            fillOpacity: 0,
        }
    },
    'autofit'
);
于 2011-10-04T10:07:20.370 回答
4

您可以将 maxzoom 属性添加到 gmap3 插件的 map 属性中:

$('#test1').gmap3(
      {
        action: 'addInfoWindow',
        address: "some place name",
        map:{
          center: true,
          zoom: 5,
          maxZoom: 10
        },...
于 2011-08-15T14:53:44.940 回答
3

这在 gmap3 5.1.1 版中似乎对我有用。只需使用 autofit:{maxZoom:14}。这告诉地图仅在自动调整时放大到 14 级,并允许用户使用鼠标或缩放控件放大或缩小。

    $(function(){

    $("#test").gmap3();

    $('#test-ok').click(function(){
      var addr = $('#test-address').val();
      if ( !addr || !addr.length ) return;
      $("#test").gmap3({
        getlatlng:{
          address:  addr,
          callback: function(results){
            if ( !results ) return;
            $(this).gmap3({
              marker:{

                latLng:results[0].geometry.location,
                map:{

                  center: true,

                },

              },
              autofit:{maxZoom: 14},

            });

          }
        }
      });
    });

    $('#test-address').keypress(function(e){
      if (e.keyCode == 13){
        $('#test-ok').click();
      }
    });
  });
于 2013-07-05T18:48:56.350 回答