source:
trunk/workshop-routing-foss4g/web/OpenLayers/lib/OpenLayers/Control/Scale.js
@
76
Revision 76, 2.7 KB checked in by djay, 12 years ago (diff) | |
---|---|
|
Rev | Line | |
---|---|---|
[76] | 1 | /* Copyright (c) 2006-2010 by OpenLayers Contributors (see authors.txt for |
2 | * full list of contributors). Published under the Clear BSD license. | |
3 | * See http://svn.openlayers.org/trunk/openlayers/license.txt for the | |
4 | * full text of the license. */ | |
5 | ||
6 | ||
7 | /** | |
8 | * @requires OpenLayers/Control.js | |
9 | */ | |
10 | ||
11 | /** | |
12 | * Class: OpenLayers.Control.Scale | |
13 | * The Scale control displays the current map scale as a ratio (e.g. Scale = | |
14 | * 1:1M). By default it is displayed in the lower right corner of the map. | |
15 | * | |
16 | * Inherits from: | |
17 | * - <OpenLayers.Control> | |
18 | */ | |
19 | OpenLayers.Control.Scale = OpenLayers.Class(OpenLayers.Control, { | |
20 | ||
21 | /** | |
22 | * Parameter: element | |
23 | * {DOMElement} | |
24 | */ | |
25 | element: null, | |
26 | ||
27 | /** | |
28 | * APIProperty: geodesic | |
29 | * {Boolean} Use geodesic measurement. Default is false. The recommended | |
30 | * setting for maps in EPSG:4326 is false, and true EPSG:900913. If set to | |
31 | * true, the scale will be calculated based on the horizontal size of the | |
32 | * pixel in the center of the map viewport. | |
33 | */ | |
34 | geodesic: false, | |
35 | ||
36 | /** | |
37 | * Constructor: OpenLayers.Control.Scale | |
38 | * | |
39 | * Parameters: | |
40 | * element - {DOMElement} | |
41 | * options - {Object} | |
42 | */ | |
43 | initialize: function(element, options) { | |
44 | OpenLayers.Control.prototype.initialize.apply(this, [options]); | |
45 | this.element = OpenLayers.Util.getElement(element); | |
46 | }, | |
47 | ||
48 | /** | |
49 | * Method: draw | |
50 | * | |
51 | * Returns: | |
52 | * {DOMElement} | |
53 | */ | |
54 | draw: function() { | |
55 | OpenLayers.Control.prototype.draw.apply(this, arguments); | |
56 | if (!this.element) { | |
57 | this.element = document.createElement("div"); | |
58 | this.div.appendChild(this.element); | |
59 | } | |
60 | this.map.events.register( 'moveend', this, this.updateScale); | |
61 | this.updateScale(); | |
62 | return this.div; | |
63 | }, | |
64 | ||
65 | /** | |
66 | * Method: updateScale | |
67 | */ | |
68 | updateScale: function() { | |
69 | var scale; | |
70 | if(this.geodesic === true) { | |
71 | var units = this.map.getUnits(); | |
72 | if(!units) { | |
73 | return; | |
74 | } | |
75 | var inches = OpenLayers.INCHES_PER_UNIT; | |
76 | scale = (this.map.getGeodesicPixelSize().w || 0.000001) * | |
77 | inches["km"] * OpenLayers.DOTS_PER_INCH; | |
78 | } else { | |
79 | scale = this.map.getScale(); | |
80 | } | |
81 | ||
82 | if (!scale) { | |
83 | return; | |
84 | } | |
85 | ||
86 | if (scale >= 9500 && scale <= 950000) { | |
87 | scale = Math.round(scale / 1000) + "K"; | |
88 | } else if (scale >= 950000) { | |
89 | scale = Math.round(scale / 1000000) + "M"; | |
90 | } else { | |
91 | scale = Math.round(scale); | |
92 | } | |
93 | ||
94 | this.element.innerHTML = OpenLayers.i18n("scale", {'scaleDenom':scale}); | |
95 | }, | |
96 | ||
97 | CLASS_NAME: "OpenLayers.Control.Scale" | |
98 | }); | |
99 |
Note: See TracBrowser
for help on using the repository browser.