GeoJson   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
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 13 3
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
11
use dosamigos\leaflet\LeafLet;
12
use yii\helpers\Json;
13
use yii\web\JsExpression;
14
15
/**
16
 * GeoJson allows you to parse GeoJSON data and display it on the map
17
 *
18
 * @see http://leafletjs.com/reference.html#geojson
19
 * @author Antonio Ramirez <[email protected]>
20
 * @link http://www.ramirezcobos.com/
21
 * @link http://www.2amigos.us/
22
 * @package dosamigos\leaflet\layers
23
 */
24
/**
25
 * @property string $name
26
 */
27
class GeoJson extends Layer
28
{
29
    /**
30
     * @var array geo spatial data interchange json object. For information related to GeoJSON format, please visit
31
     * [http://geojson.org/geojson-spec.html](http://geojson.org/geojson-spec.html). This component does not validate
32
     * this data, it just renders it. This array will be converted into a json object previous encoding.
33
     */
34
    public $data = [];
35
36
    /**
37
     * Returns the javascript ready code for the object to render
38
     * @return string|JsExpression
39
     */
40 6
    public function encode()
41
    {
42 6
        $data = Json::encode($this->data, LeafLet::JSON_OPTIONS);
43 6
        $options = $this->getOptions();
44 6
        $name = $this->name;
45 6
        $map = $this->map;
46 6
        $js = "L.geoJson($data, $options)" . ($map !== null ? ".addTo($map)" : "") . ";";
47 6
        if (!empty($name)) {
48 3
            $js = "var $name = $js";
49 3
        }
50
51 6
        return new JsExpression($js);
52
    }
53
54
}
55