merge linestrings for gpx containting multiple trkseg elements.
authorArno Renevier <arno@renevier.net>
Thu, 27 Oct 2011 08:03:39 +0000 (10:03 +0200)
committerArno Renevier <arno@renevier.net>
Thu, 27 Oct 2011 21:28:46 +0000 (23:28 +0200)
application/controllers/PathController.php
public/js/syj.js

index 394da69..af9d104 100644 (file)
@@ -77,6 +77,18 @@ class PathController extends Zend_Controller_Action
             throw new Syj_Exception_InvalidGeomUpload();
         }
 
+        // merge linestrings for gpx containting multiple trkseg elements.
+        if ($classname == 'gisconverter\\GPX' && $geom::name == 'GeometryCollection') {
+          $geomstring = "";
+          foreach (array_filter($geom->components, function ($geom) {
+            return $geom::name == "LineString";
+          }) as $linestring) {
+            $geomstring .= str_replace("<trkseg>", "",
+                              str_replace("</trkseg>", "", $linestring->toGPX()));
+          }
+          $geom = $decoder->geomFromText("<trkseg>" . $geomstring . "</trkseg>");
+        }
+
         if ($geom::name != "LineString") {
             throw new Syj_Exception_InvalidGeomUpload();
         }
index 7864fe9..8f5f509 100644 (file)
@@ -372,7 +372,7 @@ var SYJView = {
                     this.messenger.setMessage(SyjStrings.uploadFileError, "warn");
                 }.bind(this);
                 reader.onload = function(evt) {
-                    var data = null, results = null, engine = null, vector = null, i = 0, formats = ['KML', 'GPX', 'GeoJSON'];
+                    var data = null, results = null, engine = null, vector = null, i = 0, format = null, formats = ['KML', 'GPX', 'GeoJSON'];
 
                     $("geom_upload_container").removeClassName("disabled");
                     $("geom_upload").disabled = false;
@@ -383,7 +383,8 @@ var SYJView = {
                     data = evt.target.result;
 
                     for (i = 0; i < formats.length; i++) {
-                        engine = new OpenLayers.Format[formats[i]]({ internalProjection: Mercator, externalProjection: WGS84 });
+                        format = formats[i];
+                        engine = new OpenLayers.Format[format]({ internalProjection: Mercator, externalProjection: WGS84 });
                         try {
                             results = engine.read(data);
                         } catch(e) {
@@ -402,6 +403,12 @@ var SYJView = {
                         readerror();
                         return;
                     }
+                    // merge linestrings for gpx containting multiple trkseg elements.
+                    if (format === 'GPX') {
+                      for (i = 1; i < results.length; i++) {
+                        vector.geometry.addComponents(results[i].geometry.components);
+                      }
+                    }
                     this.viewLayer.addFeatures([vector]);
                     this.map.zoomToExtent(this.viewLayer.getDataExtent());