diff --git a/lib/adapters/KML.class.php b/lib/adapters/KML.class.php
index 2130f638..4d76d767 100644
--- a/lib/adapters/KML.class.php
+++ b/lib/adapters/KML.class.php
@@ -20,7 +20,9 @@
*/
class KML extends GeoAdapter
{
-
+ private $namespace = FALSE;
+ private $nss = ''; // Name-space string. eg 'georss:'
+
/**
* Read KML string into geometry objects
*
@@ -39,7 +41,11 @@ public function read($kml) {
*
* @return string The KML string representation of the input geometries
*/
- public function write(Geometry $geometry) {
+ public function write(Geometry $geometry, $namespace = FALSE) {
+ if ($namespace) {
+ $this->namespace = $namespace;
+ $this->nss = $namespace.':';
+ }
return $this->geometryToKML($geometry);
}
@@ -199,7 +205,7 @@ private function geometryToKML($geom) {
}
private function pointToKML($geom) {
- return "".$geom->getX().",".$geom->getY()."";
+ return '<'.$this->nss.'Point><'.$this->nss.'coordinates>'.$geom->getX().",".$geom->getY().''.$this->nss.'coordinates>'.$this->nss.'Point>';
}
private function linestringToKML($geom, $type = FALSE) {
@@ -207,7 +213,7 @@ private function linestringToKML($geom, $type = FALSE) {
$type = $geom->getGeomType();
}
- $str = '<'. $type .'>';
+ $str = '<'.$this->nss . $type .'><'.$this->nss.'coordinates>';
$i=0;
foreach ($geom->getComponents() as $comp) {
if ($i != 0) $str .= ' ';
@@ -215,28 +221,28 @@ private function linestringToKML($geom, $type = FALSE) {
$i++;
}
- return $str .''. $type .'>';
+ return $str .''.$this->nss.'coordinates>'. $this->nss . $type .'>';
}
public function polygonToKML($geom) {
$components = $geom->getComponents();
- $str = '' . $this->linestringToKML($components[0], 'LinearRing') . '';
+ $str = '<'.$this->nss.'outerBoundaryIs>' . $this->linestringToKML($components[0], 'LinearRing') . ''.$this->nss.'outerBoundaryIs>';
foreach (array_slice($components, 1) as $comp) {
- $str .= '' . $this->linestringToKML($comp) . '';
+ $str .= '<'.$this->nss.'innerBoundaryIs>' . $this->linestringToKML($comp) . ''.$this->nss.'innerBoundaryIs>';
}
- return ''. $str .'';
+ return '<'.$this->nss.'Polygon>'. $str .''.$this->nss.'Polygon>';
}
public function collectionToKML($geom) {
$components = $geom->getComponents();
- $str = '';
+ $str = '<'.$this->nss.'MultiGeometry>';
foreach ($geom->getComponents() as $comp) {
$sub_adapter = new KML();
$str .= $sub_adapter->write($comp);
}
- return $str .'';
+ return $str .''.$this->nss.'MultiGeometry>';
}
}