2012-11-28 70 views
0

我是Google Maps API的新增功能。Google Maps API标记和缩放

我的情况:以全屏Google地图为背景的网站。

第一个问题:如果用户向下滚动或缩小太多,则会出现灰色背景。是否有可能限制最大缩小,并且他无法滚动?或者,也许可以重复地图垂直(带标记)。 如果可以设置最大缩小并将其锁定在地图内,我怎样才能动态计算出与屏幕分辨率相关的最大缩小?

第二个问题:是否可以将自定义JavaScript添加到标记? 例如:我创建了5个标记,每个标记应该保存一个自定义值(数据库中的ID)。点击我自己的函数应该用自定义值作为参数调用,并做一些事情。

编辑:这是我的意思,灰色:(谷歌地图的垂直 “结束”) Vertical end from google maps

回答

1

好。知道它终于工作! :)

固定的灰色区域(也手柄变焦):

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; 
} 

标记click处理程序:

google_listener = google.maps.event.addListener(marker, 'click', markerHandler); 

function markerHandler(event) { 
    window.console.log(this); 
} 
+0

太棒了!感谢sahring –

2
  1. Map对象已经PROPERT MAXZOOM,将其设置在地图创建

  2. 是它是可能的,你可以添加点击事件,改变弹出窗口打开,因为它是JavaScript你可以添加任何额外的数据就像markr.MyData = 'something interesting'

我不确定你说的是什么灰色部分?我看不出有最大值和最小值变焦灰色部分在谷歌地图

enter image description here

enter image description here

+0

谢谢!得到它几乎工作。你可能知道一种防止滚动地图(进入灰色地带)的方法吗?也许一种方法来计算基于屏幕分辨率minZoom的方式? :) – Lizzaran

+0

可以请你说明你的意思是什么灰色部分?因为我没有看到任何 –

+0

感谢您的帮助。我已经用照片更新了我的帖子。 – Lizzaran

相关问题