Opened 19 years ago

Closed 19 years ago

#1141 closed defect (fixed)

GetLegendGraphic and Layers with status not defined

Reported by: bartvde@… Owned by: dmorissette
Priority: high Milestone: 4.8 release
Component: WMS Server Version: 4.4
Severity: normal Keywords:
Cc: jmckenna@…, valik.solorzano.barboza@…

Description

When issuing a GetLegendGraphic request on a layer without a status defined, no
legend is displayed. If you issue a GetMap request on the layer, the Mapserver
code probably turns the status of the layer to on so that it is displayed.

Maybe this should also be changed for the GetLegendGraphic code, or maybe there
should be a more general WMS or OWS mechanism for doing this?

Change History (9)

comment:1 by bartvde@…, 19 years ago

Cc: mapserver-bugs@… added
Added mapserver-bugs@dmsolutions.ca to the cc to see what they think about this.

comment:2 by bartvde@…, 19 years ago

Milestone: FUTURE
Setting target to future.

comment:3 by jmckenna@…, 19 years ago

i was recently testing getlegendgraphic for the docs, and was baffled why one
layer would not return a legendgraphic...it was in fact turned OFF in the server
mapfile.  I think this issue should be fixed to follow the getmap functionality,
as Bart mentioned.

comment:4 by jmckenna@…, 19 years ago

Cc: jmckenna@… added

comment:5 by bartvde@…, 19 years ago

Milestone: FUTURE4.8 release
Running into this again, we really need to get this fixed. This should be such
an easy fix, I could even do it if I had CVS commit rights ...

In mapwms.c:

         for (i=0; i<map->numlayers; i++)
         {
             if (map->layers[i].name &&
                 strcasecmp(map->layers[i].name, pszLayer) != 0)
             {
                 map->layers[i].status = MS_OFF;
             }
         } 

Change the above to:

         for (i=0; i<map->numlayers; i++)
         {
             if (map->layers[i].name &&
                 strcasecmp(map->layers[i].name, pszLayer) != 0)
             {
                 map->layers[i].status = MS_OFF;
             }
             else if (strcasecmp(map->layers[i].name, pszLayer) == 0)
             {
                 map->layers[i].status = MS_ON;
             }
         }

I have tested this fix in my local copy. Can somebody please commit this?

comment:6 by bartvde@…, 19 years ago

To be on the safe side, also add a check on the name being set:

             else if (map->layers[i].name && strcasecmp(map->layers[i].name,
pszLayer) == 0)
             {
                 map->layers[i].status = MS_ON;
             }

comment:7 by bartvde@…, 19 years ago

Reading over it again, the second check is pretty useless now, so:

             else if (map->layers[i].name)
             {
                 map->layers[i].status = MS_ON;
             }

comment:8 by dmorissette, 19 years ago

Cc: valik.solorzano.barboza@… added
Owner: changed from valik.solorzano.barboza@… to dmorissette@…
Taking this one.

comment:9 by dmorissette, 19 years ago

Resolution: fixed
Status: newclosed
Fixed in CVS HEAD (4.7) and branch-4-6 (will be in 4.6.1).

There was already a loop searching for the layer by name, so to avoid two loops
of strcasecmp() on layer names, I changed the second one to:

         /* turn this layer on and all other layers off, required for
msDrawLegend() */
         for (i=0; i<map->numlayers; i++)
         {
             if (i == iLayerIndex)
                 map->layers[i].status = MS_ON;
             else
                 map->layers[i].status = MS_OFF;
         }

Note: See TracTickets for help on using tickets.