git-svn-id: http://svn.openlayers.org/tags/openlayers/release-2.3-rc1@2106 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
|
|
* See http://svn.openlayers.org/trunk/openlayers/release-license.txt
|
|
* for the full text of the license. */
|
|
|
|
|
|
/**
|
|
* @class
|
|
*
|
|
* @requires OpenLayers/Control.js
|
|
*/
|
|
OpenLayers.Control.Scale = OpenLayers.Class.create();
|
|
OpenLayers.Control.Scale.prototype =
|
|
OpenLayers.Class.inherit( OpenLayers.Control, {
|
|
/** @type DOMElement */
|
|
element: null,
|
|
|
|
/**
|
|
* @constructor
|
|
*
|
|
* @param {DOMElement} element
|
|
* @param {String} base
|
|
*/
|
|
initialize: function(element) {
|
|
OpenLayers.Control.prototype.initialize.apply(this, arguments);
|
|
this.element = element;
|
|
},
|
|
|
|
/**
|
|
* @type DOMElement
|
|
*/
|
|
draw: function() {
|
|
OpenLayers.Control.prototype.draw.apply(this, arguments);
|
|
if (!this.element) {
|
|
this.element = document.createElement("div");
|
|
this.div.className = "olControlScale";
|
|
this.element.style.fontSize="smaller";
|
|
this.div.appendChild(this.element);
|
|
}
|
|
this.map.events.register( 'moveend', this, this.updateScale);
|
|
this.updateScale();
|
|
return this.div;
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
updateScale: function() {
|
|
var scale = this.map.getScale();
|
|
if (!scale) return;
|
|
|
|
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;
|
|
},
|
|
|
|
/** @final @type String */
|
|
CLASS_NAME: "OpenLayers.Control.Scale"
|
|
});
|
|
|