0

我正在尝试结合以下 Gmap3 的 2 个功能(尽管链接中的 Auto Fit 演示似乎不起作用,但当我将参数添加到本地演示时它可以正常工作):

http://gmap3.net/examples/tags.html

http://gmap3.net/api/auto-fit.html

因此,我希望为使标记可见和不可见的区域设置复选框,并且我希望地图在此选择后自动放大和缩小以显示页面上的所有图钉。

这可能吗?我该如何实现这一目标?谢谢

4

1 回答 1

1

似乎自动调整不处理已删除的项目。

但是你可以自己实现这个。

对于给定的示例,此修改将执行此操作:


1.

替换这一行:

tmp[ ville.region ] = true;

经过:

if( tmp[ ville.region ])
{
 tmp[ ville.region ].bounds.extend(new google.maps.LatLng(ville.lat,ville.lng))
}
else
{
 tmp[ ville.region ]=
  {
   bounds:new google.maps.LatLngBounds(new google.maps.LatLng(ville.lat,ville.lng)),
   checked:true
  }
}

它将为每个区域存储 LatLngBounds 和状态(已选中)


2.

在此之后添加:

 $.each(markers, function(i, marker){
                marker.setMap( checked ? map : null);
            });

这些行:

tmp[region].checked=checked;
var bounds=new google.maps.LatLngBounds();

$.each(tmp,function(i,o)
                      {
                        if(o.checked)
                        {
                          bounds.union(o.bounds);
                        }
                      }
                  );
map.fitBounds(bounds);

它将设置当前区域的检查状态,然后计算所有可见区域的 LatLngBounds。结果将用作 map.fitBounds() 的参数


演示:http: //jsfiddle.net/doktormolle/nBtVB/

于 2012-02-27T16:46:43.847 回答