I'm trying to register an event listener that updates the global
variables. The script works fine in a basic setup, but I hit problems
if I try to make use of OOP with references to 'this.'
Anonymous function that handles the event figures that 'this.' refers
to a map object, not to 'this.' inside the closure. Here is the
failing part:
---
MyClass = function() {
this.mouse_pos = null;
this.linewindow = new google.maps.InfoWindow({});
this.init();
};
MyClass.prototype.init = function() {
// Adding mouse events for
infowindow
google.maps.event.addListener(this.map, "mousemove", function (pos)
{
if ( pos !== null )
{
this.mouse_pos =
pos;
}
if ( this.mouse_over == true )
{
this.linewindow.setPosition(new
google.maps.LatLng(this.mouse_pos.latLng.b,
this.mouse_pos.latLng.c));
}
else
{
this.linewindow.close();
}
});
---
When the script executes, this.linewindow and this.mouse_pos is
undefined.
Is there a way to refer to 'this.' of the closure?
-Valas
--
You received this message because you are subscribed to the Google Groups
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-js-api-v3?hl=en.