Example #1
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     $array = [];
     if ($this->id !== null) {
         $array['id'] = $this->id;
     }
     $array['type'] = 'Feature';
     if ($this->bbox) {
         $array['bbox'] = Location::getBBoxArray($this->geometry);
     }
     if ($this->geometry instanceof GeometryInterface) {
         $array['geometry'] = $this->geometry->jsonSerialize();
     } else {
         $array['geometry'] = null;
     }
     $array['properties'] = $this->properties;
     return $array;
 }
Example #2
0
 /**
  * (PHP 5 &gt;= 5.4.0)<br/>
  * Specify data which should be serialized to JSON
  * @link http://php.net/manual/en/jsonserializable.jsonserialize.php
  * @return mixed data which can be serialized by <b>json_encode</b>,
  * which is a value of any type other than a resource.
  */
 function jsonSerialize()
 {
     $features = [];
     $points = [];
     foreach ($this->features as $feature) {
         $features[] = $feature->jsonSerialize();
         if ($this->bbox) {
             $points += $feature->getGeometry()->getPoints();
         }
     }
     $return = [];
     $return['type'] = 'FeatureCollection';
     if ($this->bbox) {
         $return['bbox'] = Location::getBBoxArray($points);
     }
     $return['features'] = $features;
     return $return;
 }