Method to bind class to event in google maps v3?

In the V2 Google Maps API, you can associate map events with a class method using the GEvent.bind function:

GEvent.bind(this.drag_marker, "dragstart", this, this.start_dragging_route);

In the above example, you see that the link is from a prototype.init function, where start_dragging_routeis the method inside the class.

It seems that the binding method no longer exists, at least in the documentation. If this is true, I have one way to solve it, but this touch is ugly, so I would like to hear some other solutions to this problem.

How to implement the GEvent.bind function in the Google Maps API V3?

+3
source share
1 answer

Oh right. Shutters. Duh.

var self = this;
google.maps.event.addListener(this.drag_marker, "dragstart", function(latlng) {
    self.start_dragging_route(latlng);
});
+4

Source: https://habr.com/ru/post/1750818/


All Articles