[OpenLayers-Users] Filtering a GeoJSON layer

Christoph Ratke christoph.ratke at gmx.net
Tue Jan 3 09:39:56 EST 2012


Hi Aparna,
what Arnd wrote is that you can create an OGC filter for your WFS as in

var ogcFilter = new OpenLayers.Filter.Comparison({
     type: OpenLayers.Filter.Comparison.EQUAL_TO,
     property: "id",
     value: someId
});

and then use it in your protocol:

var state = new OpenLayers.Layer.Vector("K", {
                 strategies: [new OpenLayers.Strategy.Fixed()],
                 protocol: new OpenLayers.Protocol.WFS({
                     version: "1.1.0",
                     url: "http://localhost:8085/geoserver/wfs",
                     params: {CQL_FILTER: 'SCHCAT = 3'},
                     featureType: "karf",
                     featureNS: "http://opengeo.org/India",
                     defaultFilter: ogcFilter
                 })
             });

Or have a look here: http://openlayers.org/dev/examples/wfs-filter.js

Christoph


On 03.01.2012 11:51, Aparna wrote:
> This does not seem to be working either.
>
> var state = new OpenLayers.Layer.Vector("K", {
>                 strategies: [new OpenLayers.Strategy.Fixed()],
>                 protocol: new OpenLayers.Protocol.WFS({
>                     version: "1.1.0",
>                     url: "http://localhost:8085/geoserver/wfs",
>                     params: {CQL_FILTER: 'SCHCAT = 3'},
>                     featureType: "karf",
>                     featureNS: "http://opengeo.org/India"
>
>                 })
>             });
>             map.addLayer(state);
>
>
>
> On Wed, Dec 28, 2011 at 12:07 AM, Arnd Wippermann 
> <arnd.wippermann at web.de <mailto:arnd.wippermann at web.de>> wrote:
>
>     Hi,
>     i think, you cannot use filter to load static data. OpenLayers
>     have to load the whole file and doesnot use the filter to
>     serialize only parts of the file and add them as features.
>     If you request the data from a provider, which evaluates the
>     filter like WFS, filter does work.
>     Instead you can use a styleMap to display only a set of features.
>     Arnd
>     ------------------------------------------------------------------------
>     *Von:* openlayers-users-bounces at lists.osgeo.org
>     <mailto:openlayers-users-bounces at lists.osgeo.org>
>     [mailto:openlayers-users-bounces at lists.osgeo.org
>     <mailto:openlayers-users-bounces at lists.osgeo.org>] *Im Auftrag von
>     *Aparna
>     *Gesendet:* Montag, 26. Dezember 2011 12:15
>     *An:* users at openlayers.org <mailto:users at openlayers.org>
>     *Betreff:* [OpenLayers-Users] Filtering a GeoJSON layer
>
>     filtering either after projection or in the
>     protocol->format->filter does not seem to be working at all.
>
>     var state = new OpenLayers.Layer.Vector("State", {
>                     projection: map.displayProjection,
>                     filter: new OpenLayers.Filter.Comparison({
>                     type: OpenLayers.Filter.Comparison.EQUAL_TO,
>                     property: 'SCHMGT',
>                     value: 2
>                 }),
>             strategies: [new OpenLayers.Strategy.Fixed()],
>                     protocol: new OpenLayers.Protocol.HTTP({
>                         url: "klm/GIS.json",
>                         format: new OpenLayers.Format.GeoJSON({
>                             extractAttributes: true
>
>                         })
>                     })
>                 });
>
>     How does one implement a filter??
>
>
>
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20120103/e3856346/attachment-0001.html


More information about the Users mailing list