ThinkGeo.com    |     Documentation    |     Premium Support

Create custom color for polygon

Hi ,


By using InMemoryFeatureLayer, i can create multiple shape like polygon and Ellipse. Can i set each of the polygon and ellipse as different color by using same InMemoryFeatureLayer? If yes, how?



mapShapeLayer.InternalFeatures.Add(



"AreaShape1", new Feature(BaseShape.CreateShapeFromWellKnownData("POLYGON((-10 40,40 70,50 0,-10 40))")));"AreaShape2", new Feature(new EllipseShape(new PointShape(-70, -20), 10, 20)));

 



mapShapeLayer.InternalFeatures.Add(



Bv,


Thanks for your post and questions!
 
Up to now, the style set the inmemoryFeatureLayer should be applied to all features, you could not set each feature different styles as you said.
 
If you are interested, please take a look at the following project, it probably helps.
 
code.thinkgeo.com/projects/show/mapshapes
 
Any more questions just let me know.
 
Thanks.
 
Yale

bv,


You can use ValueStyle to do this.  Please have a look at the code below.



           InMemoryFeatureLayer mapShapeLayer = new InMemoryFeatureLayer();
            // Add one column "Style" to the feature source
            mapShapeLayer.Open();
            mapShapeLayer.Columns.Add(new FeatureSourceColumn("Style"));
            mapShapeLayer.Close();

            // Create 2 features with the "Style" columns.
            Feature feature1 = new Feature(BaseShape.CreateShapeFromWellKnownData("POLYGON((-10 40,40 70,50 0,-10 40))"));
            feature1.ColumnValues["Style"] = "Blue";
            Feature feature2 = new Feature(new EllipseShape(new PointShape(-70, -20), 10, 20));
            feature2.ColumnValues["Style"] = "Yellow";

            mapShapeLayer.InternalFeatures.Add("AreaShape1", feature1);
            mapShapeLayer.InternalFeatures.Add("AreaShape2", feature2);

            // Create a ValueStyle, render differently based on the "Style" Column
            ValueStyle valueStyle = new ValueStyle();
            valueStyle.ColumnName = "Style";
            valueStyle.ValueItems.Add(new ValueItem("Blue", AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Blue)));
            valueStyle.ValueItems.Add(new ValueItem("Yellow", AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Yellow)));

            mapShapeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
            mapShapeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            Map1.StaticOverlay.Layers.Add(mapShapeLayer);


Also if you are interested, you can create your own MapShape Layer to make it simple, here is how to do it.

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


Thanks,


Ben