I had a somewhat confused face wondering whether I was just waiting for a slow connection to load one of the tile overlays on one side of the Google Map I was trying to implement in a page for the site I’m currently working on, until I stepped through the DOM / Script to notice a problem with GMaps overlays being out of sync due to the time they were taking to load.
This inevitably had the effect of making it impossible for the GMaps API to calculate the visible area until everything had initialised first, making the map controls think the overlay area was smaller than it really was.
It’s nice to see the inclusion of a checkResize method within the GMaps API, calling it through a simple setTimeout sorted the problem, however it would be nice if Google actually incorporated a live event to automagically fire the proceedures within the checkResize when the map container is resized, I guess it leaves things more open for us though, not all platforms will have resizable windows containing maps.
For the record I was using Cody Lindley’s ThickBox for the Lightbox
// Map code
var Horton = Horton || { };
Horton.GMap = function () {
return {
init: function () {
if ( GBrowserIsCompatible() ) {
mapContainer = new GMap2( document.getElementById("map1") );
mapContainer.setCenter( new GLatLng(37.4419, -122.1419), 13 );
mapContainer.addControl( new GSmallMapControl() );
mapGeocoder = new GClientGeocoder();
Horton.GMap().showAddress("An Address");
}
},
showAddress: function (address) {
if (mapGeocoder) {
mapGeocoder.getLatLng( address, function(point) {
if (!point) {
alert("There seems to have been a problem");
} else {
mapContainer.setCenter(point, 13);
var marker = new GMarker(point);
mapContainer.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
});
}
setTimeout('Horton.GMap().reloadContainer()', 10);
},
reloadContainer: function () {
mapContainer.checkResize();
}
};
};
OH crud! i just typed a nice comment and as soon as i submitted it it come up blank! Please tell me it worked properly? I do not want to sumit it again if i do not have to! Either the blog bugged out or i am just stuipd
, the latter doesnt surprise me lol.
Dan
Do you have an example of this working anywhere. I am using colorbox for my lightbox and can’t seem to get this to work.
Thanks for your help.
Nigel
The code above was implemented here, click the open map view link to see the implementation – http://www.hortonchiropractic.com/contact_us.php