/** * {@inheritdoc} */ public function jsonSerialize() { $props = array(); foreach ($this->getProperties() as $property) { $props[$property->getName()] = $property->getValue(); } return array_merge(parent::jsonSerialize(), array("id" => $this->getId(), "geometry" => $this->getGeometry() ? $this->getGeometry()->jsonSerialize() : null, "properties" => $props)); }
/** * {@inheritdoc} * @see http://php.net/manual/en/jsonserializable.jsonserialize.php */ public function jsonSerialize() { $coords = array(); switch ($this->getType()) { case 'Point': if (sizeof($this->getCoordinates())) { $coords = $this->getCoordinates()[0]->jsonSerialize(); } break; default: foreach ($this->getCoordinates() as $coordinate) { $coords[] = $coordinate->jsonSerialize(); } break; } return array_merge(parent::jsonSerialize(), array("coordinates" => $coords)); }