User Tools

Site Tools


source_code_serviceseditionsample_imagestyle_cs_120209.zip

Source Code ServicesEditionSample ImageStyle CS 120209.zip

App.xaml.cs

 using System;  
 using System.Collections.Generic;  
 using System.Configuration;  
 using System.Data;  
 using System.Linq;  
 using System.Windows;  
 
 namespace ImageStyle  
 {  
     /// <summary>  
     /// Interaction logic for App.xaml  
     /// </summary>  
     public partial class App : Application  
     {  
     }  
 }  
 

CustomImageStyle.cs

 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace ImageStyle  
 {  
     class ImageAreaStyle : Style  
     {  
         private GeoImage geoImage = null;  
 
          public ImageAreaStyle(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);  
                 }  
             }  
         }  
 
     }  
 
     class ImageLineStyle : Style  
     {  
          private GeoImage geoImage = null;  
          private int lineWidth;  
 
         public ImageLineStyle(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();  
 
                 //We Get the distance in world coordinate to always have the same width of the line in screen coordinate regardless of the zoom level  
                 double worldDistance = ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(canvas.CurrentWorldExtent, new ScreenPointF(0, 0), new ScreenPointF(lineWidth, 0), canvas.Width,  
                        canvas.Height, canvas.MapUnit, DistanceUnit.Meter);  
 
                 if (shapeWellKnownType == WellKnownType.Line)  
                 {  
                     LineShape lineShape = new LineShape(feature.GetWellKnownBinary());  
                     //We get the buffer of the lineShape so that we can fill it with the GeoImage  
                     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());  
                     //We get the buffer of the multiLineShape so that we can fill it with the GeoImage  
                     MultipolygonShape multiPolygonShapeBuffer = multilineShape.Buffer(worldDistance, canvas.MapUnit, DistanceUnit.Meter);  
                     canvas.DrawArea(multiPolygonShapeBuffer, new GeoTextureBrush(geoImage), DrawingLevel.LevelOne);  
                 }  
             }  
         }  
     }  
 }  
 

TestWindow.xaml.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Text;  
 using System.IO;  
 using System.Windows;  
 using System.Windows.Controls;  
 using System.Windows.Data;  
 using System.Windows.Documents;  
 using System.Windows.Input;  
 using System.Windows.Media;  
 using System.Windows.Media.Imaging;  
 using System.Windows.Shapes;  
 using System.Collections.ObjectModel;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace ImageStyle  
 {  
     /// <summary>  
     /// Interaction logic for TestWindow.xaml  
     /// </summary>  
     public partial class TestWindow : Window  
     {  
         public TestWindow()  
         {  
             InitializeComponent();  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             //Sets the correct map unit and the extent of the map.  
             wpfMap1.MapUnit = GeographyUnit.DecimalDegree;  
             wpfMap1.CurrentExtent = new RectangleShape(-96.982,32.7925,-96.9657,32.7808);  
             BackgroundOverlay backGroundOverlay = new BackgroundOverlay();  
             backGroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGoldenrodYellow);  
             wpfMap1.BackgroundOverlay = backGroundOverlay;  
 
             ShapeFileFeatureLayer waterLayer = new ShapeFileFeatureLayer(@"..\..\Data\Water.shp");  
             ImageAreaStyle waterImageAreaStyle = new ImageAreaStyle(new GeoImage(@"..\..\Data\Water.png"));  
             waterLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(waterImageAreaStyle);  
             waterLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             ShapeFileFeatureLayer forestLayer = new ShapeFileFeatureLayer(@"..\..\Data\Forest.shp");  
             ImageAreaStyle forestImageAreaStyle = new ImageAreaStyle(new GeoImage(@"..\..\Data\Forest.png"));  
             forestLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(forestImageAreaStyle);  
             forestLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer(@"..\..\Data\Roads.shp");  
             ImageLineStyle streetLineAreaStyle = new ImageLineStyle(new GeoImage(@"..\..\Data\Pavement.png"),3);  
             streetLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(streetLineAreaStyle);  
 
             TextStyle textStyle = new TextStyle("name", new GeoFont("Arial", 10), new GeoSolidBrush(GeoColor.StandardColors.Maroon));  
             textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 3);  
             streetLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);  
 
             streetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             LayerOverlay staticOverlay = new LayerOverlay();  
             staticOverlay.Layers.Add(waterLayer);  
             staticOverlay.Layers.Add(forestLayer);  
             staticOverlay.Layers.Add(streetLayer);  
 
             wpfMap1.Overlays.Add(staticOverlay);  
 
             wpfMap1.Refresh();  
         }  
 
 
         private void wpfMap1_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Gets the PointShape in world coordinates from screen coordinates.  
             Point point = e.MouseDevice.GetPosition(null);  
 
             ScreenPointF screenPointF = new ScreenPointF((float)point.X, (float)point.Y);  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, screenPointF, (float)wpfMap1.Width, (float)wpfMap1.Height);  
 
             textBox1.Text = "X: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.X) +  
                           "  Y: " + DecimalDegreesHelper.GetDegreesMinutesSecondsStringFromDecimalDegree(pointShape.Y);  
         }  
     }  
 }  
 
source_code_serviceseditionsample_imagestyle_cs_120209.zip.txt · Last modified: 2015/09/08 08:01 by admin