Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using timeouts to advance through functions 1

Status
Not open for further replies.

Nevermoor

Programmer
Jul 25, 2003
218
US
I am working with AutoCad Mapguide, and having a huge javascript problem. The problem stems from the fact that the actual Mapguide activeX cannot be manipulated when it is in a "busy" state, and therefore I must wait for it to leave that state before I can further interact with it. (the page uses frames)

The basic structure is as follows:

In top layer, which is not ever refreshed:
Code:
function whenMapReady(str)
{
	var busy = mapFrame.getMap().isBusy();
	if (busy){setTimeout("whenMapReady("+str+")",1000);}
	if (!busy) {eval (str);}
}

In a side layer (named info, parent = top), which does not refresh until the very end:
Code:
function send() { //Turns on layer, zooms wide, clears selection
myMap = parent.mapFrame.getMap();
myMap.zoomWidth(<%=centerY%>,<%=centerX%>,SetWidth(<%=height%>,<%=width%>),"FT");
var layers = myMap.getMapLayerGroup("LotInfo")
layers.setVisibility(true);	
var mapSel = myMap.getSelection();
mapSel.clear(); //this sends map into busy state
parent.whenMapReady("self.info.zoomToSelection()");
}
function zoomToSelection(){//Zooms to the selection found
myMap.zoomSelected();
}

The way I understand this to work is that the top function will execute, and if the map is busy it will set a timeout which allows the map to continue working and try again in 1 second.

In practice, however, the top function calls the second info function no matter what, and if the map was busy, the timeout is set but evaluates later.

Anyone have any ideas on how to wait for a flag to change (while allowing continued operation) before calling the next step in a procedure?

Thank you
 

Try changing your "whenMapReady" to this:

Code:
function whenMapReady(str)
{
	var busy = mapFrame.getMap().isBusy();
	if (busy) {
		setTimeout('whenMapReady(\'' + str + '\')', 1000);
	} else {
		eval(str);
	}
}

You were omitting the quotes needed to pass the "str" variable back through as a string. Although that doesn't explain why it executed anyway, but should avoid later issues ;o)

Hope this helps,
Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top