Hello,

I havent been able to make the filter work when using the addFeatures method
of the vector layer. So my ugly solution is to filter manually :(

    // Only display features with lat=15
    function FilterAisFeatures()
    {
        var outputFeaturesAis = [];
        var i=0;
        for (i=0; i<featuresAis.length; i++){
            if (featuresAis[i].attributes.lat==15){
                outputFeaturesAis.push(featuresAis[i]);
            }
        }
        aisDetections.removeFeatures(aisDetections.features);
        aisDetections.addFeatures(outputFeaturesAis);
    }

Thank you!

2010/9/29 Joaquín Rodríguez-Guerra Urcelay <[email protected]>

> Thank you for your answers! this filter strategy is exactly what I am
> looking for, but I just cant make it work.
>
> In the example the vector layer is built using the protocol attribute, like
> in the example I had seen before where they put the filter just in the
> filter property of the vector layer (which didnt work for me neither)
> But in my case I need to build the vector layer like this, using an array
> of features.
>
>      // CREATE DETECTIONS LAYER
>     var styleAllDetections = { styleMap: new OpenLayers.StyleMap(
> {"default": {graphicName: "circle"} } ) };
>
>     allDetections = new OpenLayers.Layer.Vector("Detections",
> styleAllDetections);
>     var featuresAll = [];
>
>     <!-- FILL VECTOR LAYER WITH THE ITEMS OF THE DETECCTIONS LIST -->
>     <logic:iterate name="product" property="detections" id="item">
>     featuresAll.push(new OpenLayers.Feature.Vector(new
> OpenLayers.Geometry.Point(<bean:write name="item" property="lon"/>,
> <bean:write name="item" property="lat"/>),
>                                                     { id: <bean:write
> name="item" property="id"/>,
>                                                       lat: <bean:write
> name="item" property="lat"/>,
>                                                       lon: <bean:write
> name="item" property="lon"/>,
>                                                       confidence:
> <bean:write name="item" property="confidence"/
>                                                     } ) );
>     </logic:iterate>
>
>     allDetections.addFeatures(featuresAll);
>     map.addLayer(allDetections);
>
> And maybe I am not accessing correctly to the property to filter. This is
> what I tried:
>
>     var filter, filterStrategy;
>     filter=new
> OpenLayers.Filter.Comparison({type:OpenLayers.Filter.Comparison.EQUAL_TO,property:
> "lat",value: 55});
>     filterStrategy = new OpenLayers.Strategy.Filter({filter: filter});
>
>
>     var styleAllDetections = { strategies: [new
> OpenLayers.Strategy.Fixed(), filterStrategy], styleMap: new
> OpenLayers.StyleMap( {"default": {graphicName: "circle"} } ) };
>
>     allDetections = new OpenLayers.Layer.Vector("Detections",
> styleAllDetections);
>
> But all the features are displayed on the map. Has anyone try to filter in
> vector layer where features where pushed in an array? Does any one have any
> idea of how I can solve this??
>
> Thanks!!
>
> 2010/9/28 Andreas Hocevar <[email protected]>
>
> Hi,
>>
>> you may want to have a look at the new Filter strategy:
>>
>>
>> http://dev.openlayers.org/releases/OpenLayers-2.10/doc/apidocs/files/OpenLayers/Strategy/Filter-js.html
>>
>> This requires OpenLayers >= 2.10.
>>
>> Regards,
>> Andreas.
>>
>> On Sep 28, 2010, at 10:58 , Joaquín Rodríguez-Guerra Urcelay wrote:
>>
>> > Hello list!
>> >
>> > I am trying to filter the features in a vector layer so I can decide
>> which of them are displayed on the map and which are not. I have succesfully
>> created the vector layer allDetections with the code below, and I can see
>> all the detections in openlayers. But I cant fiter by a certain field. I
>> used this code:
>> >
>> >       allDetections.filter =new
>> OpenLayers.Filter.Comparison({type:OpenLayers.Filter.Comparison.EQUAL_TO,property:
>> 'confidencei',value: 1200});
>> >       allDetections.refresh({force: true});
>> >
>> > Executing these two lines when clicking on a button does nothing in the
>> map,no filtering. Is this filtering possible? after googling for a while I
>> cant find anything about filtering vector layers filled manually.
>> >
>> > I really appreciate your help! thanks!!
>> >
>> > Regards.
>> >
>> >
>> > // CREATE DETECTIONS LAYER
>> >
>> >    var styleAllDetections = { styleMap: new OpenLayers.StyleMap(
>> {"default": {
>> >
>>         graphicName: "ship",
>> >
>>         rotation:    "${heading}"
>> >
>>     } ,
>> >
>>    } ) };
>> >     allDetections = new OpenLayers.Layer.Vector("Detections",
>> styleAllDetections);
>> >     var featuresAll = [];
>> >
>> >     <!-- FILL VECTOR LAYER WITH THE ITEMS OF THE DETECCTIONS LIST -->
>> >     <logic:iterate name="product" property="detections" id="item">
>> >     featuresAll.push(new OpenLayers.Feature.Vector(new
>> OpenLayers.Geometry.Point(<bean:write name="item" property="lon"/>,
>> <bean:write name="item" property="lat"/>),
>> >                                                     { id: <bean:write
>> name="item" property="id"/>,
>> >                                                       lat: <bean:write
>> name="item" property="lat"/>,
>> >                                                       lon: <bean:write
>> name="item" property="lon"/>,
>> >                                                       confidence:
>> <bean:write name="item" property="confidence"/
>> >                                                     } ) );
>> >     </logic:iterate>
>> >
>> >     allDetections.addFeatures(featuresAll);
>> >     map.addLayer(allDetections);
>> >
>> > Best regards.
>> > _______________________________________________
>> > Users mailing list
>> > [email protected]
>> > http://lists.osgeo.org/mailman/listinfo/openlayers-users
>>
>>
>
_______________________________________________
Users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/openlayers-users

Reply via email to