代码之家  ›  专栏  ›  技术社区  ›  fredrik

在使用MVC的谷歌地图API版本3中,zoom_只更改了一次触发器

  •  0
  • fredrik  · 技术社区  · 14 年前

    我正在尝试在谷歌地图3版中使用MVC对象。我不明白的是为什么 zoom_changed 方法只被调用一次。当我第一次载入地图时 变焦距 方法被调用。但当我放大地图的时候就不行了。

    function MarkerWidget (options) {
        this.setValues(options);
        this.set('zoom', this.map.zoom);
    
        var marker = new google.maps.Marker({
                icon : this.icon,
                mouseOverIcon : this.mouseOverIcon,
                orgIcon : this.orgIcon
        });
    
        marker.bindTo('map', this);
        marker.bindTo('position', this);
    
        google.maps.event.addListener(marker, 'mouseover', this.onmouseover);
        google.maps.event.addListener(marker, 'mouseout', this.onmouseout);
    }
    
    MarkerWidget.prototype = new google.maps.MVCObject();
    MarkerWidget.prototype.zoom_changed = function () {
        $.log(this, new Date());
    }
    

    地图对象是否应触发缩放事件并通知所有具有“this.set(‘zoom’,this.map.zoom)”的对象?

    1 回复  |  直到 11 年前
        1
  •  1
  •   Tim Banks    11 年前

    找到了解决方案。请参阅我对原帖子的评论。

    以下引用的注释:

    找到解决方案后,需要指定一个未设置的bindto!即this.bindto(“缩放”,this.map);