ThinkGeo.com    |     Documentation    |     Premium Support

Changing style of each feature in trackshapelayer

I currently add points, lines, and polygons to the trackshapelayer programatically. How would I go about making each of those shapes in the same layer have their own style? The end goal is to have the user be able to select the color/font of the shapes/labels.

Hi Dan,

You can set the layer styles base on the feature type, it means that all the line feature will be same style. Points/Polygons can be other styles.

If you want to set each feature to different style. that’s every special requirements. It is not easy to implement, you can consider use value style. I am not sure if I catch your meanings.

We created one simple to show you how to use value style to change the selected feature color. you can get some idea in your projects.

If you need any more information, please feel free to let us know that.

TrackShapeLayerTest.zip (12.4 KB)

Thanks
Mark

I think that’s what I want, but I’m still not sure how to implement that exactly. So I’m using your code in the Map_Loaded like so:

var valueStyle1 = new ValueStyle();
valueStyle1.ColumnName = "id";
valueStyle1.ValueItems.Add(new ValueItem("4", new AreaStyle(new GeoSolidBrush(GeoColor.SimpleColors.Blue))));
valueStyle1.ValueItems.Add(new ValueItem("3", new LineStyle(new GeoPen(GeoColor.SimpleColors.Red, 2.0f))));
valueStyle1.ValueItems.Add(new ValueItem("2", new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.Blue), 20)));
valueStyle1.ValueItems.Add(new ValueItem("1", new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.Green), 20)));

Then when I go to add a point like this:

Vertex point = new Vertex(longitude, latitude);
Feature feature = new Feature(new PointShape(point), new Dictionary<string, string>(){ { "id", "2"} });
feature.ColumnValues.Add(label, label);

mapModel.Map.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle(label, "aerial", 12, DrawingFontStyles.Bold, GeoColors.Red);
mapModel.Map.TrackOverlay.TrackShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle.IsActive = true;
mapModel.Map.TrackOverlay.TrackShapeLayer.InternalFeatures.Add(feature);
mapModel.Map.Refresh(mapModel.Map.TrackOverlay);

I get the error:

You are trying to use both a default style and the custom styles collection.  You may only use one or the other.

Shouldn’t it be using the custom style since the feature’s columns has an “id” column which corresponds to

valueStyle1.ValueItems.Add(new ValueItem("2", new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.SimpleColors.Blue), 20)));

Wait I think I got it, I had to get rid of the DefaultTextStyle and replace it with a Custom Style as well.

Hi Dan,

So does that solve your problem?

Any question please let us know.

Regards,

Ethan

Yup seems to work fine now! Thank you!

Hi Dan,

I am glad to hear that works.

Any question please let us know.

Regards,

Ethan