diff --git a/lib/OpenLayers/Control/Scale.js b/lib/OpenLayers/Control/Scale.js index b8511e5127..6aa4d0f720 100644 --- a/lib/OpenLayers/Control/Scale.js +++ b/lib/OpenLayers/Control/Scale.js @@ -47,7 +47,7 @@ OpenLayers.Control.Scale.prototype = if (!this.element) { this.element = document.createElement("div"); this.div.style.right = "3px"; - this.div.style.bottom = "3px"; + this.div.style.bottom = "2em"; this.div.style.left = ""; this.div.style.top = ""; this.div.style.display = "block"; @@ -55,16 +55,26 @@ OpenLayers.Control.Scale.prototype = this.element.style.fontSize="smaller"; this.div.appendChild(this.element); } - this.map.events.register( 'moveend', this, this.updateLink); + this.map.events.register( 'moveend', this, this.updateScale); + this.updateScale(); return this.div; }, /** * */ - updateLink: function() { + updateScale: function() { var res = this.map.getResolution(); - var scale = 1 / (res * self.INCHES_PER_UNIT[self.units] * self.dpi); + if (!res) return; + + var scale = res * this.INCHES_PER_UNIT[this.units] * this.dpi; + if (scale >= 9500 && scale <= 950000) { + scale = Math.round(scale / 1000) + "K"; + } else if (scale >= 950000) { + scale = Math.round(scale / 1000000) + "M"; + } else { + scale = Math.round(scale / 100) * 100; + } this.element.innerHTML = "Scale = 1 : " + scale; },