[Users] How to find layer record from layer node ?
Alexandre Dube
adube at mapgears.com
Wed Mar 24 14:00:44 CET 2010
Tim,
Tim Schaub wrote:
> In these cases, I think it is easiest to think of the layer store
> referenced by the MapPanel as the primary store. The the map is a view
> of the records in this store. The tree (in this case) can also be
> treated as a view. A grid could be another view. To keep things
> simple, don't call methods on the views.
>
> Tim
>
That's perfectly clear. The below line is working well and, as you
mentioned, it removed the layer from all views :
node.layerStore.remove(node.layerStore.getAt(1));
One last question on the matter though : it's about how I can get the
index of the record I'm looking for. In OpenLayers, since the layers are
stored into an array, using OpenLayers.indexOf does the trick, but is
there something similar in Ext or GeoExt ? Is there a "find record by
value" method ?
Here's how I would do it : create a method for the Store object that
creates an array with values of a specific attribute. The result would
be similar to the layers array in OpenLayers, so from then we would
simply need to use indexOf. What do you think ?
Ext.data.Store.prototype.getValueArray = function(attribute) {
var values = [];
var nValues = this.getCount();
for(var i=0; i<nValues; i++) {
values.push(this.getAt(i).get(attribute));
}
return values;
};
var layers = node.layerStore.getValueArray('layer');
var index = OpenLayers.Util.indexOf(layers, node.layer);
if(index == -1) {
node.layerStore.remove(node.layerStore.getAt(index));
}
Regards,
--
Alexandre Dubé
Mapgears
www.mapgears.com
More information about the Users
mailing list