Note that there are some explanatory texts on larger screens.

plurals
  1. PODelay between creation and display of polygons
    text
    copied!<p>To create polygons in my map, I am using <code>jQuery.getJSON()</code> to load geojson files containing polygons and multipolygons. Then I analyse the geojson with a github plugin (loadgeojson) and finally the polygons are created on the map.</p> <p>I put a <code>&lt;div&gt;</code> with a loading gif that overlays the map that appears just before the <code>jQuery.getJSON()</code> is being called. </p> <p>The problem is the timing to remove it. I make the loading animation disappears when all the polygons <strong>visible</strong> property is set to <strong>True</strong>.</p> <p>I want the <code>&lt;div&gt;</code> to disappears when the polygons appears on the map. But for the moment, it disappear a little before this. So on slower browser there is a relatively big delay between the <code>&lt;div&gt;</code> disappearing and the polygons appearing.</p> <p>I tried to put a listener on an event but I couldn't find an event that corresponded to what I want.</p> <p>How can I remove the loading animation right on time when the polygons appears on my map?</p> <p>Here's my code:</p> <pre><code>function readJSON(id){ showLoadingAnimation(); // If .json hasn't been read if(stockArray[id].length == 0) { $.getJSON(id + ".json", function(data){ showFeature(data, id) }) } } function showFeature(geojson, elemtype){ currentFeature_or_Features = new GeoJSON(geojson, elemtype, options); if (currentFeature_or_Features.type &amp;&amp; currentFeature_or_Features.type == "Error"){ return; } // Display object if (currentFeature_or_Features.length){ for (var i = 0; i &lt; currentFeature_or_Features.length; i++){ if(currentFeature_or_Features[i].length){ for(var j = 0; j &lt; currentFeature_or_Features[i].length; j++){ // Display multipolygon currentFeature_or_Features[i][j].setMap(map); // Mouse events for multipolygons mouseEventsMulti(i,j,elemtype); } } else{ // Display polygons, polylines and points currentFeature_or_Features[i].setMap(map); // Mouse events for polygons, polylines and points mouseEventsSimple(i,elemtype) } } } else { currentFeature_or_Features.setMap(map) } // Stop loading animation dontShowLoadingAnimation(); } </code></pre>
 

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