If you call some background operation whenever the user finishing zooming or panning the map (like dynamically loading pushpins) you have probably found you end up doing lots and lots of calls to your operation. This is a way to ensure the user has definatly finished moving the map before commiting the potentially expensive operation.
The code pauses for 1 sec (can be changed) then checks the user has not moved the map during that one second before calling the operation (in this case the custom buildSearch javascript method).
You will of course need to attach the map events to your functions first
Code:
map.AttachEvent("onendcontinuouspan", mapPanEnd);
map.AttachEvent("onendzoom", mapZoomEnd);
Code:
var timelastsearchrequested;
function mapPanEnd(){
//re-run search for new view
checkUserMapMovingFinished();
}
function mapZoomEnd(){
//re-run search for new view
checkUserMapMovingFinished();
}
function checkUserMapMovingFinished(timecalled){
if(timecalled==null){
//get current time
timecalled = new Date().getTime();
//update member to store time
timelastsearchrequested=timecalled;
//call this method again with timecalled, 1 secs later
setTimeout("checkUserMapMovingFinished(" + timecalled + ")",1000);
}
else{
//build search if another move has not happened
if(timecalled==timelastsearchrequested) buildSearch();
}
}