# Code coverage report for src/layer/vector/Circle.js

## Statements: 54.84% (17 / 31) Branches: 70% (7 / 10) Functions: 58.33% (7 / 12) Lines: 54.84% (17 / 31)

All files » src/layer/vector/ » Circle.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
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99

    1

    6

    6
    6

    1

    1

    12

    12

    12
    12

    1

    1

    12

    12

    12

    1
    1

     /*
     * L.Circle is a circle overlay (with a certain radius in meters).
     */

    L.Circle = L.Path.extend({
    	initialize: function (latlng, radius, options) {
    		L.Path.prototype.initialize.call(this, options);

    		this._latlng = L.latLng(latlng);
    		this._mRadius = radius;
    	},

    	options: {
    		fill: true
    	},

    	setLatLng: function (latlng) {
    		this._latlng = L.latLng(latlng);
    		return this.redraw();
    	},

    	setRadius: function (radius) {
    		this._mRadius = radius;
    		return this.redraw();
    	},

    	projectLatlngs: function () {
    		var lngRadius = this._getLngRadius(),
    		    latlng2 = new L.LatLng(this._latlng.lat, this._latlng.lng - lngRadius),
    		    point2 = this._map.latLngToLayerPoint(latlng2);

    		this._point = this._map.latLngToLayerPoint(this._latlng);
    		this._radius = Math.max(Math.round(this._point.x - point2.x), 1);
    	},

    	getBounds: function () {
    		var lngRadius = this._getLngRadius(),
    		    latRadius = (this._mRadius / 40075017) * 360,
    		    latlng = this._latlng,
    		    sw = new L.LatLng(latlng.lat - latRadius, latlng.lng - lngRadius),
    		    ne = new L.LatLng(latlng.lat + latRadius, latlng.lng + lngRadius);

    		return new L.LatLngBounds(sw, ne);
    	},

    	getLatLng: function () {
    		return this._latlng;
    	},

    	getPathString: function () {
    		var p = this._point,
    		    r = this._radius;

    		Iif (this._checkIfEmpty()) {
    			return '';
    		}

    		Eif (L.Browser.svg) {
    			return "M" + p.x + "," + (p.y - r) +
    			       "A" + r + "," + r + ",0,1,1," +
    			       (p.x - 0.1) + "," + (p.y - r) + " z";
    		} else {
    			p._round();
    			r = Math.round(r);
    			return "AL " + p.x + "," + p.y + " " + r + "," + r + " 0," + (65535 * 360);
    		}
    	},

    	getRadius: function () {
    		return this._mRadius;
    	},

    	// TODO Earth hardcoded, move into projection code!

    	_getLatRadius: function () {
    		return (this._mRadius / 40075017) * 360;
    	},

    	_getLngRadius: function () {
    		return this._getLatRadius() / Math.cos(L.LatLng.DEG_TO_RAD * this._latlng.lat);
    	},

    	_checkIfEmpty: function () {
    		Iif (!this._map) {
    			return false;
    		}
    		var vp = this._map._pathViewport,
    		    r = this._radius,
    		    p = this._point;

    		return p.x - r > vp.max.x || p.y - r > vp.max.y ||
    		       p.x + r < vp.min.x || p.y + r < vp.min.y;
    	}
    });

    L.circle = function (latlng, radius, options) {
    	return new L.Circle(latlng, radius, options);
    };