Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've had this issue as well. The problem is jQuery Mobile's page layout interferes with the size calculations of the OpenLayers.Map object. What you have is a viewer that is full width, but zero height.</p> <p>Here's what we did (most of this code was adapted from the <a href="http://openlayers.org/dev/examples/mobile-jq.html" rel="nofollow">JQuery Mobile example</a>)</p> <p>Firstly, override the OpenLayers.Map.getCurrentSize() function:</p> <pre><code>OpenLayers.Map.prototype.getCurrentSize = function() { var mapDiv = $(this.div); return new OpenLayers.Size(mapDiv.width(), mapDiv.height()); }; </code></pre> <p>Secondly, we structured the JQM page like so:</p> <pre><code>&lt;div data-role="page"&gt; &lt;div data-role="header"&gt; &lt;h3&gt;Map Viewer&lt;/h3&gt; &lt;/div&gt; &lt;div data-role="content" id="viewerContainer"&gt; &lt;div id="viewer"&gt; &lt;/div&gt; &lt;/div&gt; &lt;div data-role="footer"&gt; &lt;h3&gt;My footer&lt;/h3&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>Then we put in a functions to prep the correct container height for the OpenLayers map and to ensure the correct height afterwards</p> <pre><code>function fixContentHeight(olMap) { var footer = $("div[data-role='footer']:visible"), content = $("div[data-role='content']:visible:visible"), viewHeight = $(window).height(), contentHeight = viewHeight - footer.outerHeight(); if ((content.outerHeight() + footer.outerHeight()) !== viewHeight) { contentHeight -= (content.outerHeight() - content.height() + 1); content.height(contentHeight); } content.width($(window).width()); olMap.updateSize(); } function ensureNonZeroHeight(containerid) { var footer = $("div[id='" + containerid + "'] &gt; div[data-role='footer']"), header = $("div[id='" + containerid + "'] &gt; div[data-role='header']"), content = $("div[id='" + containerid + "'] &gt; div[data-role='content']"), viewHeight = $(window).height(), contentHeight = viewHeight - footer.outerHeight() - header.outerHeight(); if ((content.outerHeight() + footer.outerHeight() + header.outerHeight()) !== viewHeight) { contentHeight -= (content.outerHeight() - content.height() + 1); content.height(contentHeight); content.width($(window).width()); } } </code></pre> <p>Then finally, the OpenLayers.Map is set up like so:</p> <pre><code>ensureNonZeroHeight("viewerContainer"); var map = new OpenLayers.Map("viewer", { /* other options */ }); /* Other map initialization code */ fixContentHeight(map); </code></pre> <p>And ensure that fixContentHeight() is called whenever this page is presented.</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