[OpenLayers-Users] zoomToExtent with WFS filter

Phil Scadden p.scadden at gns.cri.nz
Wed Oct 9 13:22:26 PDT 2013


Firstly, just a comment about your design. Do you want to have the 
filtered layer show up as a layer - or do want to have filtered data 
show up as a selection on top of an existing unfiltered layer? (Part of 
design strategy to use WMS instead of WFS as much as possible).

My application uses WMS layers for display but each has a wfsprotocol 
object for queries. I get a wfs selection from a filter with:
                    wfsProtocol.read({
                         filter: new OpenLayers.Filter.Logical({
                             type: OpenLayers.Filter.Logical.AND,
                             filters: filters
                         }),
                         callback: processSpatialQuery,
                         scope: strategy
                     });

Inside processSpatialQuery is:
     sExt = null
     if (request.data && request.data.bbox) {
         var b = request.data.bbox;
         sExt = new OpenLayers.Bounds(b[0],b[1],b[2],b[3]);
     }else if (request.features) {
         var fts = request.features;
         if (fts.length>0 && fts[0].geometry) {
             sExt = fts[0].geometry.getBounds().clone();
             for(var i=1;i<fts.length;i++) {
                 sExt.extend(fts[i].geometry.getBounds());
             }
         }
     }

sExt is used for any zoomto called by user. If you want the filtered 
selection as a layer (as per your code), then you could also use code 
above to extract bounds using layer.features instead of request.features.

Notice: This email and any attachments are confidential.
If received in error please destroy and immediately notify us.
Do not copy or disclose the contents.



More information about the Users mailing list