[Commits] r1615 - in sandbox/cmoullet/ux/LayerManager: examples ux ux/data ux/widgets

commits at geoext.org commits at geoext.org
Sat Dec 26 08:10:43 CET 2009


Author: cmoullet
Date: 2009-12-26 08:10:43 +0100 (Sat, 26 Dec 2009)
New Revision: 1615

Added:
   sandbox/cmoullet/ux/LayerManager/ux/data/
   sandbox/cmoullet/ux/LayerManager/ux/data/Export.js
   sandbox/cmoullet/ux/LayerManager/ux/data/FormatStore.js
Modified:
   sandbox/cmoullet/ux/LayerManager/examples/LayerManagerExample.html
   sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportPanel.js
   sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerTabPanel.js
Log:


Modified: sandbox/cmoullet/ux/LayerManager/examples/LayerManagerExample.html
===================================================================
--- sandbox/cmoullet/ux/LayerManager/examples/LayerManagerExample.html	2009-12-26 04:40:32 UTC (rev 1614)
+++ sandbox/cmoullet/ux/LayerManager/examples/LayerManagerExample.html	2009-12-26 07:10:43 UTC (rev 1615)
@@ -8,6 +8,8 @@
     <script type="text/javascript" src="http://openlayers.org/api/2.8/OpenLayers.js"></script>
     <script type="text/javascript" src="../../../trunk/geoext/lib/GeoExt.js"></script>
     <script type="text/javascript" src="../ux/form/FileUploadField.js"></script>
+    <script type="text/javascript" src="../ux/data/FormatStore.js"></script>
+    <script type="text/javascript" src="../ux/data/Export.js"></script>
     <script type="text/javascript" src="../ux/widgets/LayerManagerExportPanel.js"></script>
     <script type="text/javascript" src="../ux/widgets/LayerManagerTabPanel.js"></script>
     <script type="text/javascript" src="../ux/widgets/LayerManagerWindow.js"></script>

Added: sandbox/cmoullet/ux/LayerManager/ux/data/Export.js
===================================================================
--- sandbox/cmoullet/ux/LayerManager/ux/data/Export.js	                        (rev 0)
+++ sandbox/cmoullet/ux/LayerManager/ux/data/Export.js	2009-12-26 07:10:43 UTC (rev 1615)
@@ -0,0 +1,71 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace("GeoExt.ux.data");
+
+// layers: optional {Array(<OpenLayers.Layer>)}
+// features: optional: {Array(<OpenLayers.Feature.Vector>)} 
+GeoExt.ux.data.Export = function(map, format, layers, features) {
+    var exportLayers = [];
+    var exportFeatures = [];
+
+    if (layers) {
+        exportLayers = layers;
+    } else {
+        for (var i = 0; i < map.layers.length; i++) {
+            var layer = map.layers[i];
+            if (layer.CLASS_NAME) {
+                if (GeoExt.ux.data.Export.isLayerSupported(layer.CLASS_NAME)) {
+                    exportLayers.push(layer);
+                }
+            }
+        }
+    }
+    
+    if (features) {
+       exportFeatures = features;
+    } else {
+        for (var j = 0; j < exportLayers.length; j++) {
+            var exportLayer = exportLayers[j];
+            if (exportLayer.features) {
+                for (var k = 0; k < exportLayer.features.length; k++) {
+                   exportFeatures.push(exportLayer.features[k]);
+                }
+            }
+        }
+    }
+
+    if (format == 'KML') {
+        var kmlWriter = new OpenLayers.Format.KML(GeoExt.ux.data.formats.getFormatExportConfig(format));
+        return kmlWriter.write(exportFeatures);
+    } else {
+        return 'Format ' + format + ' not supported. Patch welcome !';
+    }
+
+};
+
+GeoExt.ux.data.Export.isLayerSupported = function(className) {
+    for (var i = 0; i < GeoExt.ux.data.Export.SupportedLayerType.length; i++) {
+        if (GeoExt.ux.data.Export.SupportedLayerType[i][0] === className) {
+            return true;
+        }
+    }
+    return false;
+};
+
+GeoExt.ux.data.Export.OpenWindowIE = function(content) {
+    alert('hello');
+};
+
+
+GeoExt.ux.data.Export.SupportedLayerType = [
+    ['OpenLayers.Layer.Vector'],
+    ['OpenLayers.Layer.WFS'],
+    ['OpenLayers.Layer.GML'],
+    ['OpenLayers.Layer.PointTrack']
+];
\ No newline at end of file

Added: sandbox/cmoullet/ux/LayerManager/ux/data/FormatStore.js
===================================================================
--- sandbox/cmoullet/ux/LayerManager/ux/data/FormatStore.js	                        (rev 0)
+++ sandbox/cmoullet/ux/LayerManager/ux/data/FormatStore.js	2009-12-26 07:10:43 UTC (rev 1615)
@@ -0,0 +1,30 @@
+/**
+ * Copyright (c) 2008-2009 The Open Source Geospatial Foundation
+ *
+ * Published under the BSD license.
+ * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text
+ * of the license.
+ */
+
+Ext.namespace("GeoExt.ux.data");
+
+GeoExt.ux.data.formats = [
+    ['KML', 'OpenLayers.Format.KML', '{extractStyles: true}']
+];
+
+GeoExt.ux.data.formats.getFormatExportConfig = function(format) {
+     for (var i = 0; i < GeoExt.ux.data.formats.length; i++) {
+        if (GeoExt.ux.data.formats[i][0] === format) {
+            return GeoExt.ux.data.formats[i][2];
+        }
+    }
+    return '{}';  
+};
+
+GeoExt.ux.data.FormatStore = new Ext.data.SimpleStore({
+   fields: ['shortName', 'openLayersClass', 'formatExportConfig'],
+   data: GeoExt.ux.data.formats
+});
+
+
+

Modified: sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportPanel.js
===================================================================
--- sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportPanel.js	2009-12-26 04:40:32 UTC (rev 1614)
+++ sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerExportPanel.js	2009-12-26 07:10:43 UTC (rev 1615)
@@ -11,13 +11,33 @@
 GeoExt.ux.LayerManagerExportPanel = Ext.extend(Ext.Panel, {
     border: false,
     formatCombo: null,
+    exportLinkBox: null,
+    defaultFormat: 'KML',
+
     initComponent: function() {
 
         this.formatCombo = new Ext.form.ComboBox({
             id: 'layermanagerexportformat',
-            fieldLabel: OpenLayers.i18n('Format')
+            fieldLabel: OpenLayers.i18n('Format'),
+            store: GeoExt.ux.data.FormatStore,
+            displayField:'shortName',
+            typeAhead: true,
+            mode: 'local',
+            triggerAction: 'all',
+            emptyText:'Select a format...',
+            selectOnFocus:true,
+            resizable:true
         });
 
+        this.formatCombo.setValue(this.defaultFormat);
+
+        this.exportLinkBox = new Ext.BoxComponent({
+            id: 'exportlink',
+            autoEl: {
+                html: '<a href=""></a>'
+            }
+        });
+
         this.items = [
             {
                 layout: 'form',
@@ -62,13 +82,41 @@
                                 xtype:'button',
                                 text: OpenLayers.i18n('Export'),
                                 handler: function() {
-                                    alert('Export')
+                                    var exportContent = GeoExt.ux.data.Export(this.map, this.formatCombo.getValue(), null, null);
+
+                                    if (Ext.isIE) {
+                                        // TODO this.exportLinkBox.getEl().dom.innerHTML = '<a href="javascript:GeoExt.ux.data.Export.OpenWindowIE(\''+exportContent+'\');">Save file</a>';
+                                        return;
+                                    }
+                                    if (Ext.isGecko) {
+                                        this.exportLinkBox.getEl().dom.innerHTML = '<a href="data:text/xml,'+exportContent.replace(/"/g,'\'')+'" target="new">Right mouse click, Save As...</a>';
+                                        return;
+                                    }
+                                    this.exportLinkBox.getEl().dom.innerHTML = 'Your browser is not supported';
                                 },
                                 scope: this
                             }
                         ]
                     }
                 ]
+            },
+            {
+                layout: 'column',
+                border: false,
+                defaults:{
+                    layout:'form',
+                    border:false,
+                    bodyStyle:'padding:5px 5px 5px 5px'
+                },
+                items: [
+                    {
+                        columnWidth: 1,
+                        bodyCfg: {tag:'center'},
+                        items: [
+                                this.exportLinkBox
+                        ]
+                    }
+                ]
             }
 
         ];

Modified: sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerTabPanel.js
===================================================================
--- sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerTabPanel.js	2009-12-26 04:40:32 UTC (rev 1614)
+++ sandbox/cmoullet/ux/LayerManager/ux/widgets/LayerManagerTabPanel.js	2009-12-26 07:10:43 UTC (rev 1615)
@@ -16,7 +16,8 @@
 
     initComponent: function() {
         this.exportPanel = new GeoExt.ux.LayerManagerExportPanel({
-            map: this.map
+            map: this.map,
+            defaultFormat: 'KML'
         });
 
         this.items = [



More information about the Commits mailing list