I'm setting up a small web mapping application using PostGIS + mod_tile + FeatureServer + OpenLayers + GeoExt, each of which I'm learning as I go. In addition to the base layer, I've pulled in a few vector layers from FeatureServer, each with many features. For example, a request to my "states" layers returns a GeoJSON feature for each state, and "Congressional districts" returns a feature for each Congressional District. I can render these layers to the map and toggle them in their entirety in a GeoEXT layer tree.
What I'd like to do (seems) straightforward: For each layer, display a grouped list of all features in a layer tree with checkboxes to toggle the visibility/rendering of each feature, individually. I'm struggling to find a straightforward way to do this.
There was a question on the GeoEXT mailing list that included code to set the renderIntent to 'delete' on uncheck:
var layerList = new GeoExt.tree.LayerNode({
text: 'The United States',
expanded: true,
layer: usa, // refers to a vector layer using HTTP protocol to get GeoJSON.
leaf: false,
children : [{
text: "Alabama",
leaf: true,
fid:1,
checked: false
},{
text: "Alaska",
leaf: true,
fid:2,
checked: false
}, {
//... load other fifty states
}]
});
var layerTree = new Ext.tree.TreePanel({
title: 'Map Layers',
root: layerList,
autoScroll:true,
listeners: {
'checkchange': function(node, checked){
var tempfid = node.attributes.fid;
if(checked){
node.parentNode.attributes.layer.getFeatureByFid(tempfid).renderIntent = 'default';
// I am setting visibility with renderIntent because styles are reset when layer is redrawn form panning or zooming.
node.parentNode.attributes.layer.redraw();
}else{
node.parentNode.attributes.layer.getFeatureByFid(tempfid).renderIntent = 'delete';
node.parentNode.attributes.layer.redraw();
}
}
}
});
I'm thinking there's a better way to do this (perhaps with Strategy.Filter?), but can't seem to wrap my head around it. Could someone point me in the right direction and/or to some examples that include this functionality? Thanks in advance for your help!