@@ -14,7 +14,7 @@ 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 | protected array $coordKeys; |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * PolylineSimplifyer constructor. |
24 | 24 | */ |
25 | - public function __construct(array $polylineCoords){ |
|
25 | + public function __construct(array $polylineCoords) { |
|
26 | 26 | $this->coords = $polylineCoords; |
27 | 27 | } |
28 | 28 | |
@@ -32,18 +32,18 @@ discard block |
||
32 | 32 | public function simplify(float $tolerance = 1, bool $highestQuality = false):array{ |
33 | 33 | $coords = array_values($this->coords ?? []); |
34 | 34 | |
35 | - if(count($coords) < 2){ |
|
35 | + if (count($coords) < 2) { |
|
36 | 36 | throw new GeoJSONException('not enough points'); |
37 | 37 | } |
38 | 38 | |
39 | 39 | $this->coordKeys = array_keys($this->coords[0]); |
40 | 40 | |
41 | - if(count($this->coordKeys) < 2){ |
|
41 | + if (count($this->coordKeys) < 2) { |
|
42 | 42 | throw new GeoJSONException('invalid coordinate keys'); |
43 | 43 | } |
44 | 44 | |
45 | - foreach($this->coords as $coord){ |
|
46 | - if(!is_array($coord) || count($coord) < 2){ |
|
45 | + foreach ($this->coords as $coord) { |
|
46 | + if (!is_array($coord) || count($coord) < 2) { |
|
47 | 47 | throw new GeoJSONException('invalid coords found'); |
48 | 48 | } |
49 | 49 | } |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | $point = null; |
64 | 64 | $len = count($points); |
65 | 65 | |
66 | - for($i = 1; $i < $len; $i++){ |
|
66 | + for ($i = 1; $i < $len; $i++) { |
|
67 | 67 | $point = $points[$i]; |
68 | 68 | |
69 | - if($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance){ |
|
69 | + if ($this->getSqDist(array_values($point), array_values($prevPoint)) > $sqTolerance) { |
|
70 | 70 | $newPoints[] = $point; |
71 | 71 | $prevPoint = $point; |
72 | 72 | } |
73 | 73 | } |
74 | 74 | |
75 | - if($prevPoint !== $point){ |
|
75 | + if ($prevPoint !== $point) { |
|
76 | 76 | $newPoints[] = $point; |
77 | 77 | } |
78 | 78 | |
@@ -103,24 +103,24 @@ discard block |
||
103 | 103 | |
104 | 104 | $markers[$first] = $markers[$last] = 1; |
105 | 105 | |
106 | - while($last){ |
|
106 | + while ($last) { |
|
107 | 107 | |
108 | 108 | $maxSqDist = 0; |
109 | 109 | |
110 | - for($i = $first + 1; $i < $last; $i++){ |
|
110 | + for ($i = $first + 1; $i < $last; $i++) { |
|
111 | 111 | $sqDist = $this->getSqSegDist( |
112 | 112 | array_values($points[$i]), |
113 | 113 | array_values($points[$first]), |
114 | 114 | array_values($points[$last]) |
115 | 115 | ); |
116 | 116 | |
117 | - if($sqDist > $maxSqDist){ |
|
117 | + if ($sqDist > $maxSqDist) { |
|
118 | 118 | $index = $i; |
119 | 119 | $maxSqDist = $sqDist; |
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
123 | - if($maxSqDist > $sqTolerance){ |
|
123 | + if ($maxSqDist > $sqTolerance) { |
|
124 | 124 | $markers[$index] = 1; |
125 | 125 | array_push($stack, $first, $index, $index, $last); |
126 | 126 | } |
@@ -129,8 +129,8 @@ discard block |
||
129 | 129 | $first = array_pop($stack); |
130 | 130 | } |
131 | 131 | |
132 | - foreach($points as $i => $point){ |
|
133 | - if($markers[$i]){ |
|
132 | + foreach ($points as $i => $point) { |
|
133 | + if ($markers[$i]) { |
|
134 | 134 | $newPoints[] = $point; |
135 | 135 | } |
136 | 136 | } |
@@ -147,16 +147,16 @@ discard block |
||
147 | 147 | $dx = $p2[0] - $x; |
148 | 148 | $dy = $p2[1] - $y; |
149 | 149 | |
150 | - if((int)$dx !== 0 || (int)$dy !== 0){ |
|
150 | + if ((int) $dx !== 0 || (int) $dy !== 0) { |
|
151 | 151 | |
152 | 152 | $t = (($p[0] - $x) * $dx + ($p[1] - $y) * $dy) / ($dx * $dx + $dy * $dy); |
153 | 153 | |
154 | - if($t > 1){ |
|
154 | + if ($t > 1) { |
|
155 | 155 | $x = $p2[0]; |
156 | 156 | $y = $p2[1]; |
157 | 157 | |
158 | 158 | } |
159 | - elseif($t > 0){ |
|
159 | + elseif ($t > 0) { |
|
160 | 160 | $x += $dx * $t; |
161 | 161 | $y += $dy * $t; |
162 | 162 | } |
@@ -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 | } |
@@ -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 |