1

Here's my filter on Mapserver's Side :

PROCESSING "NATIVE_FILTER=(ct in ('%ct%'))"

It allows me to select several values for my column. My validation looks like :

VALIDATION
    'ct' '^[a-zA-Z\-]+$'    
    'default_ct' 'a'
END

On Openlayers side, I get stuck to send several value though. If I do this :

var wmsSource = new ol.source.TileWMS({
   url: 'http://localhost:5000/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/essai.map&SERVICE=WMS&VERSION=1.1.1%20&REQUEST=GetCapabilities',
        serverType: 'mapserver',
        params: {'LAYERS': 'layer','ct':"value1,value2",'TILED': true}
  });

My comma is encoded while asking mapserver as you can see on that url :

http://localhost:5000/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/essai.map&SERVICE=WMS&VERSION=1.1.1%20&REQUEST=GetCapabilities&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=later&ct=value1%2Cvalue2&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX=-5009377.085697312%2C5009377.085697312%2C-9.313225746154785e-10%2C10018754.171394624

My comma has been transcoded in %2C. Is there a way to prevent that, or to solve it?

EDIT : That was actually a validation error. I made the following changes :

var wmsSource = new ol.source.TileWMS({
   url: 'http://localhost:5000/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/htdocs/essai.map&SERVICE=WMS&VERSION=1.1.1%20&REQUEST=GetCapabilities',
        serverType: 'mapserver',
        params: {'LAYERS': 'layer','ct':"('value1','value2')",'TILED': true}
  });

and in my mapfile :

VALIDATION
    'ct' '^[a-zA-Z\-\,\\\(\)\']+$'
    'default_ct' 'a'
END

As I need to always return something (see that question) my FILTER look like that :

PROCESSING "NATIVE_FILTER=((ct in %ct%) or (%ct% in 'a'))"

I've got that error :

msPostGISLayerWhichShapes(): Error (ERREUR: erreur de syntaxe sur ou près de « 'a' » LINE 1: ...ainer','fishing')) or (('container','fishing') in 'a')) and ...

(== Error syntax.)

  • Why you are including the "&SERVICE=WMS&VERSION=1.1.1%20&REQUEST=GetCapabilities" in your URL ? it is already generated by default. – Shiko Oct 21 '16 at 13:41
  • Did you follow this example ms4w.com/trac/wiki/MapCacheOpenLayers3 – Shiko Oct 21 '16 at 13:42
  • Nop I didn't see it. I removed "&SERVICE=WMS&VERSION=1.1.1%20&REQUEST=GetCapabilities" and it works. Actually it's not an url encode issue, I updated my question – So4ne Oct 21 '16 at 13:45
  • try below link, filtering columns cannot be used the way you wrote it. check this link, gis.stackexchange.com/questions/54947/… – Shiko Oct 21 '16 at 14:19
  • @Shiko I don't think your answers could help me as I can't set a default value because I don't have one. I have to be able to select multiple values at once or all the values. For my ct, I've got 11 values different, I can't "hardwritten" (hardcoded?) them, if I add one in my db it won't be reverberated – So4ne Oct 21 '16 at 14:30
1

You have 2 options to filter fields in WMS:
1) Filter (Encoded XML format) :

 var map, layer, select, hover, control;

    function init(){
        OpenLayers.ProxyHost= "proxy.cgi?url=";
        map = new OpenLayers.Map('map', {
            controls: [
                new OpenLayers.Control.PanZoom(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.Navigation()
            ]
        });
        layer = new OpenLayers.Layer.WMS(
            "States WMS/WFS",
            "http://v2.suite.opengeo.org/geoserver/ows",
            {layers: 'usa:states', format: 'image/gif'}
        );
        select = new OpenLayers.Layer.Vector("Selection", {styleMap: 
            new OpenLayers.Style(OpenLayers.Feature.Vector.style["select"])
        });
        hover = new OpenLayers.Layer.Vector("Hover");
        map.addLayers([layer, hover, select]);

        control = new OpenLayers.Control.GetFeature({
            protocol: OpenLayers.Protocol.WFS.fromWMSLayer(layer),
            box: true,
            hover: true,
            multipleKey: "shiftKey",
            toggleKey: "ctrlKey"
        });
        control.events.register("featureselected", this, function(e) {
            select.addFeatures([e.feature]);
        });
        control.events.register("featureunselected", this, function(e) {
            select.removeFeatures([e.feature]);
        });
        control.events.register("hoverfeature", this, function(e) {
            hover.addFeatures([e.feature]);
        });
        control.events.register("outfeature", this, function(e) {
            hover.removeFeatures([e.feature]);
        });
        map.addControl(control);
        control.activate();

        map.setCenter(new OpenLayers.Bounds(-140.444336,25.115234,-44.438477,50.580078).getCenterLonLat(), 3);
    }

Example:
http://dev.openlayers.org/examples/getfeature-wfs.html
http://dev.openlayers.org/examples/wfs-filter.js

2) cql_filter

cql_filter=INTERSECTS(the_geom,%20POINT%20(-74.817265%2040.5296504))

Example:
http://dev.openlayers.org/examples/cql-format.html

Reference:
http://docs.geoserver.org/stable/en/user/services/wms/vendor.html

  • With : params: {'LAYERS': 'layer','ct':['value1, value2'],'TILED': true} VALIDATION 'ct' '.' 'default_ct' 'a' END And PROCESSING "NATIVE_FILTER=(ct in ('%ct%') or '%ct%' = 'a')" (url is : localhost:5000/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/… Nothing appears, and no error – So4ne Oct 21 '16 at 14:05
  • ct is a filter or what exactly ? – Shiko Oct 21 '16 at 14:09
  • My bad I forgot quote betweens value1 et value2 but it doesn't change anything (url is : localhost:5000/cgi-bin/mapserv.exe?map=/ms4w/apps/tutorial/… – So4ne Oct 21 '16 at 14:09
  • ct is a column on my postgis db. I need to be able to select multiple values for this column (with the in), or display every value if no parameter is given – So4ne Oct 21 '16 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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