Ticket #1141 (closed defect: fixed)

Opened 8 years ago

Last modified 8 years ago

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

Changed 8 years ago by bartvde@…

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

Changed 8 years ago by bartvde@…

  • milestone set to FUTURE
Setting target to future.

Changed 8 years ago by jmckenna@…

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.

Changed 8 years ago by jmckenna@…

  • cc jmckenna@… added

Changed 8 years ago by bartvde@…

  • milestone changed from FUTURE to 4.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?

Changed 8 years ago by bartvde@…

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;
             }

Changed 8 years ago by bartvde@…

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

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

Changed 8 years ago by dmorissette

  • cc valik.solorzano.barboza@… added
  • owner changed from valik.solorzano.barboza@… to dmorissette@…
Taking this one.

Changed 8 years ago by dmorissette

  • status changed from new to closed
  • resolution set to fixed
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.