目前,当向地图添加新标记时,它会自动缩放到该新位置。
如何配置gmaps4rails以响应将自动缩小以查看地图上所有标记的按钮?如下:
我用于渲染的配置是:
allLocations = root.table.rows(".selected").data()
$('#multi_markers').map ->
handler = Gmaps.build("Google")
handler.buildMap
internal:
id: "multi_markers"
, ->
for aLocation in allLocations
markers = handler.addMarkers([
{
lat: aLocation[9]
lng: aLocation[10]
}
])
handler.bounds.extendWith markers
handler.fitMapToBounds()
return
请注意,这与gmaps4rails有关,而不仅仅是gmaps
答案 0 :(得分:0)
在handler.buildMap之后,您可以设置如下默认缩放:
handler.buildMap({provider:{zoom:15,center:new google.maps.LatLng(40.7127,-74.00030),mapTypeId:google.maps.MapTypeId.ROADMAP},internal:{id:'地图'}}
这里指定纬度:40.7127经度:-74.00030并缩放:15。其余的是地图类型,可以省略