[mapguide-commits] r7736 - in trunk/MgDev/Server/src: Services/Mapping UnitTesting

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Mon Aug 5 09:39:00 PDT 2013


Author: jng
Date: 2013-08-05 09:39:00 -0700 (Mon, 05 Aug 2013)
New Revision: 7736

Modified:
   trunk/MgDev/Server/src/Services/Mapping/LegendPlotUtil.cpp
   trunk/MgDev/Server/src/Services/Mapping/icons.h
   trunk/MgDev/Server/src/UnitTesting/TestRenderingService.cpp
Log:
#2334: Make GETLEGENDIMAGE more suitable for printing/plotting:
 - Include inline icon for layer groups (from AJAX viewer)
 - Bump up the legend font height. This makes the text much more readable (not #1524 flexible, but serviceable quality now). Text in DWF legend plots are slightly larger than before, but the mapagent operation is much better now.
 - Fix a defect where a group that contains visible groups (but no layers) were not rendered. The existing RenderLegend test case has been updated which exposed this defect. The fix was to restructure the legend rendering code to call MgLegendPlotUtil::ProcessLayersForLegend() recursively so that all child layers *and groups* are accounted for.

Modified: trunk/MgDev/Server/src/Services/Mapping/LegendPlotUtil.cpp
===================================================================
--- trunk/MgDev/Server/src/Services/Mapping/LegendPlotUtil.cpp	2013-08-05 16:29:26 UTC (rev 7735)
+++ trunk/MgDev/Server/src/Services/Mapping/LegendPlotUtil.cpp	2013-08-05 16:39:00 UTC (rev 7736)
@@ -79,8 +79,8 @@
 
 const double legendSpacing = bitmapPixelHeight / bitmapDpi + 0.005;
 const double defaultLegendMargin = 0.1; // inch
-const double legendFontHeightMeters = 0.002;
-const double legendTextVertAdjust = 0.07;  // inch
+const double legendFontHeightMeters = 0.003;
+const double legendTextVertAdjust = 0.06;  // inch
 
 
 // Static helper method to draw a PNG icon.  Calling Renderer::ProcessRaster
@@ -156,6 +156,9 @@
     RS_LineStroke lineStroke;
     dr.ProcessPolyline(&lb, lineStroke);
 
+    //Pad left at the top-level
+    legendOffsetX += (defaultLegendMargin * convertUnits);
+
     //And then do the content.
     BuildLegendContent(map, dMapScale, legendSpec, legendOffsetX, legendOffsetY, dr, convertUnits);
 }
@@ -169,6 +172,10 @@
     textDef.halign() = RS_HAlignment_Left;
     textDef.valign() = RS_VAlignment_Base;
 
+    //for convenience compute legend bitmap size in plot units (inches, mm, pixels, whatever)
+    double dIconWidth = ((double)bitmapPixelWidth / bitmapDpi)*convertUnits;
+    double dIconHeight = ((double)bitmapPixelHeight / bitmapDpi)*convertUnits;
+
     // Get the layer info
     double x = legendOffsetX + legendSpec->GetMarginLeft();
     double y = legendOffsetY + legendSpec->GetPaperHeight() - legendSpec->GetMarginTop() - legendFontHeightMeters*M_TO_IN*convertUnits;
@@ -179,57 +186,6 @@
 
     // Add legend entries for layers that do not belong to a group
     ProcessLayersForLegend(map, scale, NULL, x, y, textDef, dr, legendSpec, legendOffsetY, convertUnits);
-
-    // do layer groups
-    Ptr<MgLayerGroupCollection> mggroups = map->GetLayerGroups();
-    Ptr<MgLayerCollection> layers = map->GetLayers();
-
-    // iterate over groups and draw each group's layers
-    for (int k = 0; k < mggroups->GetCount(); k++)
-    {
-        Ptr<MgLayerGroup> mggroup = mggroups->GetItem(k);
-
-        // Count number of visible layers in this group.
-        bool hasVisibleLayers = false;
-        for (int l = 0; l < layers->GetCount(); l++)
-        {
-            Ptr<MgLayerBase> layer = layers->GetItem(l);
-            Ptr<MgLayerGroup> layerGroup = layer->GetGroup();
-            if ((layer->IsVisible()) && (layerGroup.p == mggroup.p))
-            {
-                hasVisibleLayers = true;
-                break;
-            }
-        }
-        if (!hasVisibleLayers)
-            continue;
-
-        if (mggroup == NULL)
-        {
-            throw new MgNullReferenceException(L"MgLegendPlotUtil.AddLegendElement", __LINE__, __WFILE__, NULL, L"", NULL);
-        }
-        Ptr<MgLayerGroup> mgparent = mggroup->GetGroup();
-
-        double indent = 0;
-        while (mgparent)
-        {
-            indent += MgPrintLayout::GroupIndent;
-            mgparent = mgparent->GetGroup();
-        }
-
-        x = legendOffsetX + (defaultLegendMargin + indent)*convertUnits;
-
-        RS_LabelInfo info(x, y + legendTextVertAdjust*convertUnits, textDef);
-        dr.ProcessLabelGroup(&info, 1, mggroup->GetLegendLabel(), RS_OverpostType_All, false, NULL, 0.0);
-
-        y -= legendSpacing*convertUnits;
-
-        if (y < legendSpec->GetMarginBottom())
-            break;
-
-        // Process the layers
-        ProcessLayersForLegend(map, scale, mggroup, x, y, textDef, dr, legendSpec, legendOffsetY, convertUnits);
-    }
 }
 
 
@@ -254,6 +210,28 @@
     //bottom of the legend -- where we stop drawing
     double bottomLimit = legendOffsetY + legendSpec->GetMarginBottom();
 
+    if (NULL != mggroup)
+    {
+        x = startX - initialMarginX;
+        // use group icon
+        RS_Bounds b2(x, y, x + dIconWidth, y + dIconHeight);
+        DrawPNG(&dr, (unsigned char*)LAYER_GROUP_ICON, sizeof(LAYER_GROUP_ICON), bitmapPixelWidth, bitmapPixelHeight, b2);
+
+        // Add the group legend label.
+        RS_LabelInfo info(x + dIconWidth + (defaultLegendMargin * convertUnits), y + legendTextVertAdjust*convertUnits, textDef);
+        dr.ProcessLabelGroup(&info, 1, mggroup->GetLegendLabel(), RS_OverpostType_All, false, NULL, 0.0);
+
+        // Indent for children
+        x += initialMarginX;
+
+        //move y cursor down one line
+        y -= verticalDelta;
+
+        if (y < bottomLimit)
+        {
+            return;
+        }
+    }
     // build the list of layers that need to be processed
     Ptr<MgLayerCollection> layers = map->GetLayers();
     for (int i = 0; i < layers->GetCount(); i++)
@@ -410,6 +388,25 @@
             break;
         }
     }
+    
+    //Process child groups of this legend
+    Ptr<MgLayerGroupCollection> groups = map->GetLayerGroups();
+    for (int i = 0; i < groups->GetCount(); i++)
+    {
+        Ptr<MgLayerGroup> group = groups->GetItem(i);
+        if (!group->GetDisplayInLegend())
+            continue;
+
+        Ptr<MgLayerGroup> groupParent = group->GetGroup();
+        if (groupParent.p == mggroup)
+        {
+            ProcessLayersForLegend(map, mapScale, group, startX + initialMarginX, y, textDef, dr, legendSpec, legendOffsetY, convertUnits);
+            if (y < bottomLimit)
+            {
+                break;
+            }
+        }
+    }
 }
 
 

Modified: trunk/MgDev/Server/src/Services/Mapping/icons.h
===================================================================
--- trunk/MgDev/Server/src/Services/Mapping/icons.h	2013-08-05 16:29:26 UTC (rev 7735)
+++ trunk/MgDev/Server/src/Services/Mapping/icons.h	2013-08-05 16:39:00 UTC (rev 7736)
@@ -125,4 +125,26 @@
 0x82
 };
 
+//lc_group.png
+const unsigned char LAYER_GROUP_ICON[] = {
+0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a,0x00,0x00,0x00,0x0d,0x49,0x48,0x44,0x52,
+0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x10,0x08,0x06,0x00,0x00,0x00,0x1f,0xf3,0xff,
+0x61,0x00,0x00,0x00,0x01,0x73,0x52,0x47,0x42,0x00,0xae,0xce,0x1c,0xe9,0x00,0x00,
+0x00,0x04,0x67,0x41,0x4d,0x41,0x00,0x00,0xb1,0x8f,0x0b,0xfc,0x61,0x05,0x00,0x00,
+0x00,0x09,0x70,0x48,0x59,0x73,0x00,0x00,0x0e,0xc3,0x00,0x00,0x0e,0xc3,0x01,0xc7,
+0x6f,0xa8,0x64,0x00,0x00,0x00,0x1a,0x74,0x45,0x58,0x74,0x53,0x6f,0x66,0x74,0x77,
+0x61,0x72,0x65,0x00,0x50,0x61,0x69,0x6e,0x74,0x2e,0x4e,0x45,0x54,0x20,0x76,0x33,
+0x2e,0x35,0x2e,0x31,0x30,0x30,0xf4,0x72,0xa1,0x00,0x00,0x00,0x84,0x49,0x44,0x41,
+0x54,0x38,0x4f,0x63,0xf8,0xff,0xff,0x3f,0x45,0x18,0xab,0x20,0x29,0x18,0x4c,0x1c,
+0x5c,0xd3,0xf2,0xbf,0x39,0x92,0x13,0x03,0x83,0xc4,0x91,0x15,0x63,0xc3,0x60,0x02,
+0xa4,0xf8,0xff,0xdb,0x5e,0x0c,0x8c,0x6e,0x20,0x32,0x86,0x19,0x8e,0x6a,0xc0,0x75,
+0x4b,0x54,0xfc,0xa6,0x03,0xc3,0x50,0x10,0xbe,0xb4,0x25,0xe2,0x7f,0xa2,0x21,0x0b,
+0x61,0x03,0x90,0x6d,0xc4,0x86,0x31,0x0c,0xc0,0x50,0x80,0x66,0x20,0x0c,0x5f,0xde,
+0x62,0x89,0xdd,0x05,0xe8,0x9a,0x40,0x0a,0xb1,0xe1,0x1d,0xb3,0x35,0xf0,0x1b,0x80,
+0x4d,0x13,0x32,0x1e,0xee,0x06,0xc0,0x14,0x10,0xc2,0x28,0x06,0x80,0x52,0x15,0x48,
+0x80,0x14,0xbc,0x61,0x46,0x23,0xc2,0x00,0x4a,0x30,0x56,0x41,0xe2,0xf1,0x7f,0x06,
+0x00,0x36,0x20,0xae,0xaf,0x57,0x56,0xf5,0x08,0x00,0x00,0x00,0x00,0x49,0x45,0x4e,
+0x44,0xae,0x42,0x60,0x82
+};
+
 #endif

Modified: trunk/MgDev/Server/src/UnitTesting/TestRenderingService.cpp
===================================================================
--- trunk/MgDev/Server/src/UnitTesting/TestRenderingService.cpp	2013-08-05 16:29:26 UTC (rev 7735)
+++ trunk/MgDev/Server/src/UnitTesting/TestRenderingService.cpp	2013-08-05 16:39:00 UTC (rev 7736)
@@ -702,20 +702,44 @@
         Ptr<MgLayerGroupCollection> layerGroups = map->GetLayerGroups();
         Ptr<MgLayerCollection> layers = map->GetLayers();
 
-        Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/Layers/Parcels.LayerDefinition");
+        Ptr<MgResourceIdentifier> resId = new MgResourceIdentifier(L"Library://UnitTests/Layers/HydrographicPolygons.LayerDefinition");
+        Ptr<MgResourceIdentifier> ldfRail = new MgResourceIdentifier(L"Library://UnitTests/Layers/Rail.LayerDefinition");
 
-        Ptr<MgLayerGroup> group = new MgLayerGroup(L"Can't see me");
-        group->SetLegendLabel(L"Can't see me");
+        Ptr<MgLayerGroup> group = new MgLayerGroup(L"Test Group");
+        group->SetLegendLabel(L"Test Group");
         group->SetDisplayInLegend(true);
         layerGroups->Add(group);
 
+        Ptr<MgLayerGroup> group1 = new MgLayerGroup(L"Nest top level");
+        group1->SetLegendLabel(L"Nest top level");
+        group1->SetDisplayInLegend(true);
+        layerGroups->Add(group1);
+
+        Ptr<MgLayerGroup> group2 = new MgLayerGroup(L"Nest child");
+        group2->SetLegendLabel(L"Nest child (Nest top level)");
+        group2->SetDisplayInLegend(true);
+        group2->SetGroup(group1);
+        layerGroups->Add(group2);
+
+        Ptr<MgLayerGroup> group3 = new MgLayerGroup(L"Not visible in legend");
+        group3->SetLegendLabel(L"Not visible in legend");
+        group3->SetDisplayInLegend(false);
+        layerGroups->Add(group3);
+
         Ptr<MgLayer> layer = new MgLayer(resId, m_svcResource);
-        layer->SetName(L"MyParcels");
-        layer->SetLegendLabel(L"Parcels");
+        layer->SetName(L"HydroPolygons");
+        layer->SetLegendLabel(L"HydroPolygons (Test Group)");
         layer->SetGroup(group);
         layer->SetDisplayInLegend(true);
 
+        Ptr<MgLayer> layer2 = new MgLayer(ldfRail, m_svcResource);
+        layer2->SetName(L"RailUnderNestedGroup");
+        layer2->SetLegendLabel(L"Rail (Nest Child)");
+        layer2->SetGroup(group2);
+        layer2->SetDisplayInLegend(true);
+
         layers->Add(layer);
+        layers->Add(layer2);
 
         //Re-draw at 75k. Layer group should not be there because it has no visible layers
         map->SetViewScale(75000.0);



More information about the mapguide-commits mailing list