[Mapbender-commits] r8969 - trunk/mapbender/http/plugins

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Wed Jul 2 01:43:44 PDT 2014


Author: hwbllmnn
Date: 2014-07-02 01:43:44 -0700 (Wed, 02 Jul 2014)
New Revision: 8969

Modified:
   trunk/mapbender/http/plugins/mb_digitize_widget.php
Log:
proper filenames when downloading features


Modified: trunk/mapbender/http/plugins/mb_digitize_widget.php
===================================================================
--- trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-07-02 07:38:33 UTC (rev 8968)
+++ trunk/mapbender/http/plugins/mb_digitize_widget.php	2014-07-02 08:43:44 UTC (rev 8969)
@@ -153,7 +153,7 @@
                      + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>'
                      + '<label class="export-format-gpx">GPX<input type="radio" name="export-format" value="gpx"></input></label>'
                      + '<label class="export-format-geojson">geoJSON<input type="radio" name="export-format" value="geojson"></input></label><br></br>'
-                     + '<div class="digitize-image digitize-export" style="float: left;"></div>'
+                     + '<a download="myfeatures.kml" href="#" class="digitize-image digitize-export" style="float: left;"></a>'
                      + '</form>'
                      + '</div>';
 
@@ -289,21 +289,47 @@
 
     var exportItem = function(data) {
         var dlg = $(exportHtml).dialog({ width: 330, height: 165 });
-        $(dlg).find('.digitize-export').bind('click', function() {
-            var fmt = $(dlg).find('input:checked').val();
-            $(dlg).dialog('destroy');
+        $(dlg).find('input').bind('change', function() {
+            var fmt = $(this).val();
+            var url;
             if(fmt === 'kml') {
-                var kml = tokml(data, {simplestyle: true});
-                window.open('data:application/octet-stream,' + encodeURIComponent(kml));
+                url = tokml(data, {simplestyle: true});
             }
             if(fmt === 'gpx') {
-                var gpx = togpx(data, {simplestyle: true});
-                window.open('data:application/octet-stream,' + encodeURIComponent(gpx));
+                url = togpx(data, {simplestyle: true});
             }
             if(fmt === 'geojson') {
-                var json = JSON.stringify(data);
-                window.open('data:application/octet-stream,' + encodeURIComponent(json));
+                url = JSON.stringify(data);
             }
+            url = 'data:application/octet-stream,' + encodeURIComponent(url);
+
+            var lnk = $(dlg).find('.digitize-export')
+            .attr('download', 'myfeatures.' + fmt)
+            .attr('href', url);
+        }).change();
+        $(dlg).find('.digitize-export').bind('click', function() {
+            if(window.chrome) {
+                var fmt = $(dlg).find('input:checked').val();
+                var url;
+                if(fmt === 'kml') {
+                    url = tokml(data, {simplestyle: true});
+                }
+                if(fmt === 'gpx') {
+                    url = togpx(data, {simplestyle: true});
+                }
+                if(fmt === 'geojson') {
+                    url = JSON.stringify(data);
+                }
+
+                var link = document.createElement("a");
+                link.setAttribute('download', 'myfeatures.' + fmt);
+                console.log(link.download)
+                link.href = URL.createObjectURL(new Blob([url], {type: 'application/octet-stream'}));
+                link.click();
+
+                return false;
+            }
+            return undefined;
         });
     };
 



More information about the Mapbender_commits mailing list