Here's my filter on Mapserver's Side :


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

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

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 :


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 :

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

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

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",
            {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) {
        control.events.register("featureunselected", this, function(e) {
        control.events.register("hoverfeature", this, function(e) {
        control.events.register("outfeature", this, function(e) {

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


2) cql_filter




  • 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.