This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
source_code_serviceseditionsample_zoomtofullextent_cs_100415.zip [2015/08/20 03:08] 127.0.0.1 external edit |
source_code_serviceseditionsample_zoomtofullextent_cs_100415.zip [2015/09/08 05:41] (current) admin |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Source_Code_ServicesEditionSample_ZoomToFullExtent_CS_100415.zip ====== | + | ====== Source Code ServicesEditionSample ZoomToFullExtent CS 100415.zip ====== |
- | <noinclude>{{article rating}}</noinclude> | ||
====Program.cs==== | ====Program.cs==== | ||
- | ^ Code ^ | ||
- | | <source lang="csharp" line="1">using System; \\ using System.Collections.Generic; \\ using System.Linq; \\ using System.Windows.Forms; \\ \\ namespace ZoomToFullExtent \\ { \\ static class Program \\ { \\ <nowiki>//</nowiki>/ <summary> \\ <nowiki>//</nowiki>/ The main entry point for the application. \\ <nowiki>//</nowiki>/ </summary> \\ [[STAThread]] \\ static void Main() \\ { \\ Application.EnableVisualStyles(); \\ Application.SetCompatibleTextRenderingDefault(false); \\ Application.Run(new TestForm()); \\ } \\ } \\ } \\ </source> | | ||
+ | <code csharp> using System; | ||
+ | using System.Collections.Generic; | ||
+ | using System.Linq; | ||
+ | using System.Windows.Forms; | ||
+ | | ||
+ | namespace ZoomToFullExtent | ||
+ | { | ||
+ | static class Program | ||
+ | { | ||
+ | /// <summary> | ||
+ | /// The main entry point for the application. | ||
+ | /// </summary> | ||
+ | [STAThread] | ||
+ | static void Main() | ||
+ | { | ||
+ | Application.EnableVisualStyles(); | ||
+ | Application.SetCompatibleTextRenderingDefault(false); | ||
+ | Application.Run(new TestForm()); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> | ||
- | ====TestForm.cs==== | ||
- | ^ Code ^ | ||
- | | <source lang="csharp" line="1">using System; \\ using System.Collections.ObjectModel; \\ using System.Drawing; \\ using System.Windows.Forms; \\ using ThinkGeo.MapSuite.Core; \\ \\ namespace ZoomToFullExtent \\ { \\ public partial class TestForm : Form \\ { \\ private MapEngine mapEngine = new MapEngine(); \\ private Bitmap bitmap = null; \\ \\ public TestForm() \\ { \\ InitializeComponent(); \\ } \\ \\ private void TestForm_Load(object sender, EventArgs e) \\ { \\ <nowiki>//</nowiki> Sets the extent and the background color \\ mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-98.89,27.74,-56.97,6.78), Map.Width, Map.Height); \\ mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); \\ \\ <nowiki>//</nowiki>Displays the World Map Kit as a background. \\ ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); \\ mapEngine.StaticLayers.Add(worldMapKitLayer); \\ \\ <nowiki>//</nowiki>Adds countries and capitals shapefiles. \\ ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp"); \\ Layer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country2; \\ Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; \\ \\ ShapeFileFeatureLayer Layer2 = new ShapeFileFeatureLayer(@"..\..\Data\worldcapitals.shp"); \\ Layer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1; \\ Layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; \\ \\ mapEngine.StaticLayers.Add(Layer1); \\ mapEngine.StaticLayers.Add(Layer2); \\ \\ \\ DrawImage(); \\ } \\ \\ <nowiki>//</nowiki>Function for getting the extent based on a collection of layers. \\ <nowiki>//</nowiki>It gets the overall extent of all the layers. \\ private RectangleShape GetFullExtent(GeoCollection<Layer> Layers) \\ { \\ Collection<BaseShape> rectangleShapes = new Collection<BaseShape>(); \\ \\ foreach (Layer layer in Layers) \\ { \\ layer.Open(); \\ if (layer.HasBoundingBox == true) rectangleShapes.Add(layer.GetBoundingBox()); \\ } \\ return ExtentHelper.GetBoundingBoxOfItems(rectangleShapes); \\ } \\ \\ \\ private void DrawImage() \\ { \\ if (bitmap != null) { bitmap.Dispose(); } \\ bitmap = new Bitmap(Map.Width, Map.Height); \\ mapEngine.OpenAllLayers(); \\ mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree); \\ mapEngine.CloseAllLayers(); \\ \\ Map.Image = bitmap; \\ } \\ \\ 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": \\ <nowiki>//</nowiki>Sets the current extent according to the overall extent of the static layers. \\ mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(GetFullExtent(mapEngine.StaticLayers), 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) \\ { \\ <nowiki>//</nowiki>Displays the X and Y in screen coordinates. \\ statusStrip1.Items[["toolStripStatusLabelScreen"]].Text = "X:" + e.X + " Y:" + e.Y; \\ \\ <nowiki>//</nowiki>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); \\ \\ <nowiki>//</nowiki>Displays world coordinates. \\ statusStrip1.Items[["toolStripStatusLabelWorld"]].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); \\ } \\ } \\ } \\ </source> | | ||
+ | ====TestForm.cs==== | ||
+ | <code csharp> using System; | ||
+ | using System.Collections.ObjectModel; | ||
+ | using System.Drawing; | ||
+ | using System.Windows.Forms; | ||
+ | using ThinkGeo.MapSuite.Core; | ||
+ | | ||
+ | namespace ZoomToFullExtent | ||
+ | { | ||
+ | public partial class TestForm : Form | ||
+ | { | ||
+ | private MapEngine mapEngine = new MapEngine(); | ||
+ | private Bitmap bitmap = null; | ||
+ | | ||
+ | public TestForm() | ||
+ | { | ||
+ | InitializeComponent(); | ||
+ | } | ||
+ | | ||
+ | private void TestForm_Load(object sender, EventArgs e) | ||
+ | { | ||
+ | // Sets the extent and the background color | ||
+ | mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-98.89,27.74,-56.97,6.78), 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(); | ||
+ | mapEngine.StaticLayers.Add(worldMapKitLayer); | ||
+ | | ||
+ | //Adds countries and capitals shapefiles. | ||
+ | ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp"); | ||
+ | Layer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country2; | ||
+ | Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | ||
+ | | ||
+ | ShapeFileFeatureLayer Layer2 = new ShapeFileFeatureLayer(@"..\..\Data\worldcapitals.shp"); | ||
+ | Layer2.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1; | ||
+ | Layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; | ||
+ | | ||
+ | mapEngine.StaticLayers.Add(Layer1); | ||
+ | mapEngine.StaticLayers.Add(Layer2); | ||
+ | | ||
+ | | ||
+ | DrawImage(); | ||
+ | } | ||
+ | | ||
+ | //Function for getting the extent based on a collection of layers. | ||
+ | //It gets the overall extent of all the layers. | ||
+ | private RectangleShape GetFullExtent(GeoCollection<Layer> Layers) | ||
+ | { | ||
+ | Collection<BaseShape> rectangleShapes = new Collection<BaseShape>(); | ||
+ | | ||
+ | foreach (Layer layer in Layers) | ||
+ | { | ||
+ | layer.Open(); | ||
+ | if (layer.HasBoundingBox == true) rectangleShapes.Add(layer.GetBoundingBox()); | ||
+ | } | ||
+ | return ExtentHelper.GetBoundingBoxOfItems(rectangleShapes); | ||
+ | } | ||
+ | | ||
+ | | ||
+ | private void DrawImage() | ||
+ | { | ||
+ | if (bitmap != null) { bitmap.Dispose(); } | ||
+ | bitmap = new Bitmap(Map.Width, Map.Height); | ||
+ | mapEngine.OpenAllLayers(); | ||
+ | mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree); | ||
+ | mapEngine.CloseAllLayers(); | ||
+ | | ||
+ | Map.Image = bitmap; | ||
+ | } | ||
+ | | ||
+ | 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": | ||
+ | //Sets the current extent according to the overall extent of the static layers. | ||
+ | mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(GetFullExtent(mapEngine.StaticLayers), 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 = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </code> |