1
|
|
|
<?php namespace Cornford\Googlmapper\Models; |
2
|
|
|
|
3
|
|
|
use Cornford\Googlmapper\Contracts\ModelingInterface; |
4
|
|
|
use Illuminate\View\Factory as View; |
5
|
|
|
|
6
|
|
|
class Map implements ModelingInterface { |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Options. |
10
|
|
|
* |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
protected $options = []; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Markers. |
17
|
|
|
* |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
protected $markers = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Shapes. |
24
|
|
|
* |
25
|
|
|
* @var array |
26
|
|
|
*/ |
27
|
|
|
protected $shapes = []; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Public constructor. |
31
|
|
|
* |
32
|
|
|
* @param array $parameters |
33
|
|
|
*/ |
34
|
|
|
public function __construct(array $parameters = []) |
35
|
|
|
{ |
36
|
|
|
$this->options = $parameters; |
37
|
|
|
|
38
|
|
|
if (isset($this->options['marker']) && $this->options['marker']) { |
39
|
|
|
$this->marker($this->options['latitude'], $this->options['longitude'], $this->options); |
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Add a map marker to the markers bag. |
45
|
|
|
* |
46
|
|
|
* @param float $latitude |
47
|
|
|
* @param float $longitude |
48
|
|
|
* @param array $options |
49
|
|
|
* |
50
|
|
|
* @return void |
51
|
|
|
*/ |
52
|
|
|
public function marker($latitude, $longitude, array $options = []) |
53
|
|
|
{ |
54
|
|
|
$parameters = [ |
55
|
|
|
'latitude' => $latitude, |
56
|
|
|
'longitude' => $longitude, |
57
|
|
|
]; |
58
|
|
|
|
59
|
|
|
$parameters = array_replace_recursive( |
60
|
|
|
$this->options, |
61
|
|
|
$parameters, |
62
|
|
|
$options |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
$this->markers[] = new Marker($parameters); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Add a map shape to the shapes bag. |
70
|
|
|
* |
71
|
|
|
* @param string $type |
72
|
|
|
* @param array $coordinates |
73
|
|
|
* @param array $options |
74
|
|
|
* |
75
|
|
|
* @return void |
76
|
|
|
*/ |
77
|
|
|
public function shape($type, $coordinates, array $options = []) |
78
|
|
|
{ |
79
|
|
|
$parameters = [ |
80
|
|
|
'coordinates' => $coordinates |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
$parameters = array_replace_recursive( |
84
|
|
|
$this->options, |
85
|
|
|
$parameters, |
86
|
|
|
$options |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
switch ($type) { |
90
|
|
|
case 'polyline': |
91
|
|
|
$this->shapes[] = new Polyline($parameters); |
92
|
|
|
break; |
93
|
|
|
case 'polygon': |
94
|
|
|
$this->shapes[] = new Polygon($parameters); |
95
|
|
|
break; |
96
|
|
|
case 'rectangle': |
97
|
|
|
$this->shapes[] = new Rectangle($parameters); |
98
|
|
|
break; |
99
|
|
|
case 'circle': |
100
|
|
|
$this->shapes[] = new Circle($parameters); |
101
|
|
|
break; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Render the model item. |
108
|
|
|
* |
109
|
|
|
* @param integer $identifier |
110
|
|
|
* @param View $view |
111
|
|
|
* |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
|
public function render($identifier, View $view) |
115
|
|
|
{ |
116
|
|
|
$options = $this->options; |
117
|
|
|
$options['markers'] = $this->getMarkers(); |
118
|
|
|
$options['shapes'] = $this->getShapes(); |
119
|
|
|
|
120
|
|
|
return $view->make('googlmapper::map') |
|
|
|
|
121
|
|
|
->withOptions($options) |
122
|
|
|
->withId($identifier) |
123
|
|
|
->withView($view) |
124
|
|
|
->render(); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Return marker items. |
129
|
|
|
* |
130
|
|
|
* @return array |
131
|
|
|
*/ |
132
|
|
|
public function getMarkers() |
133
|
|
|
{ |
134
|
|
|
return $this->markers; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Return shape items. |
139
|
|
|
* |
140
|
|
|
* @return array |
141
|
|
|
*/ |
142
|
|
|
public function getShapes() |
143
|
|
|
{ |
144
|
|
|
return $this->shapes; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Get the model options. |
149
|
|
|
* |
150
|
|
|
* @return array |
151
|
|
|
*/ |
152
|
|
|
public function getOptions() |
153
|
|
|
{ |
154
|
|
|
return $this->options; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.