[Users] Keeping Selected Layers When Replacing Child Nodes
IT Intern
itintern12 at gmail.com
Tue Oct 19 22:17:17 CEST 2010
Hello GeoExt Friends,
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 :)
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:
//So there are many layers, one each per language...
var chn_townships = new OpenLayers.Layer.WMS(
"Townships (Chinese trans)", "
http://localhost:8080/geoserver/wms", {layers: 'cite:chn_townships',
transparent: true}, {isBaseLayer: false, displayInLayerSwitcher: true,
visibility: false}
);
var tib_townships = new OpenLayers.Layer.WMS(
"Townships (Tibetan trans)", "
http://localhost:8080/geoserver/wms", {layers: 'cite:tib_townships',
transparent: true}, {isBaseLayer: false, displayInLayerSwitcher: true,
visibility: true}
);
//The layers are stored in layer stores...
var tibLands = new GeoExt.data.LayerStore({
map: map,
initDir: 0,
layers: [tib_villages, tib_townships, tib_farms,
tib_countys]
});
var chnLands = new GeoExt.data.LayerStore({
map: map,
initDir: 0,
layers: [chn_villages, chn_townships, chn_farms,
chn_countys]
});
//Menu for users to select language
var languageMenu = new Ext.menu.Menu({
id: 'mainMenu',
style: {
overflow: 'visible' // For the Combo popup
},
items: [
// A Field in a Menu
{
text: 'Chinese',
checked: false,
group: 'theme',
icon: './gif/cn.gif',
handler: checkHandler
},{
text: 'English',
checked: true,
group: 'theme',
handler: checkHandler
},{
text: 'Tibetan',
checked: false,
group: 'theme',
handler: checkHandler
}
]
});
//The handler function that listens to the users selection on the menu (This
is where I want the magic to happen ;)
function checkHandler(item, checked) {
var tibetContainer, chineseContainer;
if(item.text == 'Tibetan'){
if(layerRoot.lastChild.id == 'chinese'){
layerRoot.removeChild(layerRoot.lastChild);
}
tibetContainer = new Ext.tree.TreeNode({
text: "Tibetan Labels",
expanded: true,
id: 'tibet'
});
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Lands (Tibetan trans)",
layerStore: tibLands,
expanded: false,
loader: {param: "LAYERS"}
}));
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Natural Selection (Tibetan trans)",
layerStore: tibNaturalLayers,
expanded: false,
loader: {param: "LAYERS"}
}));
tibetContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Points of Interest (Tibetan trans)",
layerStore: tibPointOfInterest,
expanded: false,
loader: {param: "LAYERS"}
}));
layerRoot.appendChild(tibetContainer);
}
else if(item.text == 'Chinese'){
chineseContainer = new Ext.tree.TreeNode({
text: "Chinese Labels",
expanded: true,
id: 'chinese'
});
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Lands (Chinese trans)",
layerStore: chnLands,
expanded: false,
loader: {param: "LAYERS"}
}));
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Natural Selection (Chinese trans)",
layerStore: chnNaturalLayers,
expanded: false,
loader: {param: "LAYERS"}
}));
chineseContainer.appendChild(new
GeoExt.tree.OverlayLayerContainer({
text: "Points of Interest (Chinese trans)",
layerStore: chnPointOfInterest,
expanded: false,
loader: {param: "LAYERS"}
}));
if(layerRoot.lastChild.id == 'tibet'){
//layerRoot.removeChild(layerRoot.lastChild);
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 :(
}else
{layerRoot.appendChild(chineseContainer);}
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.geoext.org/pipermail/users/attachments/20101019/839653a8/attachment.htm
More information about the Users
mailing list