[mapguide-trac] #167: Legend does not refresh correctly, when using the summary parameter

MapGuide Open Source trac_mapguide at osgeo.org
Tue May 29 10:45:18 EDT 2007


#167: Legend does not refresh correctly, when using the summary parameter
------------------------------------+---------------------------------------
 Reporter:  ksgeograf               |         Owner:       
     Type:  defect                  |        Status:  new  
 Priority:  medium                  |     Milestone:  1.2  
Component:  Server                  |       Version:  1.2.0
 Severity:  major                   |    Resolution:       
 Keywords:  legend summary refresh  |   External_id:       
------------------------------------+---------------------------------------
Comment (by ksgeograf):

 Ok, I found and fixed the problem.

 The summary parameter is used in the viewer to minimize the amount of data
 that is returned.

 In file legend.js, the fields for the summary are defined as:
 {{{
 function LayerSummary(name, objectId, layerRes)
 {
     this.name = name;
     this.objectId = objectId;
     this.layerRes = layerRes;
     this.isGroup = false;
     this.type = 1;
 }
 }}}
 This needs to be expanded to:
 {{{
 function LayerSummary(name, objectId, layerRes, displayInLegend, expanded,
 legend, visible)
 {
     this.name = name;
     this.objectId = objectId;
     this.layerRes = layerRes;
     this.isGroup = false;
     this.type = 1;
     this.displayInLegend = displayInLegend;
     this.expanded = expanded;
     this.legend = legend;
     this.visible = visible;
 }
 }}}
 There may be other fields needed.

 In legendui.templ the following function resides:
 {{{
 function HasTreeChanged(current, lightTree)
 {
     if(current.length != lightTree.length)
         return true;

     for(var i = 0; i < current.length; i++)
     {
         var node1 = current[i], node2 = lightTree[i];
         if(node1.type != node2.type || node1.objectId != node2.objectId)
             return true;
         if(node1.type == 1)
         {
             if(node1.layerRes != node2.layerRes)
                 return true;
         }
         else if(node1.type == 0)
         {
             if(node1.children != null)
             {
                 if(node2.children == null)
                     return true;
                 if(HasTreeChanged(node1.children, node2.children))
                     return true;
             }
         }
     }
     return false;
 }
 }}}

 This function needs to check for the new properties as well:
 {{{
 function HasTreeChanged(current, lightTree)
 {
     if(current.length != lightTree.length)
         return true;

     for(var i = 0; i < current.length; i++)
     {
         var node1 = current[i], node2 = lightTree[i];
         if(node1.type != node2.type || node1.objectId != node2.objectId)
             return true;
         if(node1.type == 1)
         {
             if(node1.layerRes != node2.layerRes)
                 return true;
             if(node1.legend != node2.legend)
                 return true;
             if(node1.expanded != node2.expanded)
                 return true;
             if(node1.displayInLegend != node2.displayInLegend)
                 return true;
             if(node1.visible != node2.visible)
                 return true;
         }
         else if(node1.type == 0)
         {
             if(node1.children != null)
             {
                 if(node2.children == null)
                     return true;
                 if(HasTreeChanged(node1.children, node2.children))
                     return true;
             }
         }
     }
     return false;
 }
 }}}

 Lastly, the different API's for the viewer must be updated to fill in the
 data.
 For the .Net version, the file to modify is legend.aspx, line 362 looks
 like:
 {{{
 output = output + String.Format("{0}[{1}] = new LayerSummary(\"{2}\",
 \"{3}\", \"{4}\"\n",
     container,
     i,
     rtLayer.GetName(),
     rtLayer.GetObjectId(),
     rtLayer.GetLayerDefinition().ToString(),
     );
 }}}

 It should be changed to:
 {{{
 output = output + String.Format("{0}[{1}] = new LayerSummary(\"{2}\",
 \"{3}\", \"{4}\", {5}, {6}, \"{7}\", {8});\n",
     container,
     i,
     rtLayer.GetName(),
     rtLayer.GetObjectId(),
     rtLayer.GetLayerDefinition().ToString(),
     rtLayer.GetDisplayInLegend() ? "true" : "false",
     rtLayer.GetExpandInLegend()? "true": "false",
     rtLayer.GetLegendLabel(),
     rtLayer.GetVisible()? "true": "false"
     );
 }}}

 This will fix the problem with the legend not updating correctly, using
 the AJAX viewer, the DWF viewer is still broken. I'm guessing it uses the
 same code internally.

 A short term fix, would be to insert/remove layers from the runtime map,
 as this seems to be detected. Also swapping layers might work.

 The above fix needs to be applied for groups as well, and also for the
 different other viewers.

-- 
Ticket URL: <http://trac.osgeo.org/mapguide/ticket/167#comment:1>
MapGuide Open Source <http://mapguide.osgeo.org/>
MapGuide Open Source Internals


More information about the mapguide-trac mailing list