簡體   English   中英

為什么在Google Maps v3上使用MVCObject更改縮放比例后,我的代碼無法提醒地圖的縮放比例

[英]why my code can't alert the map's zoom when zoom changed using MVCObject on google-maps v3

這是我的代碼:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    function A(){
        this.set('zoom',map.zoom);
        this.bindTo('zoom', map);
    }
    A.prototype = new google.maps.MVCObject();
    A.prototype.zoom_changed = function () {
        alert(map.zoom)
    }
    }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

我想在使用MVCObject更改縮放時提醒map.zoom,

但沒有工作。 謝謝

現在還可以:

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);
    function A(){
        this.bindTo('zoom', map);
    }
    A.prototype = new google.maps.MVCObject();
    A.prototype.zoom_changed = function () {
        alert(this.get('zoom'))
    }
    var a=new A()
    }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0px; padding: 0px }
  #map_canvas { height: 100% }
</style>
<script type="text/javascript"src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(-34.397, 150.644);
    var myOptions = {
      zoom: 8,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

    var marker = new google.maps.Marker({
                position: map.getCenter(),
                draggable:true,
                map: map});
    //map.bounds_=map.getBounds()
    //console.log(map.get('bounds'))
    function A(){
        this.bindTo('zoom', map);
        //this.set('marker', marker);
        marker.bindTo('position',map,'center')
        //this.bindTo('')
    }
    A.prototype = new google.maps.MVCObject();
    A.prototype.zoom_changed = function () {
        //if(this.get('marker'))
        //console.log(this.get('marker'))
        console.log(map.get('center'))
    }
    google.maps.Marker.prototype.position_changed = function () {
        console.log('sss')
    }
    var a=new A()
    }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>

嘗試這個:

alert(map.getZoom())

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM