Polygon   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 28
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A encode() 0 12 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2013-2015 2amigOS! Consulting Group LLC
4
 * @link http://2amigos.us
5
 * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
6
 */
7
8
namespace dosamigos\leaflet\layers;
9
10
use dosamigos\leaflet\LeafLet;
11
use yii\helpers\Json;
12
use yii\web\JsExpression;
13
14
/**
15
 * Polygon is a class for drawing polygon overlays on a map
16
 *
17
 * @see http://leafletjs.com/reference.html#polygon
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 Polygon extends PolyLine
27
{
28
29
    /**
30
     * @var bool whether to insert the layer at the bottom most position (z-index) on the map in reference to other
31
     * ui layers.
32
     */
33
    public $insertAtTheBottom = false;
34
35
    /**
36
     * Returns the javascript ready code for the object to render on the map.
37
     * To add a Polygon to the map, you need to use the special method [[LetLeaf::addPolygon]].
38
     * @return string
39
     */
40 12
    public function encode()
41
    {
42 12
        $latLngs = Json::encode($this->getLatLngstoArray(), LeafLet::JSON_OPTIONS);
43 12
        $options = $this->getOptions();
44 12
        $name = $this->name;
45 12
        $map = $this->map;
46 12
        $js = $this->bindPopupContent("L.polygon($latLngs, $options)") . ($map !== null ? ".addTo($map);" : "");
47 12
        if (!empty($name)) {
48 3
            $js = "var $name = $js" . ($map !== null ? "" : ";");
49 3
        }
50 12
        return new JsExpression($js);
51
    }
52
53
}
54