我有一個地圖顯示每個針腳的針腳和infowindow。縮放級別爲9,在該縮放級別,某些引腳不顯示。我需要動態控制縮放級別,以便一次顯示地圖畫布中的所有針腳。地圖放大/縮小以動態包含所有的針腳
2
A
回答
0
您可以使用map.fitBounds
函數來縮放到特定的邊界區域。爲了得到這個區域,你只需要遍歷所有的引腳,並取最小/最大的座標。
3
擁有的LatLngBounds對象。在創建每個標記時,您需要擴展邊界以包含每個標記的位置。然後在最後調用fitBounds方法調整地圖大小以適應所有標記。
function initialize() {
var arrPoints = [
{
lat: 51.498725,
lng: -0.17312,
description: "One",
price: 1.11
},
{
lat: 51.4754091676,
lng: -0.186810493469,
description: "Two",
price: 2.22
},
{
lat: 51.4996066187,
lng: -0.113682746887,
description: "Three",
price: 3.33
},
{
lat: 51.51531272,
lng: -0.176296234131,
description: "Four",
price: 4.44
}
];
var centerLatLng = new google.maps.LatLng(51.532315,-0.1544);
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 15,
center: centerLatLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
// create the Bounds object
var bounds = new google.maps.LatLngBounds();
var homeMarker = new google.maps.Marker({
position: centerLatLng,
map: map,
icon: "http://maps.google.com/mapfiles/ms/micons/green-dot.png"
});
for (var i = 0; i < arrPoints.length; i++) {
position = new google.maps.LatLng(arrPoints[i].lat, arrPoints[i].lng);
var marker = new google.maps.Marker({
position: position,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, this);
});
// extend the bounds to include this marker's position
bounds.extend(position);
}
// make sure we include the original center point
bounds.extend(centerLatLng);
// resize the map
map.fitBounds(bounds);
}
相關問題
- 1. 如何放大和縮小圖像並移動所有圖像
- 2. 從縮略圖腳本修改放大圖像,以動態顯示基於其大小屬性的圖像
- 3. 加載,滾動,放大和縮小圖像像谷歌地圖
- 4. iPhone縮放地圖顯示所有排針
- 5. 縮放ImageMap與動態大小的圖像協調
- 6. Google地圖GDirections - IE7中沒有居中/放大縮小圖
- 7. WP7 Silverlight的必應地圖 - MapPolyline不放大或縮小地圖
- 8. 放大縮小動畫
- 9. 放大縮小採樣圖
- 10. 如何動態縮小和縮小圖像大小?
- 11. javascript,獲取包含屬性的縮放背景的大小
- 12. 動態設置谷歌地圖縮放
- 13. 動態縮小縮略圖的大小以均勻佔據空間
- 14. 更改div中包含的所有圖像的大小
- 15. 使用Google Images API動態縮小圖像,但不要放大
- 16. 將SVG縮放到所需的大小
- 17. 縮放所有圖像到控制檯大小XNA
- 18. 縮放以顯示bing地圖中的所有位置
- 19. 放大時包含圖像
- 20. 背景大小:包含;高度不能正確縮放
- 21. 如何自動調整d3.js圖的大小以包含軸
- 22. 縮放以適應地圖上的所有標記谷歌地圖v2 android
- 23. iPhone MKMapView:設置地圖區域以顯示地圖上的所有針腳
- 24. ggplot2和Shiny:如何縮放圖形大小的圖例大小?
- 25. 用jquery動態啓動縮放腳本
- 26. 捏放大圖像和縮小圖像
- 27. 帶有KML的Google地圖不會遵守縮放設置;相反,縮小以適應所有標記
- 28. 放大縮小的動作腳本循環3
- 29. 放大和縮小
- 30. UIPinchGestureRecognizer(縮小/放大)