ThinkGeo.com    |     Documentation    |     Premium Support

Get a feature's column value from within custom point style

Hi ,

I have a custom point style that needs to change the style based on a feature column values.

The problem is the feature passed down in to custom style do not have any column values.

How to get the column values?

The code:

public class PolePointstyle : ThinkGeo.MapSuite.Styles.PointBaseStyle
{     

    protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
    {
        foreach (Feature feature in features)
        {
            PointStyle style = GetPointStyle(feature);
            style.Draw(new Collection<Feature>() { feature }, canvas, labelsInThisLayer, labelsInAllLayers);
        }
    }

    private PointStyle GetPointStyle(Feature feature)
    {
        bool hasPanel;
        bool.TryParse(feature.ColumnValues["has_panel"].ToString(), out hasPanel);          
        var poleStyle = hasPanel? PointStyles.CreateSimpleTriangleStyle(GeoColor.StandardColors.Red, 10, GeoColor.StandardColors.Black, 1) : PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Blue, 10, GeoColor.StandardColors.Black, 1);       
        /*Other processing */
        return poleStyle;
    }
}

Hi Yohan,

In fact your code works well.

Please try attached sample: 9114.zip (101.4 KB)

Regards,

Ethan

Hi Ethan,

I ended up using ValueStyles to set the point styles.

It is working fine now.

However I 've found another problem when saving edits. I’ll put it in a new thread

Hi Yohan,

Any question please let us know.

Regards,

Ethan