Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've come across a similar problem when dealing with waiting for markers and infoWindows to load before executing a function. I found a solution here ( <a href="https://stackoverflow.com/questions/832692/how-to-check-if-google-maps-is-fully-loaded">How can I check whether Google Maps is fully loaded?</a> see @Veseliq's answer) that using the google maps event listener function for checking when the map is 'idle', does the trick. I assume this solution would work for KML layers as well. Essentially what you will have to do is include the following at the end of your initialize function:</p> <pre><code>google.maps.event.addListenerOnce(map, 'idle', function(){ // do something only the first time the map is loaded }); </code></pre> <p>In the API reference ( <a href="https://developers.google.com/maps/documentation/javascript/reference" rel="nofollow noreferrer">https://developers.google.com/maps/documentation/javascript/reference</a> ) it states that the 'idle' event "is fired when the map becomes idle after panning or zooming". However, it seems to hold true that it is also fires on initial page load after everything in the map_canvas has loaded. And by using the <code>addListenerOnce</code> call, you ensure that it is never executed again after the initial page load (meaning it won't fire after a zoom or a pan action).</p> <hr> <p>Second option:<br> As I mentioned you can take the callback approach, I believe this will only call your urlClick function after completing the parsing. Here's how you should probably arrange your code to make it work:</p> <pre><code>function someFunction(callback){ myParser.parse(['/maps/kml/shapes.kml','/maps/kml/shapes_hidden.kml']); callback(); } </code></pre> <p>and then in your initialize you will have:</p> <pre><code>someFunction(function(){ urlClick(); }); </code></pre> <p>You will have to make your <code>map</code> and <code>myParser</code> variables global.</p> <p>Resources: This link had an excellent and detailed brief on how callback functions work in javascript, <a href="http://www.impressivewebs.com/callback-functions-javascript/" rel="nofollow noreferrer">http://www.impressivewebs.com/callback-functions-javascript/</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload