outerBoundary = $aLinearRing; } else { $e = new mb_exception("class_kml_polygon.php: __construct: parameter not a linear ring, but a " . get_class($aLinearRing)); } } /** * @return string a string representation of the object, currently * {@link http://www.geojson.org GeoJSON} */ public function __toString() { return $this->toGeoJSON(); } /** * @return string the geoJSON representation of the object */ public function toGeoJSON () { if ($this->outerBoundary !== null) { $str = $this->outerBoundary->toGeoJSON(); $numberOfInnerBoundaries = count($this->innerBoundaryArray); if ($numberOfInnerBoundaries > 0) { $str .= ", "; for ($i=0; $i < $numberOfInnerBoundaries; $i++) { if ($i > 0) { $str .= ","; } $str .= $this->innerBoundaryArray[$i]->toGeoJSON(); } } return "{\"type\": \"Polygon\", \"coordinates\": [" . $str . "]}"; } $e = new mb_exception("KMLPolygon: toGeoJSON: this point is null."); return ""; } /** * Cuts a hole in the polygon. * * @param KMLLinearRing $aLinearRing the linear ring describing the hole that is being cut. * @return bool true, if the parameter is a linear ring; else false */ public function appendInnerBoundary ($aLinearRing) { if ($aLinearRing instanceof KMLLinearRing) { array_push($this->innerBoundaryArray, $aLinearRing); return true; } $e = new mb_exception("class_kml_polygon.php: appendInnerBoundary: parameter not a linear ring."); return false; } /** * @var KMLLinearRing The outer boundary of the polygon */ private $outerBoundary; /** * @var KMLLinearRing[] The inner boundaries (holes) of the polygon */ private $innerBoundaryArray = array(); } ?>