====== Source Code ServicesEditionSample RegisterShape CS 100128.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace RegisterShape { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new TestForm()); } } } ====TestForm.cs==== using System; using System.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using System.IO; using ThinkGeo.MapSuite.Core; namespace RegisterShape { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; private MapEngine mapEngine2 = new MapEngine(); private Bitmap bitmap2 = null; const double ISOLATIONZONE_RADIUS = 300; const double PROTECTIONZONE_WIDTH = 2500; EllipseShape ellipseShape = null; PolygonShape polygonShape = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the extent and the background color for the map in meters using Spherical Mercator projection. mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-10608131,4721054,-10602691,4714837), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); worldMapKitLayer.Projection = WorldMapKitProjection.SphericalMercator; mapEngine.StaticLayers.Add(worldMapKitLayer); //Sets the extent in meters for our chemical model (floating in space). mapEngine2.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(0,4000,4000,0), Map2.Width, Map2.Height); //Add the dynamic layers to the MapEngine. //We are using an example from ERG (Emergency Response Guide)from the US department of Transportation. We take the example of a small spill of phosgene //chemical during the day (300 ft of radius of isolation zone and and area of 0.4 miles of width for the protection zone). //See the website for more info: http://www.phmsa.dot.gov/ InMemoryFeatureLayer inMemoryFeatureLayer2 = new InMemoryFeatureLayer(); inMemoryFeatureLayer2.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.Transparent, GeoColor.StandardColors.Black, 2); inMemoryFeatureLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine2.DynamicLayers.Add(inMemoryFeatureLayer2); //Builds the Isolation zone. Circle of 300 feet of radius from the source. ellipseShape = new EllipseShape(new PointShape(2000, 500), ISOLATIONZONE_RADIUS); //Builds the Protection zone. Area of 2500 feet of width. polygonShape = new PolygonShape(); polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center.X - (PROTECTIONZONE_WIDTH / 2), ellipseShape.Center.Y + PROTECTIONZONE_WIDTH)); polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center.X + (PROTECTIONZONE_WIDTH / 2), ellipseShape.Center.Y + PROTECTIONZONE_WIDTH)); polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center.X + (PROTECTIONZONE_WIDTH / 2), ellipseShape.Center.Y)); polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center.X - (PROTECTIONZONE_WIDTH / 2), ellipseShape.Center.Y)); polygonShape.OuterRing.Vertices.Add(new Vertex(ellipseShape.Center.X - (PROTECTIONZONE_WIDTH / 2), ellipseShape.Center.Y + PROTECTIONZONE_WIDTH)); inMemoryFeatureLayer2.InternalFeatures.Add(new Feature(ellipseShape)); inMemoryFeatureLayer2.InternalFeatures.Add(new Feature(polygonShape)); //Adds Scale line to the maps. ScaleLineAdornmentLayer scaleLineAdornmentLayer = new ScaleLineAdornmentLayer(); scaleLineAdornmentLayer.Location = AdornmentLocation.LowerLeft; mapEngine.AdornmentLayers.Add(scaleLineAdornmentLayer); mapEngine2.AdornmentLayers.Add(scaleLineAdornmentLayer); DrawImage(); DrawImage2(); } private void btnRegister_Click(object sender, EventArgs e) { //Location in X and Y for the destination point on the Spherical Mercator map. double Xregister = -10605639; double Yregister = 4717137; //Registers the shapes to the Spherical Mercator map. EllipseShape registeredEllipseShape = (EllipseShape)ellipseShape.Register(ellipseShape.Center, new PointShape(Xregister, Yregister), DistanceUnit.Meter, GeographyUnit.Meter); PolygonShape registeredPolygonShape = (PolygonShape)polygonShape.Register(ellipseShape.Center, new PointShape(Xregister, Yregister), DistanceUnit.Meter, GeographyUnit.Meter); //Adds the registered shapes to InMemoryFeatureLayers. InMemoryFeatureLayer inMemoryFeatureLayer1 = new InMemoryFeatureLayer(); inMemoryFeatureLayer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHatchStyle(GeoHatchStyle.Percent20, GeoColor.StandardColors.Orange, GeoColor.FromArgb(100, GeoColor.StandardColors.Yellow)); inMemoryFeatureLayer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; inMemoryFeatureLayer1.InternalFeatures.Add(new Feature(registeredEllipseShape)); mapEngine.DynamicLayers.Add(inMemoryFeatureLayer1); InMemoryFeatureLayer inMemoryFeatureLayer2 = new InMemoryFeatureLayer(); inMemoryFeatureLayer2.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHatchStyle(GeoHatchStyle.Percent05, GeoColor.StandardColors.Orange, GeoColor.FromArgb(150, GeoColor.StandardColors.Orange)); inMemoryFeatureLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; inMemoryFeatureLayer2.InternalFeatures.Add(new Feature(registeredPolygonShape)); mapEngine.DynamicLayers.Add(inMemoryFeatureLayer2); DrawImage(); } private void DrawImage() { if (bitmap != null) { bitmap.Dispose(); } bitmap = new Bitmap(Map.Width, Map.Height); mapEngine.OpenAllLayers(); mapEngine.DrawStaticLayers(bitmap, GeographyUnit.Meter); mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.Meter); mapEngine.DrawAdornmentLayers(bitmap, GeographyUnit.Meter); mapEngine.CloseAllLayers(); Map.Image = bitmap; } private void DrawImage2() { if (bitmap2 != null) { bitmap2.Dispose(); } bitmap2 = new Bitmap(Map2.Width, Map2.Height); mapEngine2.OpenAllLayers(); mapEngine2.DrawDynamicLayers(bitmap2, GeographyUnit.Meter); mapEngine2.DrawAdornmentLayers(bitmap2, GeographyUnit.Meter); mapEngine2.CloseAllLayers(); Map2.Image = bitmap2; } private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e) { switch (e.Button.Tag.ToString()) { case "Zoom In": mapEngine.CurrentExtent.ScaleDown(50); break; case "Zoom Out": mapEngine.CurrentExtent.ScaleUp(50); break; case "Full Extent": mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height); break; case "Pan Left": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20); break; case "Pan Right": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20); break; case "Pan Up": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20); break; case "Pan Down": mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20); break; default: break; } DrawImage(); } private void btnClose_Click(object sender, EventArgs e) { this.Close(); } private void Map_MouseMove(object sender, MouseEventArgs e) { //Displays the X and Y in screen coordinates. statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y; //Gets the PointShape in world coordinates from screen coordinates. PointShape pointShape = ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(Decimal Degrees) Long.:" + Math.Round(pointShape.X, 4) + " Lat.:" + Math.Round(pointShape.Y, 4); } private void Map2_MouseMove(object sender, MouseEventArgs e) { //Displays the X and Y in screen coordinates. statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y; //Gets the PointShape in world coordinates from screen coordinates. PointShape pointShape = ExtentHelper.ToWorldCoordinate(mapEngine2.CurrentExtent, new ScreenPointF(e.X, e.Y), Map2.Width, Map2.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(Meters) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); } } }