Re: Make target move to center of viewport
What happens is that the map only supports one pan animation at any one
time. The pan operations run asynchronously, and can take a few seconds
to complete using a series of onTimeout() calls to handle each frame of
the animation. Your next Javascript statement is processed before the
second frame of the animation gets processed and if that causes another
pan operation, the details of the existing pan operation get
overwritten.
This doesn't happen with map.centerAndZoom or with map.centerAtLatLng
because they execute immediately, causing the map centre to be redefined
before the map.openInfoWindowHtml call happens.
What you can do is to wait for the map.recenterOrPanToLatLng to complete
before opening the info window.
var destination = -1;
function myclick(i)
{
map.closeInfoWindow();
map.zoomTo(3);
destination = i;
map.recenterOrPanToLatLng(gpoints[i]);
}
GEvent.addListener(map, "moveend", function() {
if (destination > -1) {
map.openInfoWindowHtml(gpoints[destination],
htmls[destination]);
destination = -1;
}
});
Notes:
1. That listener is going to listen for every moveend event, but we only
want to open the info window if the moveend is the one following a
myclick()
2. Can't use "if(destination)" because zero is a valid marker index.
3. It is necessary to close the existing info window, because the
existence of an info window open on a different marker can adversely
affect the map.recenterOrPanToLatLng operation.
4. If the zoom level starts off higher than 3, it works better if you
move the "map.zoomTo(3)" into the listener. There's a better chance of
map.recenterOrPanToLatLng deciding to perform a pan at higher zoom
levels.
--
Mike Williams
Gentleman of Leisure
0 Comments:
Yorum Gönder
<< Home