javascript - Google Maps API MVC 示例说明

标签 javascript model-view-controller google-maps-api-3 google-maps-markers

我正在查看 Google Maps API MVC 使用示例。请参阅https://developers.google.com/maps/articles/mvcfun?csw=1

在第一个简单示例中,我无法理解marker.bindTo() 调用。 bindTo() 实际上是 MVC 对象的一个​​方法(参见https://developers.google.com/maps/documentation/javascript/reference#MVCObject)。标记本身不是 MVC 对象,而是以 MVC 对象作为其原型(prototype)的对象的属性。那么这个bindTo方法是如何关联为marker的属性的呢?

可能是我在这里缺少的一些基本内容!

感谢您的解释。

    /**
    * A distance widget that will display a circle that can be resized and will
    * provide the radius in km.
    *
    * @param {google.maps.Map} map The map on which to attach the distance widget.
    *
    * @constructor
    */
    function DistanceWidget(map) {
    this.set('map', map);
    this.set('position', map.getCenter());

    var marker = new google.maps.Marker({
    draggable: true,
    title: 'Move me!'
    });

    // Bind the marker map property to the DistanceWidget map property
    marker.bindTo('map', this);

    // Bind the marker position property to the DistanceWidget position
    // property
    marker.bindTo('position', this);
    }
    DistanceWidget.prototype = new google.maps.MVCObject();

最佳答案

描述可以在 documentation of MVCObject 找到:

MVCObject 构造函数保证是一个空函数,因此您只需编写 MySubclass.prototype = new google.maps.MVCObject(); 即可从 MVCObject 继承

此技术还将用于 google.maps.Marker 实例。

google.maps.Marker 实例的构造函数google.maps.MVCObject 实例的构造函数,因此标记将具有 MVCObject 的方法

因此,google.maps.Marker 的实例基本上是一个使用 google.maps.Marker 原型(prototype)的属性/方法进行扩展的 MVCObject

关于javascript - Google Maps API MVC 示例说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23082003/

相关文章:

c# - 如何访问自定义 ActionFilterAttribute 中的模型和元数据?

ajax 中的 HTML block

javascript - 在我的内存游戏脚本中添加时间计数器

javascript - 如何从另一个线程向多个线程发送消息?

javascript - 动态进度条Javascript和HTML

java - 如何在没有 <form> 元素的情况下将参数从 JSP 页面发送到 Servlet

javascript - 使用 Google Map Api 时出现错误。 Google Api key 无权使用此 api

javascript - 单击多边形时无法弹出信息气泡

c# - 使用 C# 使用数据库中的新数据每 1 分钟更新一次 Google Maps Javascript 对象?

javascript - 带有不可拖动子图像的可拖动 div 上的 FireFox 问题