11<?php
2- /**
3- * Created 16/02/2017 22:03
4- * @author Jakub Dubec <jakub.dubec@gmail.com>
5- */
62
73namespace phpGPX \Models ;
84
5+ /**
6+ * Two lat/lon pairs defining the extent of an element.
7+ */
98class Bounds implements \JsonSerializable
109{
11- public const TAG_NAME = 'bounds ' ;
12-
13- /**
14- * Minimal latitude in file.
15- * @var float|null
16- */
17- public ?float $ minLatitude ;
18-
19- /**
20- * Minimal longitude in file.
21- * @var float|null
22- */
23- public ?float $ minLongitude ;
10+ public const TAG_NAME = 'bounds ' ;
2411
25- /**
26- * Maximal latitude in file.
27- * @var float|null
28- */
29- public ?float $ maxLatitude ;
12+ public function __construct (
13+ public ?float $ minLatitude = null ,
14+ public ?float $ minLongitude = null ,
15+ public ?float $ maxLatitude = null ,
16+ public ?float $ maxLongitude = null ,
17+ ) {}
3018
3119 /**
32- * Maximal longitude in file.
33- * @var float|null
20+ * GeoJSON bbox: [minLon, minLat, maxLon, maxLat]
3421 */
35- public ?float $ maxLongitude ;
36-
37- /**
38- * @param float|null $minLatitude
39- * @param float|null $minLongitude
40- * @param float|null $maxLatitude
41- * @param float|null $maxLongitude
42- */
43- public function __construct (?float $ minLatitude , ?float $ minLongitude , ?float $ maxLatitude , ?float $ maxLongitude )
44- {
45- $ this ->minLatitude = $ minLatitude ;
46- $ this ->minLongitude = $ minLongitude ;
47- $ this ->maxLatitude = $ maxLatitude ;
48- $ this ->maxLongitude = $ maxLongitude ;
49- }
50-
51- /**
52- * GeoJSON serializer
53- * @return array
54- */
55- public function jsonSerialize (): array
56- {
57- return [$ this ->minLongitude , $ this ->minLatitude , $ this ->maxLongitude , $ this ->maxLatitude ];
58- }
59-
60- public static function parse (\SimpleXMLElement $ node ): ?Bounds
61- {
62- if ($ node ->getName () != self ::TAG_NAME ) {
63- return null ;
64- }
65-
66- return new Bounds (
67- (float ) $ node ['minlat ' ],
68- (float ) $ node ['minlon ' ],
69- (float ) $ node ['maxlat ' ],
70- (float ) $ node ['maxlon ' ]
71- );
72- }
73- }
22+ public function jsonSerialize (): array
23+ {
24+ return [$ this ->minLongitude , $ this ->minLatitude , $ this ->maxLongitude , $ this ->maxLatitude ];
25+ }
26+
27+ public static function parse (\SimpleXMLElement $ node ): ?Bounds
28+ {
29+ if ($ node ->getName () != self ::TAG_NAME ) {
30+ return null ;
31+ }
32+
33+ return new Bounds (
34+ (float ) $ node ['minlat ' ],
35+ (float ) $ node ['minlon ' ],
36+ (float ) $ node ['maxlat ' ],
37+ (float ) $ node ['maxlon ' ]
38+ );
39+ }
40+ }
0 commit comments