[Users] Problem appending layer to tree node
Andreas Hocevar
ahocevar at opengeo.org
Tue Jan 18 10:46:59 CET 2011
It is a common misunderstanding that a TreePanel for representing the layers of the map should use several layer stores in order to work with several folders.
The correct approach is to reference the mapPanel's layers property (which is a LayerStore), and configure the containers of each folder with appropriate filters (using the filter property of the LayerLoader).
Regards,
Andreas.
On Jan 18, 2011, at 10:09 , Robert Buckley 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 every root.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ügen",
> tooltip : 'Layer hinzufü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
--
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.
More information about the Users
mailing list