[英]Google Maps API markers and zoom
我是Google Maps API的新手。
我的情況:以全屏Google地圖為背景的網站。
第一個問題:如果用戶向下滾動或放大太多,則背景為灰色。 是否可以限制最大縮小並且他無法滾動? 或者,可能會垂直重復地圖(帶有標記)。 如果可以設置最大縮小並將其鎖定在地圖中,我如何動態計算與屏幕分辨率相關的最大縮小?
第二個問題:是否可以向標記添加自定義javascript? 示例:我創建5個標記,每個標記都應保留一個自定義值(數據庫中的ID)。 單擊時,應使用自定義值作為參數調用我自己的函數,並執行一些操作。
編輯:這就是我用灰色的意思:(谷歌地圖的垂直“結束”)
地圖對象具有屬性maxZoom,在創建地圖時進行設置
是的,有可能,您可以添加點擊事件,更改打開的彈出窗口,並且由於它是JavaScript,因此您可以添加任何其他數據,就像markr.MyData = 'something interesting'
我不確定您指的是什么灰色部分? 我在Google地圖中看不到最大和最小縮放的灰色部分
好的。 終於成功了! :)
固定灰色區域(手柄也會縮放):
function setBounds() {
google_allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-85.000, -122.591),
new google.maps.LatLng(85.000, -122.333));
google_lastCenter = google_map.getCenter();
google_lastZoom = google_map.getZoom();
google.maps.event.addListener(google_map, "bounds_changed", function () {
checkBounds();
});
google.maps.event.addListener(google_map, 'center_changed', function () {
checkBounds();
});
}
function checkBounds() {
if (google_allowedBounds.getNorthEast().lat() > google_map.getBounds().getNorthEast().lat()) {
if(google_allowedBounds.getSouthWest().lat() < google_map.getBounds().getSouthWest().lat()) {
google_lastCenter = google_map.getCenter();
google_lastZoom = google_map.getZoom();
return true;
}
}
google_map.panTo(google_lastCenter);
google_map.setZoom(google_lastZoom);
return false;
}
標記點擊處理程序:
google_listener = google.maps.event.addListener(marker, 'click', markerHandler);
function markerHandler(event) {
window.console.log(this);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.