ThinkGeo.com    |     Documentation    |     Premium Support

Add ValueStyle to Legend Adornment Layer

Hello,


I try to display a CustomStyle, format  ValueStyle, in the Legend Adorment Layer (Community Code).


I manage to loop through the items in ValueStyle (DrawLegend), but I have problems to properly align each item.


Someone already working on this subject?

Thank you.



 legendBitmap = New Bitmap(CInt(m_legendIconWidth), CInt(m_legendIconHeight))
            legendCanvas.BeginDrawing(legendBitmap, New RectangleShape(0, m_legendIconWidth, m_legendIconHeight, 0), GeographyUnit.Meter)
            layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.DrawSample(legendCanvas)
            layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.DrawSample(legendCanvas)
            layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.DrawSample(legendCanvas)
            For i As Integer = 0 To layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Count - 1
                Dim customStyle As Style = layer.ZoomLevelSet.ZoomLevel01.CustomStyles(i)

                Dim valueStyle As ValueStyle = TryCast(customStyle, ValueStyle)
                If valueStyle IsNot Nothing Then
                    For j As Integer = 0 To valueStyle.ValueItems.Count - 1
                        
<<< Calculate the x offset and y offset >>>

                        valueStyle.DrawSample(legendCanvas)
                        
                    Next
                Else
                    customStyle.DrawSample(legendCanvas)
                End If

            Next



In the project Legend Adornment Layer, you can find the logic for offsetting the different items in the function DrawCore. You can see how the variable yOffsetInAll is updated in the loop. I don't see anything like that in your code.


 



 protected override void DrawCore(GeoCanvas canvas, Collection<SimpleCandidate> labelsInAllLayers)
        {
            float yOffsetInAll = YOffsetInPixel;

           
            GeoFont font = new GeoFont("Arial", 10, DrawingFontStyles.Regular);
            GeoFont font1 = new GeoFont("Arial", 10, DrawingFontStyles.Bold);

            for (int i = 0; i < drawingOverlays.Count; i++)
            {
                // Draw the overlay's name.
                DrawingRectangleF rectangle = canvas.MeasureText(drawingOverlays[i].Name, font);
                DrawText(canvas, XOffsetInPixel + rectangle.Width / 2, yOffsetInAll + rectangle.Height / 2, font1, drawingOverlays[i].Name);

                // Update y offset.
                yOffsetInAll += (rectangle.Height + 2);

                for (int j = 0; j < drawingOverlays[i].Layers.Count; j++)
                {
                    FeatureLayer currentLayer = drawingOverlays[i].Layers[j] as FeatureLayer;
                    if (currentLayer != null)
                    {
                        if (currentLayer.Name != "")
                        {
                            // Calculate the x offset and y offset, then draw legend.
                            DrawLegend(canvas, currentLayer, XOffsetInPixel + indent + legendIconWidth / 2, yOffsetInAll + legendIconHeight / 2);

                            DrawingRectangleF layerRectangle = canvas.MeasureText(drawingOverlays[i].Layers[j].Name, font);
                            DrawText(canvas, XOffsetInPixel + legendIconWidth + indent + layerRectangle.Width / 2 + 5, yOffsetInAll + layerRectangle.Height / 2, font, drawingOverlays[i].Layers[j].Name);

                            // Update y offset.
                            yOffsetInAll += (rectangle.Height + 2);
                        }
                    }
                }
            }
            
            
        }