@@ -12,4 +12,4 @@ |
||
12 | 12 | |
13 | 13 | namespace chillerlan\GeoJSON; |
14 | 14 | |
15 | -class GeoJSONException extends \Exception{} |
|
15 | +class GeoJSONException extends \Exception {} |
@@ -155,8 +155,7 @@ |
||
155 | 155 | $x = $p2[0]; |
156 | 156 | $y = $p2[1]; |
157 | 157 | |
158 | - } |
|
159 | - elseif($t > 0){ |
|
158 | + } elseif($t > 0){ |
|
160 | 159 | $x += $dx * $t; |
161 | 160 | $y += $dy * $t; |
162 | 161 | } |
@@ -14,14 +14,14 @@ discard block |
||
14 | 14 | |
15 | 15 | use function array_fill, array_keys, array_pop, array_push, array_values, count, is_array; |
16 | 16 | |
17 | -class PolylineSimplifyer{ |
|
17 | +class PolylineSimplifyer { |
|
18 | 18 | |
19 | 19 | protected array $coords; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * PolylineSimplifyer constructor. |
23 | 23 | */ |
24 | - public function __construct(array $polylineCoords){ |
|
24 | + public function __construct(array $polylineCoords) { |
|
25 | 25 | $this->coords = $polylineCoords; |
26 | 26 | } |
27 | 27 | |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | public function simplify(float $tolerance = 1, bool $highestQuality = false):array{ |
32 | 32 | $coords = array_values($this->coords ?? []); |
33 | 33 | |
34 | - if(count($coords) < 2){ |
|
34 | + if (count($coords) < 2) { |
|
35 | 35 | throw new GeoJSONException('not enough points'); |
36 | 36 | } |
37 | 37 | |
38 | - foreach($this->coords as $coord){ |
|
39 | - if(!is_array($coord) || count($coord) < 2){ |
|
38 | + foreach ($this->coords as $coord) { |
|
39 | + if (!is_array($coord) || count($coord) < 2) { |
|
40 | 40 | throw new GeoJSONException('invalid coords found'); |
41 | 41 | } |
42 | 42 | } |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | $point = null; |
57 | 57 | $len = count($points); |
58 | 58 | |
59 | - for($i = 1; $i < $len; $i++){ |
|
59 | + for ($i = 1; $i < $len; $i++) { |
|
60 | 60 | $point = $points[$i]; |
61 | 61 | |
62 | - if($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance){ |
|
62 | + if ($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance) { |
|
63 | 63 | $newPoints[] = $point; |
64 | 64 | $prevPoint = $point; |
65 | 65 | } |
66 | 66 | } |
67 | 67 | |
68 | - if($prevPoint !== $point){ |
|
68 | + if ($prevPoint !== $point) { |
|
69 | 69 | $newPoints[] = $point; |
70 | 70 | } |
71 | 71 | |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | |
97 | 97 | $markers[$first] = $markers[$last] = 1; |
98 | 98 | |
99 | - while($last){ |
|
99 | + while ($last) { |
|
100 | 100 | |
101 | 101 | $maxSqDist = 0; |
102 | 102 | |
103 | - for($i = $first + 1; $i < $last; $i++){ |
|
103 | + for ($i = $first + 1; $i < $last; $i++) { |
|
104 | 104 | $sqDist = $this->getSqSegDist( |
105 | 105 | array_values($points[$i]), |
106 | 106 | array_values($points[$first]), |
107 | 107 | array_values($points[$last]) |
108 | 108 | ); |
109 | 109 | |
110 | - if($sqDist > $maxSqDist){ |
|
110 | + if ($sqDist > $maxSqDist) { |
|
111 | 111 | $index = $i; |
112 | 112 | $maxSqDist = $sqDist; |
113 | 113 | } |
114 | 114 | } |
115 | 115 | |
116 | - if($maxSqDist > $sqTolerance){ |
|
116 | + if ($maxSqDist > $sqTolerance) { |
|
117 | 117 | $markers[$index] = 1; |
118 | 118 | array_push($stack, $first, $index, $index, $last); |
119 | 119 | } |
@@ -122,8 +122,8 @@ discard block |
||
122 | 122 | $first = array_pop($stack); |
123 | 123 | } |
124 | 124 | |
125 | - foreach($points as $i => $point){ |
|
126 | - if($markers[$i]){ |
|
125 | + foreach ($points as $i => $point) { |
|
126 | + if ($markers[$i]) { |
|
127 | 127 | $newPoints[] = $point; |
128 | 128 | } |
129 | 129 | } |
@@ -140,16 +140,16 @@ discard block |
||
140 | 140 | $dx = $p2[0] - $x; |
141 | 141 | $dy = $p2[1] - $y; |
142 | 142 | |
143 | - if((int)$dx !== 0 || (int)$dy !== 0){ |
|
143 | + if ((int) $dx !== 0 || (int) $dy !== 0) { |
|
144 | 144 | |
145 | 145 | $t = (($p[0] - $x) * $dx + ($p[1] - $y) * $dy) / ($dx * $dx + $dy * $dy); |
146 | 146 | |
147 | - if($t > 1){ |
|
147 | + if ($t > 1) { |
|
148 | 148 | $x = $p2[0]; |
149 | 149 | $y = $p2[1]; |
150 | 150 | |
151 | 151 | } |
152 | - elseif($t > 0){ |
|
152 | + elseif ($t > 0) { |
|
153 | 153 | $x += $dx * $t; |
154 | 154 | $y += $dy * $t; |
155 | 155 | } |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | namespace chillerlan\GeoJSON; |
12 | 12 | |
13 | -class ContinentRect{ |
|
13 | +class ContinentRect { |
|
14 | 14 | |
15 | 15 | protected array $rect; |
16 | 16 | |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @param array $continent_rect (NW/SE corners [[nw_x, nw_y],[se_x, se_y]]) |
21 | 21 | */ |
22 | - public function __construct(array $continent_rect){ |
|
22 | + public function __construct(array $continent_rect) { |
|
23 | 23 | $this->rect = $continent_rect; |
24 | 24 | } |
25 | 25 |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | use function array_map; |
16 | 16 | |
17 | -class FeatureCollection extends GeoJSONAbstract{ |
|
17 | +class FeatureCollection extends GeoJSONAbstract { |
|
18 | 18 | |
19 | 19 | protected array $features = []; |
20 | 20 | |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param \chillerlan\GeoJSON\Feature[]|null $features |
25 | 25 | */ |
26 | - public function __construct(iterable $features = null){ |
|
26 | + public function __construct(iterable $features = null) { |
|
27 | 27 | |
28 | - if(!empty($features)){ |
|
28 | + if (!empty($features)) { |
|
29 | 29 | $this->addFeatures($features); |
30 | 30 | } |
31 | 31 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function addFeatures(iterable $features):FeatureCollection{ |
51 | 51 | |
52 | - foreach($features as $feature){ |
|
53 | - if($feature instanceof Feature){ |
|
52 | + foreach ($features as $feature) { |
|
53 | + if ($feature instanceof Feature) { |
|
54 | 54 | $this->addFeature($feature); |
55 | 55 | } |
56 | 56 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | public function toArray():array{ |
74 | 74 | $arr = ['type' => 'FeatureCollection']; |
75 | 75 | |
76 | - if(!empty($this->bbox)){ |
|
76 | + if (!empty($this->bbox)) { |
|
77 | 77 | $arr['bbox'] = $this->bbox; |
78 | 78 | } |
79 | 79 |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | use function is_int; |
17 | 17 | use function is_string; |
18 | 18 | |
19 | -class Feature extends GeoJSONAbstract{ |
|
19 | +class Feature extends GeoJSONAbstract { |
|
20 | 20 | |
21 | 21 | public const types = [ |
22 | 22 | 'Point', |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @throws \chillerlan\GeoJSON\GeoJSONException |
45 | 45 | */ |
46 | - public function __construct(array $coords = null, string $type = null, $id = null){ |
|
46 | + public function __construct(array $coords = null, string $type = null, $id = null) { |
|
47 | 47 | |
48 | - if($coords !== null){ |
|
48 | + if ($coords !== null) { |
|
49 | 49 | |
50 | - if($type === null){ |
|
50 | + if ($type === null) { |
|
51 | 51 | throw new GeoJSONException('got coords but no feature type'); |
52 | 52 | } |
53 | 53 | |
54 | 54 | $this->setGeometry($coords, $type); |
55 | 55 | } |
56 | 56 | |
57 | - if($id !== null){ |
|
57 | + if ($id !== null) { |
|
58 | 58 | $this->setID($id); |
59 | 59 | } |
60 | 60 | |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function setGeometry(array $coords, string $type):Feature{ |
67 | 67 | |
68 | - if(empty($coords)){ |
|
68 | + if (empty($coords)) { |
|
69 | 69 | throw new GeoJSONException('invalid coords array'); |
70 | 70 | } |
71 | 71 | |
72 | - if(!in_array($type, $this::types, true)){ |
|
72 | + if (!in_array($type, $this::types, true)) { |
|
73 | 73 | throw new GeoJSONException('invalid geometry type'); |
74 | 74 | } |
75 | 75 | |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | */ |
96 | 96 | public function setID($id):Feature{ |
97 | 97 | |
98 | - if(!is_string($id) && !is_int($id)){ |
|
98 | + if (!is_string($id) && !is_int($id)) { |
|
99 | 99 | throw new GeoJSONException('invalid id'); |
100 | 100 | } |
101 | 101 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | public function toArray():array{ |
111 | 111 | $arr = ['type' => 'Feature']; |
112 | 112 | |
113 | - if(empty($this->coords) || empty($this->type)){ |
|
113 | + if (empty($this->coords) || empty($this->type)) { |
|
114 | 114 | throw new GeoJSONException('invalid feature'); |
115 | 115 | } |
116 | 116 | |
@@ -119,15 +119,15 @@ discard block |
||
119 | 119 | 'coordinates' => $this->coords, |
120 | 120 | ]; |
121 | 121 | |
122 | - if(!empty($this->bbox)){ |
|
122 | + if (!empty($this->bbox)) { |
|
123 | 123 | $arr['bbox'] = $this->bbox; |
124 | 124 | } |
125 | 125 | |
126 | - if(!empty($this->properties)){ |
|
126 | + if (!empty($this->properties)) { |
|
127 | 127 | $arr['properties'] = $this->properties; |
128 | 128 | } |
129 | 129 | |
130 | - if(!empty($this->id)){ |
|
130 | + if (!empty($this->id)) { |
|
131 | 131 | $arr['properties']['id'] = $this->id; // leaflet |
132 | 132 | # $arr['id'] = $this->id; // GMaps |
133 | 133 | } |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | use function in_array; |
16 | 16 | use function json_encode; |
17 | 17 | |
18 | -abstract class GeoJSONAbstract implements JsonSerializable{ |
|
18 | +abstract class GeoJSONAbstract implements JsonSerializable { |
|
19 | 19 | |
20 | 20 | protected array $bbox; |
21 | 21 | |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | public function setBbox(array $bbox):GeoJSONAbstract{ |
26 | 26 | |
27 | - if(!in_array(count($bbox), [4, 6], true)){ |
|
27 | + if (!in_array(count($bbox), [4, 6], true)) { |
|
28 | 28 | throw new GeoJSONException('invalid bounding box array'); |
29 | 29 | } |
30 | 30 |