ThinkGeo.com    |     Documentation    |     Premium Support

Rotation of points using PointType.Character

I’m trying to override the DrawCore function of a custom style that is using PointType.Character to rotate the characters. I know there’s a RotationAngle property, but I need to set it differently for each feature using this style. I tried doing it like the ScalingImageStyleModel, but that was using canvas.DrawWorldImage function. I don’t see a draw function for PointType.Character though.

The angle would be given from a columvalue of the features using the style. Specifically this:

feature.ColumnValues["Angle"]

The custom font style is set up with this constructor:

public FontPointStyleModel(string name, int symbolType, string hexColor, int size, string fontName, int characterIndex)
{
       Color = GeoColor.FromHtml("#" + hexColor);
       Size = size;
       this.Name = name;
       this.PointType = PointType.Character;
       this.CharacterFont.FontName = fontName;
       this.CharacterIndex = characterIndex;
       this.CharacterFont.Size = Size;
       this.CharacterSolidBrush = new GeoSolidBrush(Color);
}

I got this working. Not sure if it’s the best way but it works.

In my custom point style class:

//constructor
public FontPointStyleModel(string name, int symbolType, string hexColor, int size, string fontName, int characterIndex)
{
    Color = GeoColor.FromHtml("#" + hexColor); //hexColor will always be a 6 characters long
    Size = size;
    this.Name = name; //name of the style
    this.PointType = PointType.Character; //Set this pointstyle's type to character
    this.CharacterFont.FontName = fontName; //fontName is the font family the character will be found in
    this.CharacterIndex = characterIndex; //this is the index the character is found at in the font family
    this.CharacterFont.Size = Size; //font size
    this.CharacterSolidBrush = new GeoSolidBrush(Color);
}

protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
{
    foreach (Feature feature in features)
    {
        float rotation;

        if (!feature.ColumnValues.ContainsKey("Angle")) //if there is NOT a column called 'Angle' in the feature
        {
            rotation = 0; //don't rotate
        }
        else
        {
            rotation = (float)Convert.ToDouble(feature.ColumnValues["Angle"]); //otherwise rotate it
        }
        PointShape location = (PointShape)feature.GetShape(); //get the pointshape from the feature
        string text = Convert.ToChar(CharacterIndex).ToString(); //gets the character to draw

        //determines where to actually draw the point
        ScreenPointF locationInScreen = ExtentHelper.ToScreenCoordinate(canvas.CurrentWorldExtent, location, canvas.Width, canvas.Height);
        Collection<ScreenPointF> textPathInScreen = new Collection<ScreenPointF> { locationInScreen };

        //draw to the map
        canvas.DrawText(text, new GeoFont(this.CharacterFont.FontName, this.Size, DrawingFontStyles.Regular, DrawingGraphicsUnit.Point), this.CharacterSolidBrush, new GeoPen(), textPathInScreen, DrawingLevel.LevelOne, 0, 0, rotation);
    }
}

Hi Dan,

Thanks for your share, override the DrawCore is the best solution for that.

Regards,

Ethan