[Users] Problem appending layer to tree node
Robert Buckley
robertdbuckley at yahoo.com
Tue Jan 18 10:09:43 CET 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20110118/d731a4e6/attachment.htm
More information about the Users
mailing list