Bug 664

Summary: LegendTemplateGetLayerName javascript array contents not always correct
Product: Chameleon Reporter: Bart van den Eijnden <bartvde@osgis.nl>
Component: WidgetAssignee: chameleon-dev <chameleon-dev@lists.maptools.org>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 1.99   
Target Milestone: 1.99 beta 4   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description From 2004-09-08 08:14:55
As I use css to highlight the active layer some problems have arisen with the 
contents of the javascript array of the LegendTemplateGetLayerName function.

For instance, when starting with a normal application with 2 layers, then 
loading a context of 5 layers, and after that removing one of the 5 layers, 
this old layer is still in the javascript array.

This is why I want to propose the following change:

Old piece of code:
        for( $i=0; $i< $oMap->numlayers; $i++)
        {
            $oLayer = $oMap->getLayer( $i );
            $oLayer->setmetadata( "layer_index", $i );
            $szLayers .= 'aLayers['.$i.'] = "'.$oLayer->name.'";'."\n";
        }


New piece of code:
            $oLayer = $oMap->getLayer( $i );
            if ($oLayer->status == MS_DELETE) { }
            else
            {
              $oLayer->setmetadata( "layer_index", $i );
              $szLayers .= 'aLayers['.$i.'] = "'.$oLayer->name.'";'."\n";
            }

Any objections or thoughts?
------- Comment #1 From 2004-09-08 09:33:04 -------
looks good, please implement.
------- Comment #2 From 2004-09-08 09:42:03 -------
Fixed in CVS, revision 1.13 of LegendTemplate.widget.php.
------- Comment #3 From 2004-09-10 07:40:02 -------
I have found an issue with this fix and propose the following now:

$icounter = 0;

for( $i=0; $i< $oMap->numlayers; $i++)
{
  $oLayer = $oMap->getLayer( $i );
  if ($oLayer->status == MS_DELETE) { }
  else
  {
    $oLayer->setmetadata( "layer_index", $icounter );
    $szLayers .= 'aLayers['.$icounter.'] = "'.$oLayer->name.'";'."\n";
    $icounter++;
  }
}
------- Comment #4 From 2004-09-10 12:19:41 -------
ok, I see the problem with using $i if you are deleting layers :)
------- Comment #5 From 2004-10-21 13:48:15 -------
Chanegd target to 1.99 RC 1.
------- Comment #6 From 2004-11-04 18:29:56 -------
Bart, if you fixed this and have committed it, please close the bug so we can
verify it for the release.
------- Comment #7 From 2004-11-05 02:17:47 -------
Paul, I have just committed my final fix to CVS. Revision 1.19 for 
LegendTemplate.widget.php.

Sorry for leaving this so long.

Maybe it would be useful to change the "Assigned To" for this type of bug to 
me, so there would be less chance of me leaving this so long :), but I probably 
don't have bugzilla rights to do this.
------- Comment #8 From 2004-11-05 07:41:59 -------
Bart, I believe that anyone in bugzilla can assign a bug to themselves :) 
Thanks for getting this in.