@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\GeoJSON; |
| 14 | 14 | |
| 15 | -abstract class GeoJSONAbstract{ |
|
| 15 | +abstract class GeoJSONAbstract { |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @var array |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | */ |
| 28 | 28 | public function setBbox(array $bbox):GeoJSONAbstract{ |
| 29 | 29 | |
| 30 | - if(!in_array(count($bbox), [4, 6], true)){ |
|
| 30 | + if (!in_array(count($bbox), [4, 6], true)) { |
|
| 31 | 31 | throw new GeoJSONException('invalid bounding box array'); |
| 32 | 32 | } |
| 33 | 33 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | namespace chillerlan\GeoJSON; |
| 16 | 16 | |
| 17 | -class FeatureCollection extends GeoJSONAbstract{ |
|
| 17 | +class FeatureCollection extends GeoJSONAbstract { |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * @var array |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | * |
| 27 | 27 | * @param \chillerlan\GeoJSON\Feature[]|null $features |
| 28 | 28 | */ |
| 29 | - public function __construct(iterable $features = null){ |
|
| 29 | + public function __construct(iterable $features = null) { |
|
| 30 | 30 | |
| 31 | - if(!empty($features)){ |
|
| 31 | + if (!empty($features)) { |
|
| 32 | 32 | $this->addFeatures($features); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -52,8 +52,8 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function addFeatures(iterable $features):FeatureCollection{ |
| 54 | 54 | |
| 55 | - foreach($features as $feature){ |
|
| 56 | - if($feature instanceof Feature){ |
|
| 55 | + foreach ($features as $feature) { |
|
| 56 | + if ($feature instanceof Feature) { |
|
| 57 | 57 | $this->addFeature($feature); |
| 58 | 58 | } |
| 59 | 59 | } |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | public function toArray():array{ |
| 77 | 77 | $arr = ['type' => 'FeatureCollection']; |
| 78 | 78 | |
| 79 | - if(!empty($this->bbox)){ |
|
| 79 | + if (!empty($this->bbox)) { |
|
| 80 | 80 | $arr['bbox'] = $this->bbox; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $arr['features'] = array_map(function(Feature $feature){ |
|
| 83 | + $arr['features'] = array_map(function(Feature $feature) { |
|
| 84 | 84 | return $feature->toArray(); |
| 85 | 85 | }, $this->features); |
| 86 | 86 | |
@@ -12,4 +12,4 @@ |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\GeoJSON; |
| 14 | 14 | |
| 15 | -class GeoJSONException extends \Exception{} |
|
| 15 | +class GeoJSONException extends \Exception {} |
|
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | namespace chillerlan\GeoJSON; |
| 14 | 14 | |
| 15 | -class ContinentRect{ |
|
| 15 | +class ContinentRect { |
|
| 16 | 16 | |
| 17 | 17 | /** |
| 18 | 18 | * @var array |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param array $continent_rect (NW/SE corners [[nw_x, nw_y],[se_x, se_y]]) |
| 26 | 26 | */ |
| 27 | - public function __construct(array $continent_rect){ |
|
| 27 | + public function __construct(array $continent_rect) { |
|
| 28 | 28 | $this->rect = $continent_rect; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | |
| 15 | 15 | namespace chillerlan\GeoJSON; |
| 16 | 16 | |
| 17 | -class Feature extends GeoJSONAbstract{ |
|
| 17 | +class Feature extends GeoJSONAbstract { |
|
| 18 | 18 | |
| 19 | 19 | public const types = [ |
| 20 | 20 | 'Point', |
@@ -55,18 +55,18 @@ discard block |
||
| 55 | 55 | * |
| 56 | 56 | * @throws \chillerlan\GeoJSON\GeoJSONException |
| 57 | 57 | */ |
| 58 | - public function __construct(array $coords = null, string $type = null, $id = null){ |
|
| 58 | + public function __construct(array $coords = null, string $type = null, $id = null) { |
|
| 59 | 59 | |
| 60 | - if($coords !== null){ |
|
| 60 | + if ($coords !== null) { |
|
| 61 | 61 | |
| 62 | - if($type === null){ |
|
| 62 | + if ($type === null) { |
|
| 63 | 63 | throw new GeoJSONException('got coords but no feature type'); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $this->setGeometry($coords, $type); |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if($id !== null){ |
|
| 69 | + if ($id !== null) { |
|
| 70 | 70 | $this->setID($id); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | */ |
| 82 | 82 | public function setGeometry(array $coords, string $type):Feature{ |
| 83 | 83 | |
| 84 | - if(empty($coords)){ |
|
| 84 | + if (empty($coords)) { |
|
| 85 | 85 | throw new GeoJSONException('invalid coords array'); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if(!in_array($type, $this::types, true)){ |
|
| 88 | + if (!in_array($type, $this::types, true)) { |
|
| 89 | 89 | throw new GeoJSONException('invalid geometry type'); |
| 90 | 90 | } |
| 91 | 91 | |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | public function setID($id):Feature{ |
| 116 | 116 | |
| 117 | - if(empty($id) || (!is_string($id) && !is_numeric($id))){ |
|
| 117 | + if (empty($id) || (!is_string($id) && !is_numeric($id))) { |
|
| 118 | 118 | throw new GeoJSONException('invalid id'); |
| 119 | 119 | } |
| 120 | 120 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | public function toArray():array{ |
| 131 | 131 | $arr = ['type' => 'Feature']; |
| 132 | 132 | |
| 133 | - if(empty($this->coords) || empty($this->type)){ |
|
| 133 | + if (empty($this->coords) || empty($this->type)) { |
|
| 134 | 134 | throw new GeoJSONException('invalid feature'); |
| 135 | 135 | } |
| 136 | 136 | |
@@ -139,15 +139,15 @@ discard block |
||
| 139 | 139 | 'coordinates' => $this->coords, |
| 140 | 140 | ]; |
| 141 | 141 | |
| 142 | - if(!empty($this->bbox)){ |
|
| 142 | + if (!empty($this->bbox)) { |
|
| 143 | 143 | $arr['bbox'] = $this->bbox; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if(!empty($this->properties)){ |
|
| 146 | + if (!empty($this->properties)) { |
|
| 147 | 147 | $arr['properties'] = $this->properties; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - if(!empty($this->id)){ |
|
| 150 | + if (!empty($this->id)) { |
|
| 151 | 151 | $arr['properties']['id'] = $this->id; // leaflet |
| 152 | 152 | # $arr['id'] = $this->id; // GMaps |
| 153 | 153 | } |