[Users] How to find layer record from layer node ?

Alexandre Dube adube at mapgears.com
Wed Mar 24 16:15:39 CET 2010


Tim,

  Someone on the Ext irc channel proposed using the following 
user-custom method instead :

    /**
     * Returns all records that absolutely match the field value. Ext's query
     * function uses a regular expression instead, which is just a terrible
     * idea.
     * @param field {String} The field to check
     * @param val The value to match
     * @return A set of the matching records
     */
    realQuery: function(field, val) {
        return this.queryBy(function(rec) {
            return rec.get(field) === val;
        });
    },

Since it's not an official Ext method, I would put it in the LayerStore class.  What do you think ?

Alexandre


Alexandre Dube wrote:
> 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