Ticket #1979 (closed bug: duplicate)
ScaleLine Control: runtime error on IE when only one unit is set
| Reported by: | openlayers | Owned by: | tschaub |
|---|---|---|---|
| Priority: | minor | Milestone: | 2.8 Release |
| Component: | Control.ScaleLine | Version: | 2.7 |
| Keywords: | scaleline runtime error | Cc: | battisti@… |
| State: |
Description
The ScaleLine control, (ScaleLine.js, update() function) has a small glitch.
It computes the width of the scale element without first checking if the element is visible.
If no units are specified for one of the two elements, then the computing of the width involves NaN values and doesn't make sense. As a side effect, triggers a runtime error on IE.
/* works */ scaleControl = new OpenLayers.Control.ScaleLine();
/* triggers a runtime error on IE (tried on IE 6, 7 and 8) */ scaleControl = new OpenLayers.Control.ScaleLine( { bottomOutUnits: "", bottomInUnits: "" } );
A simple workaround would be to compute the top and bottom elements width only if they are visible, for example:
topPx = 0; bottomPx = 0;
if ( this.eTop.style.visibility == "visible" )
{
var topMax = maxSizeData / inches[topUnits];
var topRounded = this.getBarLen(topMax);
topMax = topRounded / inches[curMapUnits] * inches[topUnits];
topPx = topMax / res;
}
if ( this.eBottom.style.visibility == "visible" )
{
var bottomMax = maxSizeData / inches[bottomUnits];
var bottomRounded = this.getBarLen(bottomMax);
bottomMax = bottomRounded / inches[curMapUnits] * inches[bottomUnits];
bottomPx = bottomMax / res;
}
