2012-02-21 55 views
5

我有以下代碼工作正常,但我無法添加縮放級別。根據docs它應該與'option', 'zoom', 7一起工作,但這會產生一個錯誤:"$("#map_canvas").gmap("option", "zoom", 7).bind is not a function"jquery-ui-map如何設置縮放級別

工作代碼,sans縮放,編輯。縮放始終爲1.

$("#map_trigger").click(function(){ 
     var prop_id = $("#map_canvas").attr("rel"); 
     $('#map_canvas').gmap({'zoom':6}).bind('init', function(evt, map) { 
      $.getJSON(basepath+'properties/get_gps_coords/'+prop_id, function(data) { 
       $.each(data.markers, function(i, m) { 
        lat = m.latitude; 
        longitude = m.longitude; 
        $('#map_canvas').gmap(
         'addMarker', { 'position': new google.maps.LatLng(lat, m.longitude), 'bounds':true } 
        ); 
       }); 
      }); 
     }); 
    }); 

如何向此代碼段添加縮放級別?

回答

8

用途:

$("#map_canvas").gmap({'zoom':7}) 

選項,方法可以在地圖上已經被初始化並且不會返回一個jQuery對象中使用,所以它不是可鏈接(什麼會解釋你得到了錯誤)。

+1

哪裏?我嘗試了不同的位置,在'.bind'('init',' – stef 2012-02-21 10:40:40

+0

這不是最大值,它是顯示所需的縮放比例所有標記,因爲您在標記創建過程中將「邊界」設置爲true。將邊界設置爲false並將地圖中心設置爲標記位置 – 2012-02-21 10:44:29

+0

'之前更新了我的代碼,但縮放總是最大的時候 – stef 2012-02-21 10:51:18

10

此代碼的工作對我來說:

<!doctype html> 
<html> 
    <head> 
     <meta http-equiv="content-language" content="es"> 
     <meta charset="utf-8"> 

     <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
     <script type="text/javascript" src="js/jquery-1.7.1/jquery.min.js"></script> 
     <script type="text/javascript" src="../ui/jquery.ui.map.js"></script> 

    </head> 
    <body> 
     <div style="height: 500px; width:500px;" id="map_canvas"></div> 
     <button id="btnChangeZoom">change zoom</button> 
     <script type="text/javascript"> 
     $(function() { 
      $('#map_canvas').gmap({ 'center': '40.33238,-3.76546','scrollwheel':false}); 
      $('#map_canvas').gmap('option', 'mapTypeId', google.maps.MapTypeId.SATELLITE); 
      $('#map_canvas').gmap('option', 'zoom', 17); 
      }); 

     $("#btnChangeZoom").click(function(){changeZoom()}); 

     function changeZoom(){ 
      $('#map_canvas').gmap('option', 'zoom', 10); 
     } 
     </script> 
    </body> 
</html> 
2

呦需要到中心的地圖,然後放大它。這裏是一個代碼示例

$('#map_canvas').gmap({'center': '43.1502, 25.02083'}) 
$('#map_canvas').gmap('option', 'zoom', 10); 
$('#map_canvas').gmap('addMarker', {'position': '43.1502, 25.02083', 'icon': '/picnic/img/Pin.png'}).click(function() { 
    //$('#map_canvas').gmap('openInfoWindow', {'content': 'Hello World!'}, this); 
});