# Code coverage report for src/control/Control.js

## Statements: 46.15% (12 / 26) Branches: 25% (2 / 8) Functions: 57.14% (4 / 7) Lines: 46.15% (12 / 26)

All files » src/control/ » Control.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75

    1

    51

    113

    8

    113

    113

    113

    113
    59

    54

    113

    1

     /*
     * L.Control is a base class for implementing map controls. Handles positioning.
     * All other controls extend from this class.
     */

    L.Control = L.Class.extend({
    	options: {
    		position: 'topright'
    	},

    	initialize: function (options) {
    		L.setOptions(this, options);
    	},

    	getPosition: function () {
    		return this.options.position;
    	},

    	setPosition: function (position) {
    		var map = this._map;

    		if (map) {
    			map.removeControl(this);
    		}

    		this.options.position = position;

    		if (map) {
    			map.addControl(this);
    		}

    		return this;
    	},

    	getContainer: function () {
    		return this._container;
    	},

    	addTo: function (map) {
    		this._map = map;

    		var container = this._container = this.onAdd(map),
    		    pos = this.getPosition(),
    		    corner = map._controlCorners[pos];

    		L.DomUtil.addClass(container, 'leaflet-control');

    		if (pos.indexOf('bottom') !== -1) {
    			corner.insertBefore(container, corner.firstChild);
    		} else {
    			corner.appendChild(container);
    		}

    		return this;
    	},

    	removeFrom: function (map) {
    		var pos = this.getPosition(),
    		    corner = map._controlCorners[pos];

    		corner.removeChild(this._container);
    		this._map = null;

    		if (this.onRemove) {
    			this.onRemove(map);
    		}

    		return this;
    	}
    });

    L.control = function (options) {
    	return new L.Control(options);
    };