ThinkGeo.com    |     Documentation    |     Premium Support

Not able to see effect of overridden DrawLine method

Hi


I have created one  CustomLineStyle class deriving from LineStyle and override the DrawLine method. Buit when I call DrawLine method I cannot see the line I want to draw.


Code is as follows


 


public class CustomArrowLineStyle : LineStyle
    {
protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            foreach (Feature f in features)
            {
                
                if (f.GetShape().GetType() == typeof(LineShape))
                {
                    LineShape ln = (LineShape)f.GetShape();
                    canvas.DrawLine(ln, new GeoPen(new GeoSolidBrush(GeoColor.SimpleColors.Black), 5));
                }
            }
 
            
   } 
   }
 
I am creating style as:
CustomArrowLineStyle speedAndHeadingLineStyle = new CustomArrowLineStyle();
         
            speedAndHeadingLineStyle.OuterPen = new GeoPen(new GeoColor(0, 0, 0), 5);
            speedAndHeadingLineStyle.InnerPen = new GeoPen(new GeoColor(0, 0, 0), 0);
            speedAndHeadingLineStyle.CenterPen = new GeoPen(new GeoColor(0, 0, 0), 4);
            speedAndHeadingLineStyle.CenterPen.EndCap = GeoDashCap.Triangle;
            speedAndHeadingLineStyle.OuterPen.EndCap = GeoDashCap.Triangle;
 
MemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(speedAndHeadingLineStyle);
MemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
 And Creating line at run time as:
 LineShape line = new LineShape();
            line.Vertices.Add(point);
            line.Vertices.Add(point2);
            Feature lineFeature = new Feature(line);
            MemoryFeatureLayer.InternalFeatures.Add(update.DisplayElementKey + "speed", lineFeature);

But when I run the code, code gets executed properly but does not display line.


Do I have to do anything additionaly.


Thanks


Sunil



 


Hi, Sunil
Thanks for your provided information about your problem. There are some problems for your custom line style. I have modified it base on your codes, please refer to it.


    public class CustomArrowLineStyle : LineStyle
    {
        protected override void DrawCore(System.Collections.Generic.IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            List<Feature> featuresList = new List<Feature>(features);
 
            for (int i = 0; i < featuresList.Count; i++)
            {
                WellKnownType shapeWellKnownType = featuresList[i].GetWellKnownType();
                if (shapeWellKnownType != WellKnownType.Line && shapeWellKnownType != WellKnownType.Multiline)
                { continue; }
 
                canvas.DrawLine(featuresList[i], this.OuterPen, XOffsetInPixel, YOffsetInPixel);
                canvas.DrawLine(featuresList[i], this.InnerPen, XOffsetInPixel, YOffsetInPixel);
                canvas.DrawLine(featuresList[i], this.CenterPen, XOffsetInPixel, YOffsetInPixel);
            }
        }
    }



Thanks,
Khalil