From d501fa8a29291499c668bed9ddfcb4fc328b2e25 Mon Sep 17 00:00:00 2001 From: arno Date: Tue, 24 Aug 2010 23:48:24 +0200 Subject: [PATCH] kml export --- application/controllers/GeomController.php | 47 +++++++++++++++++++++- application/views/scripts/idx/index.phtml | 22 +++++++++- public/css/syj.css | 7 ++++ 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/application/controllers/GeomController.php b/application/controllers/GeomController.php index 5e0a034..f97d016 100644 --- a/application/controllers/GeomController.php +++ b/application/controllers/GeomController.php @@ -10,11 +10,23 @@ class GeomController extends Zend_Controller_Action $response = $this->getResponse(); $idx = $request->idx; + $pathMapper = new Syj_Model_PathMapper(); $path = new Syj_Model_Path(); $api = $this->_helper->SyjApi; + $ext = ""; + $parts = explode('.', $idx); + if (count($parts) >= 2) { + $ext = end($parts); + if (in_array($ext, array('kml', 'gpx', 'json'))) { + $idx = implode('.', explode('.', $idx, -1)); + } else { + $ext = ""; + } + } + if (!$pathMapper->find($idx, $path)) { if ($pathMapper->hasexisted($idx)) { $api->setCode(410); @@ -24,12 +36,45 @@ class GeomController extends Zend_Controller_Action return; } + switch ($ext) { + case 'kml': + $this->kml($path); + break; + case 'gpx': + $this->gpx($path); + break; + case 'json': + default: + $this->json($path); + return; + break; + } + } + + protected function kml(Syj_Model_Path $path) { + $data = '' . PHP_EOL; // '; + $data .= ''; + if ($path->creator) { + $data .= '' . htmlspecialchars($path->creator->pseudo) . ''; + } + $data .= '' . htmlspecialchars($path->displayTitle) . ''; + $data .= $path->geom->toKML(); + $data .= ''; + $data .= ''; + + $api = $this->_helper->SyjApi; + $api->setCheckIfNoneMatch(true)->setContentType('application/vnd.google-earth.kml+xml')->setBody($data); + } + + protected function json(Syj_Model_Path $path) { $data = array('geom' => (string)$path->geom, 'title' => (string)$path->displayTitle); if ($path->creator) { $data['creator'] = (string)$path->creator->pseudo; } - + $api = $this->_helper->SyjApi; $api->setCheckIfNoneMatch(true)->setBodyJson($data); } + } diff --git a/application/views/scripts/idx/index.phtml b/application/views/scripts/idx/index.phtml index f2983ee..95535d3 100644 --- a/application/views/scripts/idx/index.phtml +++ b/application/views/scripts/idx/index.phtml @@ -58,17 +58,37 @@
translate("route infos")?>
diff --git a/public/css/syj.css b/public/css/syj.css index e8b6d43..44cfc9f 100644 --- a/public/css/syj.css +++ b/public/css/syj.css @@ -87,6 +87,13 @@ body, html { padding: 4px 15px 15px 15px; } +#path-export-title { + margin-top: 1em; +} +#path-export-content a { + text-decoration: none; +} + #path-length { text-align: center; position: absolute; /* otherwise, under #map in ie */ -- 2.39.2