[Commits] r2720 - in sandbox/gxm/geoext/gxm: examples lib tests/lib

commits at geoext.org commits at geoext.org
Tue May 24 16:48:55 CEST 2011


Author: marcjansen
Date: 2011-05-24 16:48:55 +0200 (Tue, 24 May 2011)
New Revision: 2720

Modified:
   sandbox/gxm/geoext/gxm/examples/buttons.js
   sandbox/gxm/geoext/gxm/lib/Button.js
   sandbox/gxm/geoext/gxm/lib/MapPanel.js
   sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html
Log:
  - tests

Modified: sandbox/gxm/geoext/gxm/examples/buttons.js
===================================================================
--- sandbox/gxm/geoext/gxm/examples/buttons.js	2011-05-24 08:05:52 UTC (rev 2719)
+++ sandbox/gxm/geoext/gxm/examples/buttons.js	2011-05-24 14:48:55 UTC (rev 2720)
@@ -31,7 +31,7 @@
         
         var zoomin = new OpenLayers.Control.ZoomIn();
         var zoomout = new OpenLayers.Control.ZoomOut();
-        
+        alert(map.id)
         var btnZoomIn = new GXM.Button({
             control: zoomin,
             map: map,

Modified: sandbox/gxm/geoext/gxm/lib/Button.js
===================================================================
--- sandbox/gxm/geoext/gxm/lib/Button.js	2011-05-24 08:05:52 UTC (rev 2719)
+++ sandbox/gxm/geoext/gxm/lib/Button.js	2011-05-24 14:48:55 UTC (rev 2720)
@@ -6,66 +6,27 @@
  * of the license.
  */
 
-/** api: (define)
- *  module = GeoExt
- *  class = Action
- *  base_link = `Ext.Action <http://dev.sencha.com/deploy/dev/docs/?class=Ext.Action>`_
- */
-
-/** api: example
- *  Sample code to create a toolbar with an OpenLayers control into it.
- * 
- *  .. code-block:: javascript
- *  
- *      var action = new GeoExt.Action({
- *          text: "max extent",
- *          control: new OpenLayers.Control.ZoomToMaxExtent(),
- *          map: map
- *      });
- *      var toolbar = new Ext.Toolbar([action]);
- */
-
-/** api: constructor
- *  .. class:: Action(config)
- *  
- *      Create a GeoExt.Action instance. A GeoExt.Action is created
- *      to insert an OpenLayers control in a toolbar as a button or
- *      in a menu as a menu item. A GeoExt.Action instance can be
- *      used like a regular Ext.Action, look at the Ext.Action API
- *      doc for more detail.
- */
-
-// toggle button via seg,mented button und allowDerpress
-
-// je nach OpenLayers.Control.TYPE_TOOL => segmented button
-
-// abstrakte wrapper klasse von component, die den TYPE der control überprüft
-// und entweder button / segmentedbutton zurückgibt
-
-//  button / segmentedbutton eventuell nochmal ableiten als gxm_singlebutton / gxm_togglebutton
-
 Ext.ns('GXM');
 
-// usually a Ext.ComponentQuery.query('gxm_button[exclusiveGroup="humpty"]') 
-// would be enough, but it seems as if we currently hav a bug in sencha:
-// http://www.sencha.com/forum/showthread.php?120633-Ext.ComponentQuery.query()-not-working
-GXM.buttonManager = new Ext.AbstractManager();
-
-
-
-
-
 GXM.Button = Ext.extend(Ext.Button, {
     exclusiveGroup:null,
     map: null,
+    mappanel: null,
     uScope: null,
     uHandler: null,
+    control:null,
     initComponent : function(){
         GXM.Button.superclass.initComponent.call(this);
         
         // register button for de/activating in exclusiveGroups
-        GXM.buttonManager.register(this);
+        GXM.Button.manager.register(this);
         
+        if (!this.map && this.mapPanel && this.mapPanel.map) {
+            this.map = this.mapPanel.map;  
+        } else if (!this.map && this.control && this.control.map) {
+            this.map = this.control.map;  
+        }
+        
         // store the user scope and handlers
         this.uScope = this.scope;
         this.uHandler = this.handler;
@@ -112,7 +73,7 @@
         var members = [];
         var myGroup = this.exclusiveGroup;
         if (myGroup) {
-            GXM.buttonManager.each(function(id, btn) {
+            GXM.Button.manager.each(function(id, btn) {
                 if(btn.exclusiveGroup === myGroup) {
                     members.push(btn);
                 }
@@ -140,4 +101,9 @@
     onCtrlDeactivate: function(){
     }
 });
-Ext.reg('gxm_button', GXM.Button);
\ No newline at end of file
+Ext.reg('gxm_button', GXM.Button);
+
+// usually a Ext.ComponentQuery.query('gxm_button[exclusiveGroup="humpty"]') 
+// would be enough, but it seems as if we currently hav a bug in sencha:
+// http://www.sencha.com/forum/showthread.php?120633-Ext.ComponentQuery.query()-not-working
+GXM.Button.manager = new Ext.AbstractManager();
\ No newline at end of file

Modified: sandbox/gxm/geoext/gxm/lib/MapPanel.js
===================================================================
--- sandbox/gxm/geoext/gxm/lib/MapPanel.js	2011-05-24 08:05:52 UTC (rev 2719)
+++ sandbox/gxm/geoext/gxm/lib/MapPanel.js	2011-05-24 14:48:55 UTC (rev 2720)
@@ -15,8 +15,8 @@
         ];   
     },
     initComponent: function(){
-        GXM.MapPanel.superclass.initComponent.call(this);
         
+        
         // check config-property map for an existing OpenLayers.Map-instance, a
         // conf object for an OpenLayers.Map or null
         if ( !(this.map instanceof OpenLayers.Map) ) {
@@ -29,6 +29,8 @@
         }
         // this.map is now initialized in any case
         
+        
+        
         // check config-property layers for any layers to be added to the map
         if ( this.layers ) {
             // normalize the case where this.layers was not an array but a layer 
@@ -69,7 +71,7 @@
         } else if(Ext.isArray(this.extent)) {
             this.extent = OpenLayers.Bounds.fromArray(this.extent);
         }
-        
+        GXM.MapPanel.superclass.initComponent.call(this);
         // events
         this.addEvents(
             /** private: event[aftermapmove]

Modified: sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html
===================================================================
--- sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html	2011-05-24 08:05:52 UTC (rev 2719)
+++ sandbox/gxm/geoext/gxm/tests/lib/MapPanel.test.html	2011-05-24 14:48:55 UTC (rev 2720)
@@ -39,12 +39,10 @@
     return mappanel;
 }
 
-function getLazyMapPanel() {
-    var map = getMap();
-    var mappanel = {
-        xtype: 'gxm_mappanel',
-        map: map  
-    };
+function getLazyMapPanel(opts) {
+    var options = Ext.apply(opts || {}, { xtype: 'gxm_mappanel' });
+    options.map = ( opts && opts.map ) ? opts.map : getMap();
+    var mappanel = options;
     
     var panel = new Ext.Panel({
         fullscreen: true,
@@ -305,6 +303,121 @@
     t.ok(map instanceof OpenLayers.Map, 'map is still a OpenLayers.Map-instance after the panel has been destroyed.');
 }
 
+function test_render(t) {
+    var map = getMap();
+    
+    
+    var renderCalled = false;
+    map.render = function() {
+        renderCalled = true;
+        OpenLayers.Map.prototype.render.apply(this, arguments);
+    };
+    var mappanel = getMapPanel({
+        map: map,
+        layers: [
+            map.layers[0].clone(),
+            map.layers[0].clone(),
+            map.layers[0].clone()
+        ]
+    });
+    
+    //
+    // when the map is rendered, we should find elements with the following 
+    // classes:
+    // 
+    //  CSS-class        | # | element | comment     
+    // ------------------+---+---------+----------------------------------
+    //  .olMap           | 1 | div     | exactly one
+    //  .olMapViewPort   | 1 | div     | exactly one
+    //  .olLayerDiv      | 1 | div     | exactly one per layer in the map
+    // 
+    var expectedElems = [
+        {
+            tag: 'div',
+            cssClass: 'olMap',
+            expectedNum: 1
+        },
+        {
+            tag: 'div',
+            cssClass: 'olMapViewport',
+            expectedNum: 1
+        },
+        {
+            tag: 'div',
+            cssClass: 'olLayerDiv',
+            expectedNum: 1 * mappanel.map.layers.length
+        }
+    ];
+    
+    t.plan(1 + expectedElems.length);
+    
+    t.ok(renderCalled, 'the maps render method gets called');
+    
+    var result;
+    Ext.each(expectedElems, function(expectedElem) {
+        result = Ext.DomQuery.select(expectedElem.tag + '.' + expectedElem.cssClass);
+        t.eq(result.length, expectedElem.expectedNum, 'We found "' + expectedElem.tag + '.' + expectedElem.cssClass + '" exactly ' + expectedElem.expectedNum + ' times.');
+    });
+    
+    mappanel.destroy();
+    map.destroy();
+}
+
+// we always should have an instance of layerstore in mappanel.layers
+function test_MapManelsLayerStore(t){
+    // get a cloneable layer
+    var map = getMap();
+    var layer = map.layers[0].clone();
+    // cleanup
+    map.destroy(); 
+
+    var map1 = getMap();
+    var map2 = getMap();
+    // the "desc"-property is used only for test output
+    var mappanels = [
+        getMapPanel({desc:'instanciation plain'}),
+        getMapPanel({map:map1, desc:'instanciation w/ map'}),
+        getLazyMapPanel({desc:'lazy plain'}),
+        getLazyMapPanel({map:map2, desc:'lazy w/ map'}),
+        // the following are all adding a layer
+        // adding an additional layer
+        getMapPanel({layers:[layer.clone()], desc:'instanciation plain w/ layers'}),
+        getMapPanel({map:map1, layers:[layer.clone()], desc:'instanciation w/ map and w/ layers'}), 
+        getLazyMapPanel({layers:[layer.clone()], desc:'lazy plain w/ layers'}), 
+        getLazyMapPanel({map:map2, layers:[layer.clone()], desc:'lazy w/ map and w/layers'}) 
+    ];
+    t.plan(4 * mappanels.length);
+    var isStoreInstance = false;
+    Ext.each(mappanels, function(mappanel) {
+        isStoreInstance = mappanel.layers instanceof GXM.data.LayerStore;
+        t.ok(mappanel.layers instanceof GXM.data.LayerStore, "Mappanel (" + mappanel.desc + "): layers property is instance of GXM.data.LayerStore.");
+        if (isStoreInstance){
+            // check the modelname:
+            t.eq(mappanel.layers.model.modelName, 'gxm_Layer', 
+                '...the store has the right modelName "gxm_Layer" bound.');
+            // check the field "layer"
+            var firstRec = mappanel.layers.first();
+            // is it an OpenLayers Layer?
+            t.ok(firstRec.get('layer') instanceof OpenLayers.Layer, 
+                '...the first record has an attribute layer that is an OpenLayers.Layer-instance.');
+            // is it the correct one?
+            t.eq(firstRec.get('layer').id, mappanel.map.layers[0].id, 
+                '...that records layer-field has the correct layer reference (id="' + firstRec.get('layer').id + '").');
+        } else {
+            t.fail("mappanel.layers wasn't an instance of GXM.data.LayerStore, fail this test.");
+            t.fail("mappanel.layers wasn't an instance of GXM.data.LayerStore, fail this test.");
+            t.fail("mappanel.layers wasn't an instance of GXM.data.LayerStore, fail this test.");
+        }
+    });
+    // iterate again to cleanup
+    Ext.each(mappanels, function(mappanel){
+        mappanel.destroy();
+    });
+    // cleanup
+    map1.destroy();
+    map2.destroy();
+}
+
         </script>
     </head>
     <body></body>



More information about the Commits mailing list