[Commits] r1077 - in sandbox/camptocamp/geobretagne: examples lib/GeoExt/data lib/GeoExt/widgets lib/GeoExt/widgets/tree tests tests/lib/GeoExt/data tests/lib/GeoExt/widgets tests/lib/GeoExt/widgets/tree

commits at geoext.org commits at geoext.org
Sat Jun 13 14:48:11 CEST 2009


Author: elemoine
Date: 2009-06-13 14:48:11 +0200 (Sat, 13 Jun 2009)
New Revision: 1077

Added:
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/LegendImage.html
Modified:
   sandbox/camptocamp/geobretagne/examples/legendpanel.js
   sandbox/camptocamp/geobretagne/examples/mappanel-div.js
   sandbox/camptocamp/geobretagne/examples/mappanel-viewport.js
   sandbox/camptocamp/geobretagne/examples/mappanel-window.js
   sandbox/camptocamp/geobretagne/examples/toolbar.js
   sandbox/camptocamp/geobretagne/examples/tree.js
   sandbox/camptocamp/geobretagne/examples/zoom-chooser.js
   sandbox/camptocamp/geobretagne/lib/GeoExt/data/LayerStore.js
   sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendImage.js
   sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendPanel.js
   sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/tree/LayerContainer.js
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/LayerStore.html
   sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/tree/LayerContainer.html
   sandbox/camptocamp/geobretagne/tests/list-tests.html
Log:
svn merge -r1042:HEAD http://svn.geoext.org/core/trunk/geoext .


Modified: sandbox/camptocamp/geobretagne/examples/legendpanel.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/legendpanel.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/legendpanel.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -13,12 +13,12 @@
     map.addLayers([
         new OpenLayers.Layer.WMS(
             "Tasmania",
-            "http://publicus.opengeo.org/geoserver/wms?",
+            "http://demo.opengeo.org/geoserver/wms?",
             {layers: 'topp:tasmania_state_boundaries', format: 'image/png', transparent: true},
             {singleTile: true}),
         new OpenLayers.Layer.WMS(
             "Cities and Roads",
-            "http://publicus.opengeo.org/geoserver/wms?",
+            "http://demo.opengeo.org/geoserver/wms?",
             {layers: 'topp:tasmania_cities,topp:tasmania_roads', format: 'image/png', transparent: true},
             {singleTile: true}),
         new OpenLayers.Layer.Vector('Polygons', {styleMap: new OpenLayers.StyleMap({
@@ -33,7 +33,7 @@
 
     var addLayer = function() {
         var wmslayer = new OpenLayers.Layer.WMS("Bodies of Water",
-            "http://publicus.opengeo.org/geoserver/wms?",
+            "http://demo.opengeo.org/geoserver/wms?",
             {layers: 'topp:tasmania_water_bodies', format: 'image/png', transparent: true},
             {singleTile: true});
         mapPanel.map.addLayer(wmslayer);

Modified: sandbox/camptocamp/geobretagne/examples/mappanel-div.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/mappanel-div.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/mappanel-div.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -11,8 +11,8 @@
 Ext.onReady(function() {
     var map = new OpenLayers.Map();
     var layer = new OpenLayers.Layer.WMS(
-        "bluemarble",
-        "http://sigma.openplans.org/geoserver/wms?",
+        "Global Imagery",
+        "http://demo.opengeo.org/geoserver/wms",
         {layers: 'bluemarble'}
     );
     map.addLayer(layer);

Modified: sandbox/camptocamp/geobretagne/examples/mappanel-viewport.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/mappanel-viewport.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/mappanel-viewport.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -39,8 +39,8 @@
 
     } else {
         layer = new OpenLayers.Layer.WMS(
-            "bluemarble",
-            "http://sigma.openplans.org/geoserver/wms?",
+            "Global Imagery",
+            "http://demo.opengeo.org/geoserver/wms",
             {layers: 'bluemarble'},
             {isBaseLayer: true}
         );

Modified: sandbox/camptocamp/geobretagne/examples/mappanel-window.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/mappanel-window.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/mappanel-window.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -18,8 +18,8 @@
             xtype: "gx_mappanel",
             id: "mappanel",
             layers: [new OpenLayers.Layer.WMS(
-                "bluemarble",
-                "http://sigma.openplans.org/geoserver/wms?",
+                "Global Imagery",
+                "http://demo.opengeo.org/geoserver/wms",
                 {layers: 'bluemarble'}
             )],
             extent: "-5,35,15,55"

Modified: sandbox/camptocamp/geobretagne/examples/toolbar.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/toolbar.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/toolbar.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -9,8 +9,8 @@
 Ext.onReady(function() {
     var map = new OpenLayers.Map();
     var wms = new OpenLayers.Layer.WMS(
-        "bluemarble",
-        "http://sigma.openplans.org/geoserver/wms?",
+        "Global Imagery",
+        "http://demo.opengeo.org/geoserver/wms",
         {layers: 'bluemarble'}
     );
     var vector = new OpenLayers.Layer.Vector("vector");

Modified: sandbox/camptocamp/geobretagne/examples/tree.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/tree.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/tree.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -32,8 +32,8 @@
         center: [146.1569825, -41.6109735],
         zoom: 6,
         layers: [
-            new OpenLayers.Layer.WMS("Blue Marble",
-                "http://sigma.openplans.org/geoserver/wms", {
+            new OpenLayers.Layer.WMS("Global Imagery",
+                "http://demo.opengeo.org/geoserver/wms", {
                     layers: "bluemarble"
                 }, {
                     buffer: 0,

Modified: sandbox/camptocamp/geobretagne/examples/zoom-chooser.js
===================================================================
--- sandbox/camptocamp/geobretagne/examples/zoom-chooser.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/examples/zoom-chooser.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -11,8 +11,8 @@
 Ext.onReady(function() {
     var map = new OpenLayers.Map();
     var layer = new OpenLayers.Layer.WMS(
-        "bluemarble",
-        "http://sigma.openplans.org/geoserver/wms?",
+        "Global Imagery",
+        "http://demo.opengeo.org/geoserver/wms",
         {layers: 'bluemarble'}
     );
     map.addLayer(layer);

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/data/LayerStore.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/data/LayerStore.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/data/LayerStore.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -155,6 +155,7 @@
             "clear": this.onClear,
             "add": this.onAdd,
             "remove": this.onRemove,
+            "update": this.onUpdate,
             scope: this
         });
         this.data.on({
@@ -210,6 +211,8 @@
                         delete this._adding;
                     }
                 }
+            } else if(evt.property === "name") {
+                record.set("title", layer.name);
             } else {
                 this.fireEvent("update", this, record, Ext.data.Record.EDIT);
             }
@@ -328,6 +331,23 @@
             }
         }
     },
+    
+    /** private: method[onUpdate]
+     *  :param store: ``Ext.data.Store``
+     *  :param record: ``Ext.data.Record``
+     *  :param operation: ``Number``
+     * 
+     *  Handler for a store's update event
+     */
+    onUpdate: function(store, record, operation) {
+        if(operation === Ext.data.Record.EDIT) {
+            var layer = record.get("layer");
+            var title = record.get("title");
+            if(title !== layer.name) {
+                layer.setName(title);
+            }
+        }
+    },
 
     /** private: method[removeMapLayer]
      *  :param record: ``Ext.data.Record``

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendImage.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendImage.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendImage.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -26,19 +26,31 @@
      *  ``String``  The url of the image to load
      */
     url: null,
+    
+    /** api: config[defaultImgSrc]
+     *  ``String`` Path to image that will be used if the legend image fails
+     *  to load.  Default is Ext.BLANK_IMAGE_URL.
+     */
+    defaultImgSrc: null,
 
     /** api: config[imgCls]
      *  ``String``  Optional css class to apply to img tag
      */
     imgCls: null,
-
+    
     /** private: method[initComponent]
      *  Initializes the legend image component. 
      */
     initComponent: function() {
         GeoExt.LegendImage.superclass.initComponent.call(this);
-        this.autoEl = {tag: 'img',
-            'class': (this.imgCls ? this.imgCls : ''), src: this.url};
+        if(this.defaultImgSrc === null) {
+            this.defaultImgSrc = Ext.BLANK_IMAGE_URL;
+        }
+        this.autoEl = {
+            tag: "img",
+            "class": (this.imgCls ? this.imgCls : ""),
+            src: this.defaultImgSrc
+        };
     },
 
     /** api: method[setUrl]
@@ -47,8 +59,11 @@
      *  Sets the url of the image.
      */
     setUrl: function(url) {
+        this.url = url;
         var el = this.getEl();
         if (el) {
+            el.un("error", this.onImageLoadError, this);
+            el.on("error", this.onImageLoadError, this, {single: true});
             el.dom.src = url;
         }
     },
@@ -59,14 +74,19 @@
      */
     onRender: function(ct, position) {
         GeoExt.LegendImage.superclass.onRender.call(this, ct, position);
-        this.getEl().on('error', this.onImageLoadError, this);
+        if(this.url) {
+            this.setUrl(this.url);
+        }
     },
 
     /** private: method[onDestroy]
      *  Private method called during the destroy sequence.
      */
     onDestroy: function() {
-        this.getEl().un('error', this.onImageLoadError, this);
+        var el = this.getEl();
+        if(el) {
+            el.un("error", this.onImageLoadError, this);
+        }
         GeoExt.LegendImage.superclass.onDestroy.apply(this, arguments);
     },
     
@@ -74,9 +94,10 @@
      *  Private method called if the legend image fails loading.
      */
     onImageLoadError: function() {
-        this.getEl().dom.src = Ext.BLANK_IMAGE_URL;
+        this.getEl().dom.src = this.defaultImgSrc;
     }
 
 });
 
+
 Ext.reg('gx_legendimage', GeoExt.LegendImage);

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendPanel.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendPanel.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/LegendPanel.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -98,6 +98,7 @@
         var store = this.layerStore;
         var count = store.getCount();
         var panelIndex = -1;
+        var legendCount = this.items ? this.items.length : 0;
         for(var i=count-1; i>=0; --i) {
             var layer = store.getAt(i).get("layer");
             var legendGenerator = GeoExt[
@@ -106,7 +107,7 @@
             if(layer.displayInLayerSwitcher && legendGenerator &&
                 (store.getAt(i).get("hideInLegend") !== true)) {
                     ++panelIndex;
-                    if(index === i) {
+                    if(index === i || panelIndex > legendCount-1) {
                         break;
                     }
             }
@@ -150,7 +151,7 @@
      *  :param index: ``Integer`` The index of the inserted record.
      */
     onStoreAdd: function(store, records, index) {
-        var panelIndex = this.recordIndexToPanelIndex(index);
+        var panelIndex = this.recordIndexToPanelIndex(index+records.length-1);
         for (var i=0, len=records.length; i<len; i++) {
             this.addLegend(records[i], panelIndex);
         }

Modified: sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/tree/LayerContainer.js
===================================================================
--- sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/tree/LayerContainer.js	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/lib/GeoExt/widgets/tree/LayerContainer.js	2009-06-13 12:48:11 UTC (rev 1077)
@@ -80,7 +80,7 @@
      */
     onStoreAdd: function(store, records, index) {
         if(!this._reordering) {
-            var nodeIndex = this.recordIndexToNodeIndex(index);
+            var nodeIndex = this.recordIndexToNodeIndex(index+records.length-1);
             for(var i=0; i<records.length; ++i) {
                 this.addLayerNode(records[i], nodeIndex);
             }
@@ -117,11 +117,12 @@
     recordIndexToNodeIndex: function(index) {
         var store = this.layerStore;
         var count = store.getCount();
+        var nodeCount = this.childNodes.length;
         var nodeIndex = -1;
         for(var i=count-1; i>=0; --i) {
             if(store.getAt(i).get("layer").displayInLayerSwitcher) {
                 ++nodeIndex;
-                if(index === i) {
+                if(index === i || nodeIndex > nodeCount-1) {
                     break;
                 }
             }
@@ -162,7 +163,7 @@
         var layer = layerRecord.get("layer");
         if (layer.displayInLayerSwitcher === true) {
             var node = new GeoExt.tree.LayerNode(Ext.applyIf({
-                iconCls: layer.isBayeLayer ? 'baselayer-icon' : 'layer-icon',
+                iconCls: layer.isBaseLayer ? 'baselayer-icon' : 'layer-icon',
                 layer: layer,
                 layerStore: this.layerStore
             }, this.defaults));

Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/LayerStore.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/LayerStore.html	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/data/LayerStore.html	2009-06-13 12:48:11 UTC (rev 1077)
@@ -285,6 +285,26 @@
 
         }
         
+        function test_update(t) {
+            t.plan(2);
+            
+            var map = new OpenLayers.Map("mappanel");
+            var layer = new OpenLayers.Layer("foo");
+            map.addLayer(layer);
+
+            var store = new GeoExt.data.LayerStore({
+                map: map
+            });
+
+            layer.setName("newName");
+            t.eq(store.getAt(0).get("title"), "newName", "record title synced from layer name");
+            
+            store.getAt(0).set("title", "newTitle");
+            t.eq(layer.name, "newTitle", "layer name synced from record title");
+                                    
+            map.destroy();
+        }
+        
         function test_events(t) {
             t.plan(21);
             

Copied: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/LegendImage.html (from rev 1076, core/trunk/geoext/tests/lib/GeoExt/widgets/LegendImage.html)
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/LegendImage.html	                        (rev 0)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/LegendImage.html	2009-06-13 12:48:11 UTC (rev 1077)
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <script type="text/javascript" src="../../../../../openlayers/lib/OpenLayers.js"></script>
+    <script type="text/javascript" src="../../../../../ext/adapter/ext/ext-base.js"></script>
+    <script type="text/javascript" src="../../../../../ext/ext-all-debug.js"></script>
+    <script type="text/javascript" src="../../../../lib/GeoExt.js"></script>
+
+    <script type="text/javascript">
+
+        function test_constructor(t) {
+            t.plan(2);
+            
+            var legend;
+            
+            // create a legend with the default config
+            legend = new GeoExt.LegendImage();
+            t.eq(legend.defaultImgSrc, Ext.BLANK_IMAGE_URL, "defaultImgSrc defaults to Ext.BLANK_IMAGE_URL");
+            legend.destroy();
+            
+            // create a legend with a custom defaultImgSrc
+            legend = new GeoExt.LegendImage({defaultImgSrc: "foo"});
+            t.eq(legend.defaultImgSrc, "foo", "defaultImgSrc can be set in config");
+            legend.destroy();
+            
+        }
+        
+        function test_onImageLoadError(t) {
+            t.plan(2);
+            
+            var legend, calls = 0;
+
+            // create a legend with a bogus image url (one call to error handler)
+            legend = new GeoExt.LegendImage({
+                url: "bogus",
+                defaultImgSrc: "also-bogus",
+                renderTo: "legend",
+                onImageLoadError: function() {
+                    ++calls;
+                    GeoExt.LegendImage.prototype.onImageLoadError.apply(this, arguments);
+                }
+            });
+            t.delay_call(0.5, function() {
+                t.eq(calls, 1, "onImageLoadError called once for bogus image src");
+                var el = legend.getEl();
+                t.eq(el && el.dom.src.split("/").pop(), "also-bogus", "defaultImgSrc set as image src");
+                legend.destroy();
+            });            
+            
+        }
+
+
+    </script>
+  <body>
+    <div id="legend"></div>
+  </body>
+</html>

Modified: sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/tree/LayerContainer.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/tree/LayerContainer.html	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/tests/lib/GeoExt/widgets/tree/LayerContainer.html	2009-06-13 12:48:11 UTC (rev 1077)
@@ -54,9 +54,73 @@
             t.ok(node.firstChild.layer === layer, "child layer is correct");
 
             node.destroy();
+            //map.destroy();
             
         }
         
+        function test_order(t) {
+            
+            t.plan(16);
+            
+            var map = new OpenLayers.Map({
+                div: "map",
+                allOverlays: true
+            });
+            
+            var store = new GeoExt.data.LayerStore({
+                map: map
+            });
+            
+            var root = new GeoExt.tree.LayerContainer({
+                layerStore: store
+            });
+            
+            var panel = new Ext.tree.TreePanel({
+                renderTo: document.body,
+                root: root
+            });
+            
+            var a = new OpenLayers.Layer("a");
+            var b = new OpenLayers.Layer("b");
+            var c = new OpenLayers.Layer("c");
+            var d = new OpenLayers.Layer("d");
+            
+            var reader = new GeoExt.data.LayerReader();
+            
+            // add two records to empty root
+            store.add(reader.readRecords([a, b]).records);
+            t.eq(root.childNodes.length, 2, "[a, b] two records added");
+            t.eq(root.childNodes[0].layer.name, "b", "[a, b] last layer drawn at top of root");
+            t.eq(root.childNodes[1].layer.name, "a", "[a, b] first layer drawn at bottom of root");
+            
+            // add two records to root with two existing child nodes
+            store.add(reader.readRecords([c, d]).records);
+            t.eq(root.childNodes.length, 4, "[a, b, c, d] four records total");
+            t.eq(root.childNodes[0].layer.name, "d", "[a, b, c, d] last layer drawn at top of root");
+            t.eq(root.childNodes[1].layer.name, "c", "[a, b, c, d] third layer drawn at correct index");
+            t.eq(root.childNodes[2].layer.name, "b", "[a, b, c, d] second layer drawn at correct index");
+            t.eq(root.childNodes[3].layer.name, "a", "[a, b, c, d] first layer drawn at bottom of root");
+            
+            // remove the first two layers in draw order
+            store.remove(store.getAt(0));
+            store.remove(store.getAt(0));
+            t.eq(root.childNodes.length, 2, "[c, d] two records total");
+            t.eq(root.childNodes[0].layer.name, "d", "[c, d] last layer drawn at top of root");
+            t.eq(root.childNodes[1].layer.name, "c", "[c, d] first layer drawn at bottom of root");
+            
+            // insert two records in the middle
+            store.insert(1, reader.readRecords([a, b]).records);
+            t.eq(root.childNodes.length, 4, "[c, a, b, d] four records total");
+            t.eq(root.childNodes[0].layer.name, "d", "[c, a, b, d] last layer drawn at top of root");
+            t.eq(root.childNodes[1].layer.name, "b", "[c, a, b, d] third layer drawn at correct index");
+            t.eq(root.childNodes[2].layer.name, "a", "[c, a, b, d] second layer drawn at correct index");
+            t.eq(root.childNodes[3].layer.name, "c", "[c, a, b, d] first layer drawn at bottom of root");
+            
+            root.destroy();
+            //map.destroy();
+            
+        }
+        
         </script>
     </head>
     <body>

Modified: sandbox/camptocamp/geobretagne/tests/list-tests.html
===================================================================
--- sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-06-13 04:04:31 UTC (rev 1076)
+++ sandbox/camptocamp/geobretagne/tests/list-tests.html	2009-06-13 12:48:11 UTC (rev 1077)
@@ -18,6 +18,7 @@
   <li>lib/GeoExt/widgets/form/FormPanel.html</li>
   <li>lib/GeoExt/widgets/tree/LayerNode.html</li>
   <li>lib/GeoExt/widgets/tree/LayerContainer.html</li>
+  <li>lib/GeoExt/widgets/LegendImage.html</li>
   <li>lib/GeoExt/widgets/LegendPanel.html</li>
   <li>lib/GeoExt/widgets/grid/FeatureSelectionModel.html</li>
   <li>lib/GeoExt/widgets/ZoomSlider.html</li>



More information about the Commits mailing list