Greetings list,

I noticed while playing with DEFAULT layers that they were being drawn behind all my other layers. After looking at the code, I found that mapwms.c will draw DEFAULT layers before any others, and does not respect the draw order that the WMS client provides.

I think this violates the WMS 1.1.1 spec - 01-068r3 7.2.3.3 which states:

"A WMS shall render the requested layers by drawing the leftmost in the list bottommost, the next one over that, and so on."

From the WMS client's perspective, it has no idea what a layer's STATUS is.

I have attached a patch which will respect the draw order for DEFAULT layers, if they are specified in the LAYERS parameter. If they are not specified, the old behavior is used. I would appreciate feedback, if anyone has, on whether this is worthy of submitting as a ticket.

-Shawn
Index: mapwms.c
===================================================================
--- mapwms.c    (revision 7141)
+++ mapwms.c    (working copy)
@@ -425,11 +425,26 @@
       for(j=0; j<map->numlayers; j++)
       {
         /* Keep only layers with status=DEFAULT by default */
-        /* Layer with status DEFAULT is drawn first. */
+        /* Layer with status DEFAULT is drawn first, unless specified in the
+        /* LAYERS parameter. */
         if (GET_LAYER(map, j)->status != MS_DEFAULT)
            GET_LAYER(map, j)->status = MS_OFF;
-        else
-           map->layerorder[nLayerOrder++] = j;
+        else {
+          /* If this layer (of type MS_DEFAULT) is included in the layers 
list,  */
+          /* don't set its layerorder yet, it will be done below. Otherwise 
draw */
+          /* this layer first */
+          layerfound = 0;
+          for (k=0; k<numlayers; k++) {
+            if (strcasecmp(GET_LAYER(map, j)->name, layers[k]) == 0) {
+              /* Layer is referenced in the LAYERS list, don't set it now */
+              layerfound = 1;
+              break;
+            }
+          }
+          
+          if (!layerfound)
+            map->layerorder[nLayerOrder++] = j;
+        }
       }
 
       for (k=0; k<numlayers; k++)
@@ -449,9 +464,10 @@
                   layerfound = 1;
               }
           }
-          if (layerfound == 0)
+          if (layerfound == 0) {
+            msDebug("msWMSLoadGetMapParams(): Unknown layer '%s' given in 
LAYERS parameter\n", layers[k]);
             invalidlayers++;
-
+          }
       }
 
       /* set all layers with status off at end of array */

Reply via email to