Circle::encode()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 6
nop 0
crap 4
1
<?php
2
/**
3
 * /**
4
 * @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC
5
 * @link http://2amigos.us
6
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
7
 */
8
9
namespace dosamigos\leaflet\layers;
10
11
12
use yii\web\JsExpression;
13
14
/**
15
 * Circle a class for drawing circle overlays on a map.
16
 *
17
 * @see http://leafletjs.com/reference.html#circle
18
 * @author Antonio Ramirez <[email protected]>
19
 * @link http://www.ramirezcobos.com/
20
 * @link http://www.2amigos.us/
21
 * @package dosamigos\leaflet\layers
22
 */
23
/**
24
 * @property string $name
25
 */
26
class Circle extends Layer
27
{
28
    use LatLngTrait;
29
    use PopupTrait;
30
31
    /**
32
     * @var float Sets the radius of a circle. Units are in meters.
33
     */
34
    public $radius;
35
36
    /**
37
     * Returns the javascript ready code for the object to render
38
     * @return JsExpression
39
     */
40 9
    public function encode()
41
    {
42 9
        $bounds = $this->getLatLng()->toArray(true);
43 9
        $radius = $this->radius;
44 9
        $options = $this->getOptions();
45 9
        $name = $this->name;
46 9
        $map = $this->map;
47 9
        $js = $this->bindPopupContent("L.circle($bounds, $radius, $options)") . ($map !== null ? ".addTo($map);" : "");
48 9
        if (!empty($name)) {
49 3
            $js = "var $name = $js" . ($map !== null ? "" : ";");
50 3
        }
51 9
        return new JsExpression($js);
52
    }
53
54
}
55