]> dev.renevier.net Git - syj.git/blobdiff - application/controllers/GeomController.php
update copyright headers
[syj.git] / application / controllers / GeomController.php
index f97d016c554ee0f950723d97b8c920c7395cd01e..0c399fedd89684f989e17bb860b4e62222117351 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/*  This file is part of Syj, Copyright (c) 2010 Arnaud Renevier,
+/*  This file is part of Syj, Copyright (c) 2010-2011 Arnaud Renevier,
     and is published under the AGPL license. */
 
 class GeomController extends Zend_Controller_Action
@@ -67,11 +67,27 @@ class GeomController extends Zend_Controller_Action
         $api->setCheckIfNoneMatch(true)->setContentType('application/vnd.google-earth.kml+xml')->setBody($data);
     }
 
+    protected function gpx(Syj_Model_Path $path) {
+        $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;   // <? <-- vim syntax goes crazy
+        $data .= '<gpx creator="syj" version="1.0" xmlns="http://www.topografix.com/GPX/1/0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">';
+        $data .= '<trk>';
+        if ($path->creator) {
+            $data .= '<author>' . htmlspecialchars($path->creator->pseudo) . '</author>';
+        }
+        $data .= '<name>' . htmlspecialchars($path->displayTitle) . '</name>';
+        $data .= $path->geom->toGPX();
+        $data .= '</trk>';
+        $data .= '</gpx>';
+
+        $api = $this->_helper->SyjApi;
+        $api->setCheckIfNoneMatch(true)->setContentType('application/octet-stream')->setBody($data);
+    }
+
     protected function json(Syj_Model_Path $path) {
-        $data = array('geom' => (string)$path->geom,
-                  'title' => (string)$path->displayTitle);
+        $data = json_decode($path->geom->toGeoJSON());
+        $data->title = (string)$path->displayTitle;
         if ($path->creator) {
-            $data['creator'] = (string)$path->creator->pseudo;
+            $data->creator = (string)$path->creator->pseudo;
         }
         $api = $this->_helper->SyjApi;
         $api->setCheckIfNoneMatch(true)->setBodyJson($data);