[OpenLayers-Users] Vector Filters

Andreas Hocevar ahocevar at opengeo.org
Wed Jul 22 04:07:13 EDT 2009


Hi,

the filter property of the layer does not do anything, unless the
layer is connected to a strategy that uses it (currently only
Strategy.BBOX as far as I know). Since you do not use any strategy and
protocol to manage your layers, you are probably better off using your
filter in a style context function, using e.g.

var context = {
    display: function(feature) {
        return filter.evaluate(feature.attributes) ? "", "none";
    }
};

See the styles-context.html examples for details on how to use this.

Regards,
Andreas.

On Wed, Jul 22, 2009 at 8:47 AM, Brad Spencer<brad at cubewerx.com.au> wrote:
> List,
>
>
>
> I have successfully built a layer of points and styled them with a stylemap.
> However, I now want to filter these after they have been loaded via an
> interactive user process.
>
>
>
> To test filtering I assume you have to include a filter in the vector layer
> definition and then later you can redefine it and refresh the vector layer
> with the new filter active?
>
>
>
> To test this, I am trying to make sure that there is a filter on the new
> vector layer at load time just to see that my assumptions are correct.
> Whilst the code runs it does not filter. I have added an attribute called
> ‘color’ to the array used to build the layer and assume it is the property
> value needed in the Filter?
>
>
>
> I can’t see any examples that do exactly this so thought I would seek advice
> from the pond.
>
>
>
> // show the first color value
>
> alert('Color = '+sortedPoints[0].attributes.color);
>
>
>
> // create the vector layer and apply the styleMap at the same time
>
> userMarkers = new OpenLayers.Layer.Vector( "Vector Markers",
>
> {              styleMap: styleMap,
>
>                 rendererOptions: {zIndexing: true}
>
>                 ,filter: new OpenLayers.Filter.Comparison
>
>                 ({
>
>                                 type: OpenLayers.Filter.Comparison.EQUAL_TO,
>
>                                 property:'color',
>
>                                 value:'#FF0000'
>
>                 })
>
> });
>
>
>
> // pointFeature is the array of sorted point objects to be added as vector
> markers
>
> userMarkers.addFeatures(sortedPoints);
>
> map.addLayer(userMarkers);
>
>
>
> I must be doing something very wrong here. Can anyone quickly see a problem?
>
>
>
> Cheers, Brad…
>
>
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
>



-- 
Andreas Hocevar
OpenGeo - http://opengeo.org/
Expert service straight from the developers.



More information about the Users mailing list