[Users] Problem appending layer to tree node

IT Intern itintern12 at gmail.com
Tue Jan 18 16:06:27 CET 2011


I know you can use a loader with a filter to specify which layer you do not
want to append to a container

new GeoExt.tree.OverlayLayerContainer({
            text: text,
            layerStore: layerStore,
            expanded: true,
            iconCls: iconCls,  //If not specified, defaults to original
image
            loader:{
                filter: function(record) {
                    //return record.get("layer").name.indexOf("Tasmania")
!== -1 This code means attach any layers with "Tasmania" in their name,
notice the the (!== -1)
                    return record.get("layer").name.indexOf("Photos") == -1
&& record.get("layer").name.indexOf("OpenLayers.Handler.Polygon") == -1 &&
record.get("layer").name.indexOf("OpenLayers.Handler.Path") == -1; This code
means do NOT take any layers with "Photos", "OpenLayers.Handler.Polygon", or
"OpenLayers.Handler.Path" in their name notice the (== -1)
                }
            }
        })


Hope this help you somehow

Happy Mapping,

elshae


On Tue, Jan 18, 2011 at 4:09 AM, Robert Buckley <robertdbuckley at yahoo.com>wrote:

> Hi,
>
> I have defined a treepanel which has child elements which work as data
> folders for wms layers....
> I have added a grid which lists the other layers on my server (from the
> getcapabilities doc) and adds them to the map .
>
> I have successfully achieved this, but am having the problem that the newly
> added layers from the window are being assigned to each and everyroot.child.
>
> To solve this, I would like to add the layers from the gecapabilities doc
> grid to a new root.child called "MyLayers".
>
> My logic is this.....II need to then write code to firstly check if the
> root.child with an id" MyLayers" exists, and if not... create it, and then
> add any layers to this child.
>
> Is this possible? and how?
>
>
> My Code...
>
> // Layer root container
>
>     var layerRoot = new Ext.tree.TreeNode({
>           text: "Karteninhalt",
>           expanded:false
>
>         });
>
> // These are the content layer stores
>
> // Baselayers
>     var layerListBase = new GeoExt.tree.BaseLayerContainer({
>           text: "<span class='TreeHeader'>Hintergrundkarten</span>",
>           map: map,
>           expanded: false
>
>     });
>
> // Layer Stores - Nachrichtlich
>     var nachrichtlich_store = new GeoExt.data.LayerStore({
>         text: "Grenzen",
>         map:map,
>         initDir: 0,
>         layers:[Grenzen]
>     });
>
>     // Layer Stores - WIND
>     var wea_store = new GeoExt.data.LayerStore({
>         text: "Windenergie",
>         map:map,
>         initDir: 0,
>         layers:[layer_windpotential,layer_wea_f,layer_wea]
>     });
>
> // the tree is made here
>
> layerRoot.appendChild(layerListBase);
>
>     layerRoot.appendChild(new GeoExt.tree.OverlayLayerContainer({
>         text: "<span class='TreeHeader'>Nachrichtlich</span>",
>         layerStore: nachrichtlich_store,
>         expanded: false
>         })
>     );
>
>     layerRoot.appendChild(new GeoExt.tree.OverlayLayerContainer({
>         text: "<span class='TreeHeader'>Windenergie</span>",
>         layerStore: wea_store,
>         expanded: false
>         })
>     );
>
>
> ...the extract from the button in the grid which adds the layers from the
> getcapabilities doc...
>
> bbar: [new Ext.Button({
>                  text: "Layer hinzuf&uuml;gen",
>                  tooltip : 'Layer hinzuf&uuml;gen',
>                  handler: function() {
>
>                 // select layer from grid
>
> capabilitiesgrid.getSelectionModel().each(function(record) {
>                      var clone = record.clone();
>                      clone.get("layer").mergeNewParams({
>                         format: "image/png",
>                          transparent: true
>                      });
>
>             // add layer to map
>             mapPanel.layers.add(clone);
>
>             if(node) {
>             var node = tree.getNodeById('MyLayers');
>             tree.node.add(node,clone);
>
>             }
>
>                 //  zoom to nely added layer
>         var bounds = new OpenLayers.Bounds.fromArray(clone.get("llbbox"))
>         bounds.transform(epsg4326, map.getProjectionObject());
>         map.zoomToExtent(bounds)
>
>
>             });
>         }
>         })
>         ,
>
>
> Thanks for any help,
>
>
> Robert
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at geoext.org
> http://www.geoext.org/cgi-bin/mailman/listinfo/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110118/b0213806/attachment.htm 


More information about the Users mailing list