Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: layer items of a LayerTree do not support children anymore #213

Open
Skrol29 opened this issue Nov 14, 2013 · 5 comments
Open

Bug: layer items of a LayerTree do not support children anymore #213

Skrol29 opened this issue Nov 14, 2013 · 5 comments

Comments

@Skrol29
Copy link

Skrol29 commented Nov 14, 2013

It seems to be a regression between version "pre-2.0" and "2.0.0".
In GeoExt "pre-2.0" items of a LayerTree can have both a layer and children.
In GeoExt "2.0.0" children are deleted when the item have a layer.

This bug seems related to issue #212 in that the code of "LayerNode.js" available in "pre-2.0" seems to be abandoned in "2.0.0".

The patch below worked for my application and solved both issues #212 and this current one. It just consists in applying a snippet of "pre-2.0" on "2.0.0".

diff --git "a/src\\GeoExt\\tree\\LayerNode.js" "b/src\\GeoExt\\tree\\LayerNode.js"
index cad9e0c..354f9a7 100644
--- "a/src\\GeoExt\\tree\\LayerNode.js"
+++ "b/src\\GeoExt\\tree\\LayerNode.js"
@@ -36,25 +36,49 @@ Ext.define('GeoExt.tree.LayerNode', {
     init: function(target) {

         this.target = target;
-        var layer = target.get('layer');
-
-        target.set('checked', layer.getVisibility());
-        if (!target.get('checkedGroup') && layer.isBaseLayer) {
-            target.set('checkedGroup', 'gx_baselayer');
+        this.layer  = target.get('layer') instanceof OpenLayers.Layer && target.get('layer');
+       
+        if ( !this.layer ) {
+            // guess the store if not provided
+            if ( !this.layerStore || this.layerStore == "auto") {
+                this.layerStore = GeoExt.panel.Map.guess().layers;
+            }
+            
+            // now we try to find the layer by its name in the layer store
+            var i = this.layerStore.findBy(function(o) {
+                return o.get("title") == this.target.get('layer');
+            }, this);
+            if ( i != -1 ) {
+                // if we found the layer, we can assign it and everything
+                // will be fine
+                this.layer = this.layerStore.getAt(i).getLayer();
+                
+                target.set('layer', this.layer); 
+            }
         }
-        target.set('fixedText', !!target.text);
-
-        target.set('leaf', true);
+        
+       if ( this.layer ) {
+            target.set('checked', this.layer .getVisibility());
+            if (!target.get('checkedGroup') && this.layer.isBaseLayer) {
+                target.set('checkedGroup', 'gx_baselayer');
+           }
+            target.set('fixedText', !!target.text);
+            
+            if ( !target.childNodes.length )
+                target.set('leaf', true);
+            
+            if(!target.get('iconCls')) {
+                target.set('iconCls', "gx-tree-layer-icon");
+            }
+            
+            target.on('afteredit', this.onAfterEdit, this);
+            this.layer.events.on({
+                "visibilitychanged": this.onLayerVisibilityChanged,
+                scope: this
+            });

-        if(!target.get('iconCls')) {
-            target.set('iconCls', "gx-tree-layer-icon");
-        }
+       }

-        target.on('afteredit', this.onAfterEdit, this);
-        layer.events.on({
-            "visibilitychanged": this.onLayerVisibilityChanged,
-            scope: this
-        });
     },

     /**
@marcjansen
Copy link
Member

Looks cool at first sight @Skrol29, thanks.

Can you turn this into a pull request? Please add at least two tests if so, and also send in a contributor agreement.

If you cannot turn this into a PR, let me know, I will take of this then.

@bartvde
Copy link
Member

bartvde commented Nov 15, 2013

@marcjansen I don't think we should go reverting this code without checking why. There must have been good reasons for @ahocevar to change this? Not sure of this is the only changeset involved though:

46918c3

@marcjansen
Copy link
Member

He @bartvde, this is why I wrote "at first sight". I wasn't thinking of blindly merging this.

It'd be extra nice if @ahocevar or @juliensam would give us some inside-knowledge about this change, though.

@Skrol29
Copy link
Author

Skrol29 commented Nov 18, 2013

@marcjansen The patch is currently being tested in our application and all is ok so far.

Can the contributor agreement be sent by email, or the postal way is mandatory ?

@marcjansen
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants