ThinkGeo.com    |     Documentation    |     Premium Support

Can't use CustomStyle in a legend

I am having a problem displaying a CustomStyle in a legend. I am using the last posted sample LegendAdornmentLayer found in this forum.


gis.thinkgeo.com/Support/Dis...fault.aspx


I altered the sample's DrawCore function to account for CustomStyles. The problem being it seems that the CustomStyle.DrawSample() is not drawing the icon I am using and results in a blank bitmap. I know the custom style is good as it draws on the map, just not on the legend.


Code from LegendAdornementLayer.DrawCore


legendBitmap = new Bitmap((int)legendIconWidth, (int)legendIconHeight);

legendCanvas.BeginDrawing(legendBitmap, new RectangleShape(0, legendIconWidth, legendIconHeight, 0), GeographyUnit.DecimalDegree);


layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.DrawSample(legendCanvas);

layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.DrawSample(legendCanvas);

layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.DrawSample(legendCanvas);

for (int i = 0; i < layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Count; i++)

{

     layer.ZoomLevelSet.ZoomLevel01.CustomStyles.DrawSample(legendCanvas);


}


I create my CustomStyle using the sample RotagedImageStyle Class found in the projects.


RotatedImageStyle rotatedImageStyle = new RotatedImageStyle(new GeoImage(stream), "Angle");

pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Clear();

pointLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(rotatedImageStyle);

pointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;


Any reason I can't use custom styles in my legend. Any feedback is greatly appreciated.


Eric



Eric, 
  
 Where is the RotagedImageStyle from? I think this style is written by you or you have source code of it, so can you check if this style override the DrawSampleCore method or not, if you want to use this style to LegendAdornementLayer, the DrawSample method will be called in DrawCore of LegendLayer, you can look at the code you provide. 
  
 So there are solutions, one is override DrawSampleCore of RotagedImageStyle and write the code to show your image. The other one is update the DrawCore of LegendAdornementLayer and make it can show your image. 
   
 Please let me know if the problem is not this. 
  
 Thanks 
  
 James

James,


The RotatedImageStyle was provided by the Project "Rotated Image Style"


code.thinkgeo.com/projects/show/3


No it does not override DrawCoreSample. Not sure what I would do in an override.


I did try to update the LegendAdornmentLayer DrawLegend, which is called by DrawCore, to account for the CustomStyle as illustrated in my previous post.


Code from LegendAdornementLayer.DrawLegend

l

egendBitmap = new Bitmap((int)legendIconWidth, (int)legendIconHeight);

legendCanvas.BeginDrawing(legendBitmap, new RectangleShape(0, legendIconWidth, legendIconHeight, 0), GeographyUnit.DecimalDegree);


layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.DrawSample(legendCanvas);

layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.DrawSample(legendCanvas);

layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.DrawSample(legendCanvas);

for (int i = 0; i < layer.ZoomLevelSet.ZoomLevel01.CustomStyles.Count; i++)

{

     layer.ZoomLevelSet.ZoomLevel01.CustomStyles.DrawSample(legendCanvas);

}




CustomStyles.DrawSample(legendCanvas) results in an empty bitmap.




Here is the RotatedImageStyle I am using.


public class RotatedImageStyle : Style

 {

        private GeoImage geoImage;

        private string angleColumnName;

        public RotatedImageStyle()

            : this(new GeoImage(), string.Empty)

        { }

        public RotatedImageStyle(GeoImage geoImage, string angleColumnName)

        {

            this.geoImage = geoImage;

            this.angleColumnName = angleColumnName;

        }

        public GeoImage GeoImage

        {

            get { return geoImage; }

            set { GeoImage = value; }

        }

        public string AngleColumnName

        {

            get { return angleColumnName; }

            set { AngleColumnName = value; }

        }

        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)

        {

            foreach (Feature feature in features)

            {

                float angleData = Convert.ToSingle(feature.ColumnValues[angleColumnName]);

                PointShape pointShape = (PointShape)feature.GetShape();

                canvas.DrawWorldImageWithoutScaling(geoImage, pointShape.X, pointShape.Y, DrawingLevel.LevelFour, 0, 0, 360 - angleData); //angleData);

            }

        }

}


Not sure how to proceed with your suggestions. Any Help? Thanks!


Eric


 



James,


I managed to figure this out. You set me on the right path with overriding the DrawSampleCore of my custom style. It took one line of code.


protected override void DrawSampleCore(GeoCanvas canvas)

{

            

     canvas.DrawScreenImage(geoImage, canvas.Width / 2, canvas.Height / 2,canvas.Width,canvas.Height, DrawingLevel.LevelOne, 0, 0, 0);

            

}


where geoImage is the stored image in my custom class illustrated in my previous post.


Thanks for pointing me in the right direction.


Eric


 


 



Eric,  
  
 James is on vocation and will be back in a week. It’s great you figure it out yourself!  
  
 Let us know for any new questions. 
  
 Ben