我的地图对象上有以下侦听器:
myMapObject.addListener('bounds_changed', function(){
mySearchBoxObject.setBounds(myMapObject.getBounds());
if(this.getZoom() == 14){
for(var i = 0; i < customInfoWindows.length; i++){
customInfoWindows[i].open(myMapObject, customMarkers[i]);
}
}
});
在缩放级别14时,我自动打开绑定到我在地图上放置的自定义标记的所有信息窗口。
有没有一种方法可以使用API提供的信息来仅打开缩放当前视图内的信息窗口?例如,如果我的地图上有20个标记/信息窗口,而我在当前缩放视图中只能看到4个标记,那么我只想打开与这4个标记关联的4个信息窗口。
在打开信息窗口之前,请检查标记是否在范围内:
myMapObject.addListener('bounds_changed', function(){
mySearchBoxObject.setBounds(myMapObject.getBounds());
if(this.getZoom() == 14){
for(var i = 0; i < customInfoWindows.length; i++){
// check if is in bounds
if (myMapObject.getBounds().contains(customMarkers[i].getPosition()))
customInfoWindows[i].open(myMapObject, customMarkers[i]);
}
}
});
google.maps.Map.getBounds()方法会返回具有方法的google.maps.LatLngBounds()对象.contains
。
包含(latLng:LatLng | LatLngLiteral)
返回值:布尔值
如果给定的纬度/经度在此范围内,则返回true。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句