]> dev.renevier.net Git - syj.git/commitdiff
kml export
authorarno <arno@renevier.net>
Tue, 24 Aug 2010 21:48:24 +0000 (23:48 +0200)
committerarno <arno@renevier.net>
Tue, 24 Aug 2010 21:48:24 +0000 (23:48 +0200)
application/controllers/GeomController.php
application/views/scripts/idx/index.phtml
public/css/syj.css

index 5e0a0340ea887ef1ba6af94b22816446d44aa7ca..f97d016c554ee0f950723d97b8c920c7395cd01e 100644 (file)
@@ -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 = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;   // <? <-- vim syntax goes crazy
+        $data .= '<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:atom="http://www.w3.org/2005/Atom">';
+        $data .= '<Placemark>';
+        if ($path->creator) {
+            $data .= '<atom:author><atom:name>' . htmlspecialchars($path->creator->pseudo) . '</atom:name></atom:author>';
+        }
+        $data .= '<name>' . htmlspecialchars($path->displayTitle) . '</name>';
+        $data .= $path->geom->toKML();
+        $data .= '</Placemark>';
+        $data .= '</kml>';
+
+        $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);
     }
+
 }
index f2983ee521afa5459c57d217423fcb9f6d904e79..95535d3967f6f3ca883017e872d177ebc784399a 100644 (file)
                 <div id="path-infos-toggler"><a href="" id="path-infos-anchor"><?php echo $this->translate("route infos")?></a></div>
              </div>
                 <div id="path-infos-content" class="menu-item">
+
                     <div id="path-directlink-title" class="info-title"><?php echo $this->translate("direct link")?></div>
                     <div id="path-directlink-content"><?php
                             $serverUrl = rtrim($this->serverUrl(), '/');
                             $baseUrl = trim($this->baseUrl(), '/');
+                            $fullBaseUrl = $serverUrl . '/' . ($baseUrl ? ($baseUrl . '/'): '');
                             $urlcomp = urlencode($this->path->urlcomp ?: $this->path->id);
-                            $href = $serverUrl . '/' . ($baseUrl ? ($baseUrl . '/'): '') . 'idx/' . $urlcomp . '?format=raw';
+                            $href = $fullBaseUrl . 'idx/' . $urlcomp . '?format=raw';
                             printf('<a href="%s" title="%s">%s</a>',
                                         $href,
                                         $this->translate('direct link'),
                                         $this->escape($href));
                         ?></div>
+
+                    <div id="path-export-title" class="info-title"><?php echo $this->translate("export")?></div>
+                    <div id="path-export-content"><?php
+                       $href = $fullBaseUrl . 'geom/' . urlencode($this->path->id) . '.kml';
+                       printf('<a href="%s" title="%s">%s</a>',
+                                        $href,
+                                        $this->translate('kml export'),
+                                        $this->translate('kml export'));
+
+                        print '<br>';
+                       $href = $fullBaseUrl . 'geom/' . urlencode($this->path->id) . '.gpx';
+                       printf('<a href="%s" title="%s">%s</a>',
+                                        $href,
+                                        $this->translate('gpx export'),
+                                        $this->translate('gpx export'));
+                       ?>
+
+
                 </div>
             </div>
         </div>
index e8b6d43d421b4f6203d20d73050709ee23cf31c9..44cfc9f63152d1a06b1a1c19cc06fdb57f063af2 100644 (file)
@@ -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 */