ThinkGeo.com    |     Documentation    |     Premium Support

Is there any way to make areastyle and linestyle from image?

 hi hi hi dears


you know there is :


new PointStyle(new GeoImage(imgpath));


we can use images as point styles but for line and polygons no defined api 


is there alternate way to do that or it's impossible?


thanks


 


another question:


how can minimize overlayswitcher at startup page?


 


best regards


 



Hossein,


  It is possible to use a GeoImage for Styles to represent polygon based features but you will need to create a custom style. Below in the code, you can see the custom ImageStyle taking a GeoImage. You can also see in the capture where I use an image of a forest to represent some polygons. This can also be done for line based features but this is going to require some more work. I will contact you back when I that solution. Thank you.



 


 



InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
ImageStyle imageStyle = new ImageStyle(new GeoImage(@"C:\ThinkGeo\Support\Posts\10037\Forest.png"));
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(imageStyle); 
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

   class ImageStyle : Style
    {
         private GeoImage geoImage = null;

        public ImageStyle(GeoImage geoImage)
        {
            this.geoImage = geoImage;
        }

        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
        {
            // Loop through all of the features being passed in to draw.
            foreach (Feature feature in features)
            {
                WellKnownType shapeWellKnownType = feature.GetWellKnownType();
                if (shapeWellKnownType == WellKnownType.Polygon) 
                {
                    PolygonShape polygonShape = new PolygonShape(feature.GetWellKnownBinary());
                    canvas.DrawArea(polygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);

                }
                else if (shapeWellKnownType == WellKnownType.Multipolygon)
                {
                    MultipolygonShape multiPolygonShape = new MultipolygonShape(feature.GetWellKnownBinary());
                    canvas.DrawArea(multiPolygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
                }
            }
        }
    }



Hossein,


 I extented the class ImageStyle so that it can handle having an Image for representing line based feature. You can see the result in the screen shot below. I use an actual image of a pavement to draw my streets. Keep in mind that this is a fairly intensive operation and that ImageStyle should be limited to the lower zoom levels to avoid performance issues. Also you can see the new code for ImageStyle.




wpfMap1.MapUnit = GeographyUnit.DecimalDegree;

ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer(@"C:\ThinkGeo\Support\MapData\Austinstreets.shp");

ImageStyle imageStyle = new ImageStyle(new GeoImage(@"C:\ThinkGeo\Support\Posts\10037\Pavement.png"), 5);
TextStyle textStyle = new TextStyle("FENAME", new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.StandardColors.Maroon));
textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 3);
           
streetLayer.ZoomLevelSet.ZoomLevel18.CustomStyles.Add(imageStyle);
streetLayer.ZoomLevelSet.ZoomLevel18.CustomStyles.Add(textStyle);
streetLayer.ZoomLevelSet.ZoomLevel18.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
streetLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new LineStyle(new GeoPen(GeoColor.StandardColors.DarkGray,3)));
streetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level17;

LayerOverlay layerOverlay = new LayerOverlay();
layerOverlay.TileType = TileType.SingleTile;
layerOverlay.Layers.Add(streetLayer);

wpfMap1.Overlays.Add(layerOverlay);

streetLayer.Open();
wpfMap1.CurrentExtent = new RectangleShape(-97.7231, 30.2752, -97.7212, 30.2740);   
streetLayer.Close();


 class ImageStyle : Style
    {
         private GeoImage geoImage = null;
         private int lineWidth;

        public ImageStyle(GeoImage geoImage, int lineWidth)
        {
            this.geoImage = geoImage;
            this.lineWidth = lineWidth;
        }

        protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
        {
            // Loop through all of the features being passed in to draw.
            foreach (Feature feature in features)
            {
                WellKnownType shapeWellKnownType = feature.GetWellKnownType();
                if (shapeWellKnownType == WellKnownType.Polygon) 
                {
                    PolygonShape polygonShape = new PolygonShape(feature.GetWellKnownBinary());
                    canvas.DrawArea(polygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);

                }
                else if (shapeWellKnownType == WellKnownType.Multipolygon)
                {
                    MultipolygonShape multiPolygonShape = new MultipolygonShape(feature.GetWellKnownBinary());
                    canvas.DrawArea(multiPolygonShape, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
                }
                else if (shapeWellKnownType == WellKnownType.Line)
                {
                    LineShape lineShape = new LineShape(feature.GetWellKnownBinary());
                    double worldDistance = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(canvas.CurrentWorldExtent, new ScreenPointF(0,0),new ScreenPointF(lineWidth,0),canvas.Width,
                        canvas.Height,canvas.MapUnit,DistanceUnit.Meter);
                     MultipolygonShape multiPolygonShapeBuffer = lineShape.Buffer(worldDistance, canvas.MapUnit, DistanceUnit.Meter);
                     canvas.DrawArea(multiPolygonShapeBuffer, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
                }
                else if (shapeWellKnownType == WellKnownType.Multiline)
                {
                    MultilineShape multilineShape = new MultilineShape(feature.GetWellKnownBinary());
                    double worldDistance = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(canvas.CurrentWorldExtent, new ScreenPointF(0, 0), new ScreenPointF(lineWidth, 0), canvas.Width,
                        canvas.Height, canvas.MapUnit, DistanceUnit.Meter);
                    MultipolygonShape multiPolygonShapeBuffer = multilineShape.Buffer(worldDistance, canvas.MapUnit, DistanceUnit.Meter);
                    canvas.DrawArea(multiPolygonShapeBuffer, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);
                }
            }
        }
    }



Hello!


This is to inform everybody that a sample project in relation to this post was added recently to the Code Community in ThinkGeo Wiki. The sample, ImageStyle, can be found a the following link:


wiki.thinkgeo.com/wiki/Map_Suite_Wp...mage_Style