I know that method exists and is documented, but I don't know how to get an MapCanvasProjection object.
+4
A:
To get a MapCanvasProjection you could derive a class from OverlayView and call the getProjection() method which returns a MapCanvasProjection type
onAdd(), draw() and onRemove() must be implemented to derive from OverlayView.
function MyOverlay(options) {
this.setValues(options);
var div = this.div_= document.createElement('div');
div.className = "overlay";
};
// MyOverlay is derived from google.maps.OverlayView
MyOverlay.prototype = new google.maps.OverlayView;
MyOverlay.prototype.onAdd = function() {
var pane = this.getPanes().overlayLayer;
pane.appendChild(this.div_);
}
MyOverlay.prototype.onRemove = function() {
this.div_.parentNode.removeChild(this.div_);
}
MyOverlay.prototype.draw = function() {
var projection = this.getProjection();
var position = projection.fromLatLngToDivPixel(this.getMap().getCenter());
var div = this.div_;
div.style.left = position.x + 'px';
div.style.top = position.y + 'px';
div.style.display = 'block';
};
then when you're creating your map
var OverLayMap = new MyOverlay( { map: map } );
For V2 you should be able to call fromLatLngToDivPixel from your GMap2 instance
var centerPoint = map.fromLatLngToDivPixel(map.getCenter());
Michael G
2009-10-12 18:26:57
aren't you mixing the API v2 with v3?
Jader Dias
2009-10-12 19:26:32
These are from V3
Michael G
2009-10-12 19:28:02
Now with your last edit, it's ok
Jader Dias
2009-10-12 19:34:52
Sorry, it must not have taken a previous edit. :)
Michael G
2009-10-12 19:56:12
I think this is a great problem with the new API. It should have an easier way to do that
Jader Dias
2009-10-12 23:46:53
+4
A:
var map;
// Create your map
MyOverlay.prototype = new google.maps.OverlayView();
MyOverlay.prototype.onAdd = function() { }
MyOverlay.prototype.onRemove = function() { }
MyOverlay.prototype.draw = function() { }
function MyOverlay(map) { this.setMap(map); }
var overlay = new MyOverlay(map);
var projection = overlay.getProjection();
Ralph Stevens
2009-10-31 23:35:55