1

I'm trying to filter features in OpenLayers when moving a JQueryUI slider. It works like this:

EDIT: full files available here on GitHub.

JQueryUI slider

When moving the slider cursor, minSelection and maxSelection values are defined. I need to show only features with minSelection < height < maxSelection. I've defined a filter that takes the current min and maxSelection and makes a query on the WFS, applying it to the vector layer (curlayer is the current vector layer object):

heightFilter = new OpenLayers.Filter.Comparison({
    type: OpenLayers.Filter.Comparison.BETWEEN,
    property: 'height',
    lowerBoundary: minSelection,
    upperBoundary: maxSelection
});

curlayer.filter = heightFilter;
curlayer.refresh({force: true})

OpenLayers.js

var _projObj = {
    wgs84 : new OpenLayers.Projection('EPSG:4326'),
    mercator : new OpenLayers.Projection('EPSG:900913'),
    osm_wms : new OpenLayers.Projection('EPSG:3857')
};

uses_layer = new OpenLayers.Layer.Vector("US Layer", {
    strategies : [new OpenLayers.Strategy.Fixed()],
    projection : _projObj.wgs84,
    visibility : true,
    displayInLayerSwitcher : false,
    protocol : new OpenLayers.Protocol.WFS({
        version : '1.0.0',
        url : 'http://46.105.19.68/cgi-bin/mapserv?map=/home/fradeve/public_html/ark-oia/ark-scrmap/wfs.map&service=WFS',
        featureType : USType
    })
});

Mapserver

LAYER
    CONNECTION "host=46.105.19.68 user=** password=** dbname=sipdb"
    CONNECTIONTYPE POSTGIS
    DATA "geometry from (select gid, layer, the_geom as geometry, n1, n2, n13 as height from us) as pseudo_table using unique gid using srid=4326"
    NAME "us"
    DUMP TRUE
    METADATA
        "wfs_srs"         "EPSG:4326"
        "gml_featureid"   "gid"
        "wfs_title"       "us"
        "wfs_typename"    "us"
        "gml_include_items"       "all"
        "wfs_version"     "1.0.0" 
        "wfs_enable_request" "*" 
    END
    PROJECTION
        "init=epsg:4326"
    END
    STATUS ON
    TYPE Polygon
    UNITS METERS
    CLASS 
        STYLE
            ANGLE 360
            ANTIALIAS TRUE
            WIDTH 1
        END
    END
END

The XHTTP Post response

Here is what I get when moving around the slider cursor:

Request payload

<?xml version="1.0" encoding="UTF-8"?>
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.0.0" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">
<wfs:Query xmlns:feature="http://localhost/cgi-bin/mapserv.exe" typeName="feature:us">
  <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
     <ogc:PropertyIsBetween>
        <ogc:PropertyName>height</ogc:PropertyName>
        <ogc:LowerBoundary>
           <ogc:Literal>870</ogc:Literal>
        </ogc:LowerBoundary>
        <ogc:UpperBoundary>
           <ogc:Literal>900</ogc:Literal>
        </ogc:UpperBoundary>
     </ogc:PropertyIsBetween>
  </ogc:Filter>
 </wfs:Query>
</wfs:GetFeature>

Response

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs" xmlns:ms="http://localhost/cgi-bin/mapserv.exe" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd http://localhost/cgi-bin/mapserv.exe http://46.105.19.68/cgi-bin/mapserv?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=feature:us&amp;OUTPUTFORMAT=XMLSCHEMA">
    <gml:boundedBy>
        <gml:null>missing</gml:null>
    </gml:boundedBy>
</wfs:FeatureCollection>

So...

Where is the error? Everything seems fine to me...

1 Answer 1

2

If setting a DEBUG 5 on both your LAYER and MAP objects, and also add CONFIG MS_ERRORFILE "ms_error.log" in your MAP object. You should be able to see more about what's going on.

You should be able to see the temp mapfile being created to execute your query. You should also be able to see the postgresql query built to fetch your records, which you could copy/paste in psql/pgadmin to see its actual result.

Also, please note that OpenLayers and MapServer both have mailing list you could register to and post your questions there. You might get faster replies that way.

HTH,

Alexandre

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.