Jump to content

Timing Issue


wychegnome

Recommended Posts

At least I think it is a timing issue but I could be wrong.

 

I have a web page that loads an Ordnance Survey (UK) map into a window and then needs to add a series of overlays containing my own data. The overlays do not always load with one or all 'missing' when the page is loaded. The situation is worsened when the page is refreshed. And which overlay file(s) is missed seems to vary randomly.

 

<body onLoad="initialiseMap()"> triggers the sequence and the following code forms a part of that sequence:

 

$(document).ready(function(){ var commonOneFile = myMapPath + "common1.js"; var venueFile = myMapPath + "venues.js"; $.getScript(commonOneFile, function() { }); $.getScript(venueFile, function() { });// and load selective markers and lines if we have a file name to work from if (myFileName.length > 2) { var commonTwoFile = myMapPath + "common2.js"; var linesFile = myMapPath + myFileName + "lines.js"; var markersFile = myMapPath + myFileName + "markers.js"; $.getScript(commonTwoFile, function() { }); $.getScript(linesFile, function() { }); $.getScript(markersFile, function() { }); } }); // end of document.ready function

The files must be called in the sequence shown as the content of the second file is dependent on the content of the first one and so on. The last two must follow as fourth and fifth but can be in either order.

 

I have tried both with and without using the document.ready function and the results are much the same either way.

 

It also seems to make no difference whether I call these overlay scripts before or after the map is created.

 

Is there a better or more reliable way of ensuring all the (two or five) required javascript files are fully read in the correct sequence before the map page is presented to the user?

 

Thanks

Link to comment
Share on other sites

It looks like the getScript function has a callback, so you can use that to load the next one.

$.getScript(commonOneFile, function() {  $.getScript(venueFile, function() {    // load third one    });});
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...