Ok so far I have been able to find a way to access the properties of nodes...now I am struggling to find out if there is anyway to access the properties of the node's leafs? If anyone know please help me, I think if I have that I will be able to carry out the desired task :)<br>
<br>Some code of my approach:<br><br>var i;<br> var j = 0;<br> var selectedLayers = new Array();<br> while(layerRoot.lastChild.hasChildNodes()){<br>
alert(layerRoot.lastChild.firstChild.childNodes.length); //This returns 0, but the childNodes here are leafs :(<br> for(i = 0; i < layerRoot.lastChild.firstChild.childNodes.length; i++){<br>
if(layerRoot.lastChild.firstChild.childNodes[i].isSelected()){<br> selectedLayers[j] = layerRoot.lastChild.firstChild.childNodes[i].attributes.text;<br>
alert(selectedLayers[j]);<br> j++;<br> } <br> }<br> <br>
layerRoot.lastChild.removeChild(layerRoot.lastChild.firstChild);<br> }<br> layerRoot.removeChild(layerRoot.lastChild); <br> }<br>
<br>Thanks for taking the time to consider my questions,<br><br>elshae<br><br><div class="gmail_quote">On Tue, Oct 19, 2010 at 4:17 PM, IT Intern <span dir="ltr"><<a href="mailto:itintern12@gmail.com">itintern12@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hello GeoExt Friends,<br><br>So I have been using the GeoExt and Ext libraries to develop my map browser and now there's a feature I'd like to have, but don't know how to go about it :)<br>
<br>So far everything is working. What I have is a tree panel that when a menu is clicked a parent node with layer containers is added to the tree. The layers in these containers are in different languages, so as the user toggles between the languages in the menu, it be nice if the layers in the previous language correspond to the language that is currently selected. I hope you will understand what I am asking to do. I guess a good starting point would be, is there a way to "get" which layers are selected in a layer container? Thanks for your time, below is some relevant code:<br>
<br>//So there are many layers, one each per language...<br><br>var chn_townships = new OpenLayers.Layer.WMS(<br> "Townships (Chinese trans)", "<a href="http://localhost:8080/geoserver/wms" target="_blank">http://localhost:8080/geoserver/wms</a>", {layers: 'cite:chn_townships', transparent: true}, {isBaseLayer: false, displayInLayerSwitcher: true, visibility: false}<br>
);<br> <br> var tib_townships = new OpenLayers.Layer.WMS(<br> "Townships (Tibetan trans)", "<a href="http://localhost:8080/geoserver/wms" target="_blank">http://localhost:8080/geoserver/wms</a>", {layers: 'cite:tib_townships', transparent: true}, {isBaseLayer: false, displayInLayerSwitcher: true, visibility: true} <br>
); <br><br>//The layers are stored in layer stores...<br>var tibLands = new GeoExt.data.LayerStore({<br> map: map,<br> initDir: 0,<br> layers: [tib_villages, tib_townships, tib_farms, tib_countys]<br>
});<br><br> var chnLands = new GeoExt.data.LayerStore({<br> map: map,<br> initDir: 0,<br> layers: [chn_villages, chn_townships, chn_farms, chn_countys]<br>
});<br><br>//Menu for users to select language<br>var languageMenu = new Ext.menu.Menu({<br> id: 'mainMenu',<br> style: {<br> overflow: 'visible' // For the Combo popup<br>
},<br> items: [<br> // A Field in a Menu<br> {<br> text: 'Chinese',<br> checked: false,<br> group: 'theme',<br>
icon: './gif/cn.gif',<br> handler: checkHandler<br> },{<br> text: 'English',<br> checked: true,<br>
group: 'theme',<br> handler: checkHandler<br> },{<br> text: 'Tibetan',<br> checked: false,<br>
group: 'theme',<br> handler: checkHandler<br> }<br> ]<br> });<br><br>//The handler function that listens to the users selection on the menu (This is where I want the magic to happen ;)<br>
function checkHandler(item, checked) {<br> var tibetContainer, chineseContainer;<br> <br> if(item.text == 'Tibetan'){<br> if(<a href="http://layerRoot.lastChild.id" target="_blank">layerRoot.lastChild.id</a> == 'chinese'){<br>
layerRoot.removeChild(layerRoot.lastChild); <br> }<br> <br> tibetContainer = new Ext.tree.TreeNode({<br> text: "Tibetan Labels",<br>
expanded: true,<br> id: 'tibet'<br> });<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br>
text: "Lands (Tibetan trans)",<br> layerStore: tibLands,<br> expanded: false,<br> loader: {param: "LAYERS"}<br>
}));<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br> text: "Natural Selection (Tibetan trans)",<br> layerStore: tibNaturalLayers,<br>
expanded: false,<br> loader: {param: "LAYERS"}<br> }));<br><br> tibetContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br>
text: "Points of Interest (Tibetan trans)",<br> layerStore: tibPointOfInterest,<br> expanded: false,<br> loader: {param: "LAYERS"}<br>
}));<br><br> layerRoot.appendChild(tibetContainer);<br><br> }<br> else if(item.text == 'Chinese'){<br> <br>
chineseContainer = new Ext.tree.TreeNode({<br> text: "Chinese Labels",<br> expanded: true,<br> id: 'chinese'<br>
});<br><br> chineseContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br> text: "Lands (Chinese trans)",<br> layerStore: chnLands,<br>
expanded: false,<br> loader: {param: "LAYERS"}<br> }));<br><br> chineseContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br>
text: "Natural Selection (Chinese trans)",<br> layerStore: chnNaturalLayers,<br> expanded: false,<br> loader: {param: "LAYERS"}<br>
}));<br><br> chineseContainer.appendChild(new GeoExt.tree.OverlayLayerContainer({<br> text: "Points of Interest (Chinese trans)",<br> layerStore: chnPointOfInterest,<br>
expanded: false,<br> loader: {param: "LAYERS"}<br> }));<br><br> if(<a href="http://layerRoot.lastChild.id" target="_blank">layerRoot.lastChild.id</a> == 'tibet'){<br>
//layerRoot.removeChild(layerRoot.lastChild); <br> layerRoot.replaceChild(chineseContainer, layerRoot.lastChild) //thought this might have done it, this just replaces the nodes but not the layers selected to the new ones :(<br>
}else<br> {layerRoot.appendChild(chineseContainer);}<br><br> }<br>
</blockquote></div><br>