admin管理员组文章数量:1415460
I am looking at the Google Maps API MVC usage example. See
In the first simple example, I am unable to understand the marker.bindTo() call. The bindTo() is actually a method of the MVC object (See ). marker itself is not an MVC object but a property of an object that has a MVC object as its prototype. So how is this bindTo method associated as a property of marker?
May be something elementary that I am missing here!
Thanks for any explanation.
/**
* 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();
I am looking at the Google Maps API MVC usage example. See https://developers.google./maps/articles/mvcfun?csw=1
In the first simple example, I am unable to understand the marker.bindTo() call. The bindTo() is actually a method of the MVC object (See https://developers.google./maps/documentation/javascript/reference#MVCObject). marker itself is not an MVC object but a property of an object that has a MVC object as its prototype. So how is this bindTo method associated as a property of marker?
May be something elementary that I am missing here!
Thanks for any explanation.
/**
* 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();
Share
Improve this question
edited Apr 15, 2014 at 11:18
Sunny
asked Apr 15, 2014 at 11:12
SunnySunny
10.1k12 gold badges55 silver badges91 bronze badges
2 Answers
Reset to default 5The description may be found at the documentation of MVCObject:
The MVCObject constructor is guaranteed to be an empty function, and so you may inherit from MVCObject by simply writing MySubclass.prototype = new google.maps.MVCObject();
This technique will also be used for a google.maps.Marker
-instance.
The constructor of a google.maps.Marker
-instance is the constructor of a google.maps.MVCObject
-instance, so a Marker will have the methods of a MVCObject
So the instance of a google.maps.Marker
basically is an MVCObject extended with properties/methods of the google.maps.Marker
-prototype
You are right bindTo
is a MVC model object function. there is MVC model object is the object of map which is set from
DistanceWidget.prototype = new google.maps.MVCObject();
above line.
bindTo(key:string, target:MVCObject, targetKey?:string, noNotify?:boolean);
And as per documentation the second parameter of bondTo is a MVC object. and in the above first line of code there is pass the object of map by using the this keyword.
So this
is the MVC object of map class which is called in the above line. you can see it in your code also.
marker.bindTo('map', this);
And DistanceWidget
is a function which has the object of map class that why bondTo has the MVC Object which is correct.
本文标签: javascriptGoogle Maps API MVC example clarificationStack Overflow
版权声明:本文标题:javascript - Google Maps API MVC example clarification - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745166386a2645705.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论