1 | <?php |
||
2 | namespace Ballen\Cartographer; |
||
3 | |||
4 | use Ballen\Cartographer\Core\GeoJSONTypeInterface; |
||
5 | use Ballen\Cartographer\Core\Multipliable; |
||
6 | use Ballen\Cartographer\Core\GeoJSON; |
||
7 | use Ballen\Distical\Entities\LatLong; |
||
8 | |||
9 | /** |
||
10 | * Cartographer |
||
11 | * |
||
12 | * Cartographer is a PHP library providing the ability to programmatically |
||
13 | * generate GeoJSON objects. |
||
14 | * |
||
15 | * @author Bobby Allen <[email protected]> |
||
16 | * @license http://www.gnu.org/licenses/gpl-3.0.html |
||
17 | * @link https://github.com/allebb/cartographer |
||
18 | * @link http://bobbyallen.me |
||
19 | * |
||
20 | */ |
||
21 | class Point extends GeoJSON implements GeoJSONTypeInterface, Multipliable |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * The GeoJSON schema type |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $type = GeoJSON::TYPE_POINT; |
||
29 | |||
30 | /** |
||
31 | * The LatLong point for the map. |
||
32 | * @var LatLong |
||
33 | */ |
||
34 | private $coordinate; |
||
35 | |||
36 | /** |
||
37 | * Create a new instance of the Point GeoJSON schema |
||
38 | * @param LatLong $coordinate |
||
39 | */ |
||
40 | 12 | public function __construct(LatLong $coordinate) |
|
41 | { |
||
42 | 12 | $this->coordinate = $coordinate; |
|
43 | 12 | } |
|
44 | |||
45 | /** |
||
46 | * Exports the type specific schema element(s). |
||
47 | * @return array |
||
48 | */ |
||
49 | 8 | public function export() |
|
50 | { |
||
51 | return [ |
||
52 | 8 | 'coordinates' => $this->coordinate->lngLatArray() |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
53 | ]; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * Exports the type specific schema array (for use in MultiX types). |
||
58 | * @return array |
||
59 | */ |
||
60 | 2 | public function exportArray() |
|
61 | { |
||
62 | 2 | return $this->coordinate->lngLatArray(); |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Validate the type specific schema element(s). |
||
67 | * @return boolean |
||
68 | */ |
||
69 | 2 | public function validate() |
|
70 | { |
||
71 | // No need for additional validation as the class constructor will enforce a single LatLong object. |
||
72 | 2 | return true; |
|
73 | } |
||
74 | } |
||
75 |