ThinkGeo.com    |     Documentation    |     Premium Support

How to draw features based on values in InMemoryFeatureLayer?

Hi all,


From DrawFeaturesBasedOnValues sample I learned how to do this in ShapFileFeatureLayer. But it seems don't work in InMemoryFeatureLayer. Please help me with this problem.


Best regards,


Feng



 Feng,


Here is the code what you want below:


 



winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

            winformsMap1.CurrentExtent = new RectangleShape(0, 100, 100, 0);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.White);

            InMemoryFeatureLayer inMemoryLayer = new InMemoryFeatureLayer();
            inMemoryLayer.FeatureSource.Open();
            inMemoryLayer.Columns.Add(new FeatureSourceColumn("Name"));
            inMemoryLayer.Close();
            Dictionary<string, string> columnValuesForPolygon = new Dictionary<string, string>();
            columnValuesForPolygon.Add("Name", "Polygon");
            Dictionary<string, string> columnValuesForMultiPoint = new Dictionary<string, string>();
            columnValuesForMultiPoint.Add("Name", "MultiPoint");
            Dictionary<string, string> columnValuesForLine = new Dictionary<string, string>();
            columnValuesForLine.Add("Name", "Line");
            Dictionary<string, string> columnValuesForRectangle = new Dictionary<string, string>();
            columnValuesForRectangle.Add("Name", "Rectangle");

            ValueStyle valueStyle = new ValueStyle();
            valueStyle.ColumnName = "Name";
            valueStyle.ValueItems.Add(new ValueItem("Polygon", AreaStyles.Country1));
            valueStyle.ValueItems.Add(new ValueItem("MultiPoint", PointStyles.Capital3));
            valueStyle.ValueItems.Add(new ValueItem("Line", LineStyles.Highway1));
            valueStyle.ValueItems.Add(new ValueItem("Rectangle", AreaStyles.Country2));
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
            inMemoryLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            inMemoryLayer.InternalFeatures.Add("Polygon", new Feature(BaseShape.CreateShapeFromWellKnownData("POLYGON((10 60,40 70,30 85, 10 60))"), columnValuesForPolygon));
            inMemoryLayer.InternalFeatures.Add("Multipoint", new Feature(BaseShape.CreateShapeFromWellKnownData("MULTIPOINT(10 20, 30 20,40 20, 10 30, 30 30, 40 30)"), columnValuesForMultiPoint));
            inMemoryLayer.InternalFeatures.Add("Line", new Feature(BaseShape.CreateShapeFromWellKnownData("LINESTRING(60 60, 70 70,75 60, 80 70, 85 60,95 80)"), columnValuesForLine));
            inMemoryLayer.InternalFeatures.Add("Rectangle", new Feature(new RectangleShape(65, 30, 95, 15), columnValuesForRectangle));

            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("InMemoryFeatureLayer", inMemoryLayer);
            winformsMap1.Overlays.Add("InMemoryOverlay", staticOverlay);

            winformsMap1.Refresh();
  So you can realize how to draw the features with ValueStyle for InMemoryFeaturelayer,   Any more questions please let us know,


Thanks,


Scott,