1 /* Copyright (c) 2006-2008 MetaCarta, Inc., published under the Clear BSD
2 * license. See http://svn.openlayers.org/trunk/openlayers/license.txt for the
3 * full text of the license. */
7 * @requires OpenLayers/Control.js
11 * Class: OpenLayers.Control.Scale
12 * The Scale control displays the current map scale as a ratio (e.g. Scale =
13 * 1:1M). By default it is displayed in the lower right corner of the map.
16 * - <OpenLayers.Control>
18 OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, {
27 * Constructor: OpenLayers.Control.Scale
30 * element - {DOMElement}
33 initialize: function(element, options) {
34 OpenLayers.Control.prototype.initialize.apply(this, [options]);
35 this.element = OpenLayers.Util.getElement(element);
45 OpenLayers.Control.prototype.draw.apply(this, arguments);
47 this.element = document.createElement("div");
48 this.div.appendChild(this.element);
50 this.map.events.register( 'moveend', this, this.updateScale);
58 updateScale: function() {
59 var scale = this.map.getScale();
64 if (scale >= 9500 && scale <= 950000) {
65 scale = Math.round(scale / 1000) + "K";
66 } else if (scale >= 950000) {
67 scale = Math.round(scale / 1000000) + "M";
69 scale = Math.round(scale);
72 this.element.innerHTML = OpenLayers.i18n("scale", {'scaleDenom':scale});
75 CLASS_NAME: "OpenLayers.Control.Scale"