2011-02-22 14:49:03 +01:00
|
|
|
function CustomMarker(latlng, map, oncreated) {
|
2010-12-28 14:41:44 +01:00
|
|
|
google.maps.OverlayView.call(this);
|
|
|
|
|
|
|
|
this.latlng_ = latlng;
|
|
|
|
|
|
|
|
// Once the LatLng and text are set, add the overlay to the map. This will
|
|
|
|
// trigger a call to panes_changed which should in turn call draw.
|
|
|
|
this.setMap(map);
|
|
|
|
|
|
|
|
this.oncreated = oncreated;
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomMarker.prototype = new google.maps.OverlayView();
|
|
|
|
|
|
|
|
CustomMarker.prototype.draw = function() {
|
|
|
|
var me = this;
|
2011-02-06 03:00:51 +01:00
|
|
|
if (this.removed)
|
|
|
|
return;
|
2010-12-28 14:41:44 +01:00
|
|
|
// Check if the div has been created.
|
|
|
|
var div = this.div_;
|
|
|
|
if (!div) {
|
|
|
|
// Create a overlay text DIV
|
|
|
|
div = this.div_ = document.createElement('DIV');
|
|
|
|
// Create the DIV representing our CustomMarker
|
|
|
|
div.style.position = "absolute";
|
|
|
|
|
|
|
|
google.maps.event.addDomListener(div, "click", function(event) {
|
|
|
|
google.maps.event.trigger(me, "click");
|
|
|
|
});
|
|
|
|
|
2011-02-22 14:49:03 +01:00
|
|
|
this.oncreated(div);
|
2010-12-28 14:41:44 +01:00
|
|
|
|
|
|
|
// Then add the overlay to the DOM
|
|
|
|
var panes = this.getPanes();
|
|
|
|
panes.overlayLayer.appendChild(div);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Position the overlay
|
|
|
|
var point = this.getProjection().fromLatLngToDivPixel(this.latlng_);
|
|
|
|
if (point) {
|
|
|
|
div.style.left = point.x + 'px';
|
|
|
|
div.style.top = point.y + 'px';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
CustomMarker.prototype.setPosition = function(p) {
|
|
|
|
this.latlng_ = p;
|
|
|
|
var projection = this.getProjection();
|
|
|
|
if (projection) {
|
|
|
|
var point = projection.fromLatLngToDivPixel(this.latlng_);
|
|
|
|
this.div_.style.left = point.x + 'px';
|
|
|
|
this.div_.style.top = point.y + 'px';
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-12-31 13:33:51 +01:00
|
|
|
CustomMarker.prototype.getPosition = function(p) {
|
|
|
|
return this.latlng_;
|
|
|
|
};
|
|
|
|
|
2010-12-28 14:41:44 +01:00
|
|
|
CustomMarker.prototype.hide = function() {
|
|
|
|
if (this.div_ && !this.isHidden) {
|
|
|
|
this.div_.style.display = 'none';
|
|
|
|
this.isHidden = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CustomMarker.prototype.show = function() {
|
|
|
|
if (this.div_ && this.isHidden) {
|
|
|
|
this.div_.style.display = 'block';
|
|
|
|
this.isHidden = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-12 02:03:31 +01:00
|
|
|
CustomMarker.prototype.toggle = function(t) {
|
2011-02-18 00:07:59 +01:00
|
|
|
if ((typeof t) == "boolean") {
|
|
|
|
if (t) { this.show(); }
|
|
|
|
else { this.hide(); }
|
2011-01-12 02:03:31 +01:00
|
|
|
} else {
|
2011-02-18 00:07:59 +01:00
|
|
|
this.toggle((this.isHidden) == true);
|
2011-01-12 02:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-28 14:41:44 +01:00
|
|
|
CustomMarker.prototype.remove = function() {
|
|
|
|
// Check if the overlay was on the map and needs to be removed.
|
|
|
|
if (this.div_) {
|
|
|
|
this.div_.parentNode.removeChild(this.div_);
|
|
|
|
this.div_ = null;
|
2011-02-06 03:00:51 +01:00
|
|
|
this.removed = true;
|
2010-12-28 14:41:44 +01:00
|
|
|
}
|
|
|
|
};
|