Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript method processing fixed by alert()
    text
    copied!<p>I have SWT application which uses <a href="http://api4.mapy.cz" rel="nofollow">map service API</a> (<a href="http://mapy.cz" rel="nofollow">http://mapy.cz</a> particularly) for acquiring image as background for some additional drawings based on that provided map data.</p> <p>Before the browser component screenshot is made by SWT GC instance, I'm trying to hide the controls from map layer, to have it cleanest as possible. This functionality is provided by service's JS API this way:</p> <pre class="lang-js prettyprint-override"><code>function hideControls() { var controls = map.getControls(); for (var i = controls.length; i &gt; 0; i--) { map.removeControl(controls[i]); } //alert('test'); } </code></pre> <p>This <strong>works absolutely flawless in all desktop browsers</strong> by calling <code>hideControls()</code> function from console. </p> <p>But if the method is called by SWT Browser component by </p> <pre><code>browser.evaluate("hideControls();"); </code></pre> <p><strong>it just do not work until the alert() function</strong> (as commented right now) <strong>is uncommented.</strong> Then alert dialog is shown and controls hidden as they should be.</p> <p>Any idea why <code>alert()</code> method call cause correct working of that JavaScript function?</p> <p><strong>EDIT</strong></p> <p>Some additional code context </p> <pre><code>browser.evaluate("hideControls();"); // ugly ie scroll bar force workaround // calls JS methods which returns size of map content in browser component Double mapWidth = (Double) browser.evaluate("return getSizeX();"); Double mapHeight = (Double) browser.evaluate("return getSizeY();"); // creates new canvas GC gc = new GC(browser); // do the screenshot capturedImage = new Image(display, mapWidth.intValue(), mapHeight.intValue()); gc.copyArea(capturedImage, 0, 0); // cleanout gc.dispose(); </code></pre> <p>JavaScript methods for map size calculation (provided by JS API for map service)</p> <pre class="lang-js prettyprint-override"><code>function getSizeX() { return map.getSize().x; } function getSizeY() { return map.getSize().y; } </code></pre> <p><strong>EDIT2</strong></p> <p>After some deeper debug the method which removes controls from map layer is</p> <pre class="lang-js prettyprint-override"><code>SMap.prototype.removeControl = function (a) { var b = this.controls.indexOf(a); - 1 != b &amp;&amp; ((a = a.getContainer()) &amp;&amp; this.controlLayer.removeItem(a), this.controls.splice(b, 1)) }; </code></pre> <p>So for instance (for HUD control)</p> <pre class="lang-js prettyprint-override"><code>SMap.Layer.HUD.prototype.removeItem = function (a) { a.parentNode.removeChild(a) }; </code></pre> <p>That means it directly change the DOM tree, though it's not asynchronous..</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