Project

General

Profile

1
/* Copyright (c) 2006 MetaCarta, Inc., published under the BSD license.
2
 * See http://svn.openlayers.org/trunk/openlayers/license.txt for the full
3
 * text of the license. */
4

    
5
/**
6
* @class
7
*/
8
OpenLayers.Control = Class.create();
9
OpenLayers.Control.prototype = {
10

    
11
    /** this gets set in the addControl() function in OpenLayers.Map
12
    * @type OpenLayers.Map */
13
    map: null,
14

    
15
    /** @type DOMElement */
16
    div: null,
17

    
18
    /** @type OpenLayers.Pixel */
19
    position: null,
20

    
21
    /** @type OpenLayers.Pixel */
22
    mouseDragStart: null,
23

    
24
    /**
25
     * @constructor
26
     * 
27
     * @param {Object} options
28
     */
29
    initialize: function (options) {
30
        Object.extend(this, options);
31
    },
32

    
33
    /**
34
     * 
35
     */
36
    destroy: function () {
37
        // eliminate circular references
38
        this.map = null;
39
    },
40

    
41
    /** Set the map property for the control. This is done through an accessor
42
     *   so that subclasses can override this and take special action once 
43
     *   they have their map variable set. 
44
     * 
45
     * @param {OpenLayers.Map} map
46
     */
47
    setMap: function(map) {
48
        this.map = map;
49
    },
50
  
51
    /**
52
     * @param {OpenLayers.Pixel} px
53
     *
54
     * @returns A reference to the DIV DOMElement containing the control
55
     * @type DOMElement
56
     */
57
    draw: function (px) {
58
        if (this.div == null) {
59
            this.div = OpenLayers.Util.createDiv();
60
        }
61
        if (px != null) {
62
            this.position = px.clone();
63
        }
64
        this.moveTo(this.position);        
65
        return this.div;
66
    },
67

    
68
    /**
69
     * @param {OpenLayers.Pixel} px
70
     */
71
    moveTo: function (px) {
72
        if ((px != null) && (this.div != null)) {
73
            this.div.style.left = px.x + "px";
74
            this.div.style.top = px.x + "px";
75
        }
76
    },
77

    
78
    /** @final @type String */
79
    CLASS_NAME: "OpenLayers.Control"
80
};
(3-3/13)