PageSourceSearch

https://turistautak.hu/maps/mapnik/Scale.js

js turistautak.hu collected 2026-10-02 10:33:33 UTC 2,899 bytes, 106 lines download raw bytes

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 */
19OpenLayers.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/*
87        if (scale >= 9500 && scale <= 950000) {
88            scale = Math.round(scale / 1000) + "e";
89        } else if (scale >= 950000) {
90            scale = Math.round(scale / 1000000) + "m";
91        } else {
92            scale = Math.round(scale);
93        }
94*/
95
96		scale=Math.floor(scale);
97		scale=FormatNumberBy3(scale, ',', ' ');
98
99        this.element.innerHTML = '<span title="zoom: ' + this.map.getZoom() + '">M=1:'+scale+'</span>';
100		// OpenLayers.i18n("scale", {'scaleDenom':scale});
101
102    },
103
104    CLASS_NAME: "OpenLayers.Control.Scale"
105});
106

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.