Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. COThat is a very ideal solution; however, in testing it I come across one little issue. When I run it in Firefox- which is apparently weighed down by something for it is dreadfully slow- it works. However, if I try it in the much faster Chrome, I receive the same error. I assume that, since the parser is not part of the map itself and instead simply adds/passes shapes to the map, if the map completely loads what it has internally and hits idle before the parser is done parsing, I still get the "active is null" error. It would seem that this route of delaying based on the map won't work. >_<
      singulars
    2. COInteresting, I did not notice that the layer the parser creates was independent of the map itself. If this is the case, then you can probably achieve this by putting the `myParser.parse(['/maps/kml/shapes.kml','/maps/kml/shapes_hidden.kml']);` in a separate function, then calling the `urlClick()` function as a callback to the other one. I will update my answer.
      singulars
    3. COOh, that's an interesting technique; I'll have to try and remember it. This has the opposite effect however, for reasons I can not guess the reason for, in that it works in Chrome, but not in Firefox. (Un)fortunately, removing the parser appears to work perfectly and, while I thank you for your assistance, I feel removing the parser will do much more good than leaving it in with some tricky fix to make unique urls. At the very least, I've learned a few things. ;3
      singulars
 

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