[Mapbender-commits] r8944 - in trunk/mapbender/http: php plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Mon Jun 30 00:57:20 PDT 2014


Author: hwbllmnn
Date: 2014-06-30 00:57:20 -0700 (Mon, 30 Jun 2014)
New Revision: 8944

Modified:
   trunk/mapbender/http/php/uploadKml.php
   trunk/mapbender/http/plugins/kmlTree.js
Log:
added GPX and GeoJSON upload


Modified: trunk/mapbender/http/php/uploadKml.php
===================================================================
--- trunk/mapbender/http/php/uploadKml.php	2014-06-27 14:13:21 UTC (rev 8943)
+++ trunk/mapbender/http/php/uploadKml.php	2014-06-30 07:57:20 UTC (rev 8944)
@@ -19,21 +19,29 @@
 require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
 require_once(dirname(__FILE__) . "/../classes/class_kml_ows.php");
 
-
 header("Content-Type: application/vnd.geo+json");
 
 $kml = new KML();
-$kmlString = file_get_contents($_FILES['kml']['tmp_name']);
+$content = file_get_contents($_FILES['kml']['tmp_name']);
 try {
+    if(preg_match('/.kml$/', $_FILES['kml']['name'])) {
+        header("Content-Type: application/vnd.geo+json");
+        if($kml->parseKml($content)){
+            $geojson  =  $kml->toGeoJSON();
+            echo $geojson;
+        }else{
+            echo("{}");
+        }
+    }
+    if(preg_match('/.(json|geojson)$/', $_FILES['kml']['name'])) {
+        header("Content-Type: application/vnd.geo+json");
+        echo $content;
+    }
+    if(preg_match('/.(xml|gpx)$/', $_FILES['kml']['name'])) {
+        header("Content-Type: text/plain");
+        echo $content;
+    }
 
-	if($kml->parseKml($kmlString)){
-		$geojson  =  $kml->toGeoJSON();
-		echo $geojson;
-	}else{
-		echo("{}");
-	}
-
-
 } catch (Exception $e) {
 	echo($e);
 	die;

Modified: trunk/mapbender/http/plugins/kmlTree.js
===================================================================
--- trunk/mapbender/http/plugins/kmlTree.js	2014-06-27 14:13:21 UTC (rev 8943)
+++ trunk/mapbender/http/plugins/kmlTree.js	2014-06-30 07:57:20 UTC (rev 8944)
@@ -36,6 +36,35 @@
  * http://svn.osgeo.org/mapbender/trunk/mapbender/license/license.txt
  */
 
+if( typeof window.DOMParser === "undefined" ){
+    window.DOMParser = function(){};
+
+    window.DOMParser.prototype.parseFromString = function(str, contentType){
+        if(typeof ActiveXObject !== 'undefined'){
+            var xmldata = new ActiveXObject('MSXML.DomDocument');
+            xmldata.async = false;
+            xmldata.loadXML(str);
+            return xmldata;
+        } else if(typeof XMLHttpRequest !== 'undefined'){
+            var xmldata = new XMLHttpRequest;
+
+            if(!contentType){
+                contentType = 'application/xml';
+            }
+
+            xmldata.open('GET', 'data:' + contentType + ';charset=utf-8,' + encodeURIComponent(str), false);
+
+            if(xmldata.overrideMimeType) {
+                xmldata.overrideMimeType(contentType);
+            }
+
+            xmldata.send(null);
+            return xmldata.responseXML;
+        }
+    };
+
+}
+
 var $kmlTree = $(this);
 var KmlTree = function(o){
     $kmlTree.children().remove();
@@ -81,7 +110,14 @@
         $('#kml-from-upload form').bind('submit', function() {
             $('iframe[name="kml-upload-target').bind('load', function() {
                 $(this).unbind('load');
-                var data = JSON.parse($(this).contents().find('pre').text());
+                var txt = $(this).contents().find('pre').text();
+                var data;
+                try {
+                    data = JSON.parse(txt);
+                } catch(e) {
+                    var xml = new DOMParser().parseFromString(txt, 'application/xml');
+                    data = toGeoJSON.gpx(xml);
+                }
                 var kml = $('#mapframe1').data('kml');
                 var name = $('#kml-from-upload input[type="file"]').val();
                 name = name.match(/[\\]([^\\]+)/g);



More information about the Mapbender_commits mailing list