Hi,
I'm trying to convert the very useful LabeledMarker class to Google Maps API V3:
http://gmaps-utility-library-dev.googlecode.com/svn/tags/labeledmarker/I used it in my V2 map... but I want something similar in my V3 map.
I read Mike's article about extending GMarker:
http://www.googlemapsbook.com/2007/01/22/extending-gmarker/I'm trying to do the same with google.maps.Marker, but I'm running into some problems.
Here's my very simple code:
function LabeledMarker(opts) { // constructor
google.maps.Marker.apply(this, arguments); // call parent constructor (google.maps.Marker)*/
}
LabeledMarker.prototype = new google.maps.Marker();
LabeledMarker.prototype.onAdd = function() {
alert('onAdd1');
google.maps.Marker.prototype.onAdd.apply(this, arguments);
alert('onAdd2');
}
LabeledMarker.prototype.draw = function() {
alert('draw1');
google.maps.Marker.prototype.draw.apply(this, arguments);
alert('draw2');
}
LabeledMarker.prototype.onRemove = function() {
alert('onRemove1');
google.maps.Marker.prototype.onRemove.apply(this, arguments);
alert('onRemove2');
}
Here's how I call it:
var point = new google.maps.LatLng(37, -59);
var labeledMarker = new LabeledMarker({
map: map,
position: point,
labelText: 'Label'
});
Here's a URL:
http://www.canamgroup.ws/GM.nsf/Map2?OpenPageMy Marker is displayed on the map (so I assume that my constructor is successfully calling the google.maps.Marker constructor) but my alerts in onAdd, draw and onRemove are never triggered (so I assume that my methods are not successfully calling the google.maps.Marker methods).
This is the way Mike was doing it though in V2 (except the method names were different).
I tried:
google.maps.Marker.prototype.draw.apply(this, arguments);
google.maps.Marker.prototype.draw.apply(this);
google.maps.Marker.prototype.draw.call(this);
google.maps.Marker.prototype.draw.call(this, arguments);
I'm just beginning to code OO Javascript, so I might be missing something?
Or maybe I have to do something different in V3?
Can someone help?
Thanks!