User Tools

Site Tools


source_code_desktopeditionsample_zoomintopoint_cs_091106.zip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
source_code_desktopeditionsample_zoomintopoint_cs_091106.zip [2015/08/20 03:08]
127.0.0.1 external edit
source_code_desktopeditionsample_zoomintopoint_cs_091106.zip [2015/09/09 03:32] (current)
admin
Line 1: Line 1:
-====== ​Source_Code_DesktopEditionSample_ZoomInToPoint_CS_091106.zip ======+====== ​Source Code DesktopEditionSample ZoomInToPoint CS 091106.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 ZoomInToPoint ​ ​\\ ​ ​\\ ​    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 ZoomInToPoint 
 +{ 
 +    ​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==== ====TestForm.cs====
-^ Code ^ 
-| <source lang="​csharp"​ line="​1">​using System; ​ \\ using System.Windows.Forms; ​ \\ using ThinkGeo.MapSuite.Core; ​ \\  \\ namespace ​ ZoomInToPoint ​ \\ {  \\     ​public partial class TestForm : Form  \\     ​{ ​ \\         ​public TestForm() ​ \\         ​{ ​ \\             ​InitializeComponent(); ​ \\         ​} ​ \\  \\         ​private void TestForm_Load(object sender, EventArgs e)  \\         ​{ ​ \\             ​winformsMap1.MapUnit = GeographyUnit.DecimalDegree; ​ \\             ​winformsMap1.CurrentExtent = new RectangleShape(-125,​ 47, -67, 25);  \\             ​winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255,​ 198, 255, 255)); ​ \\  \\             <​nowiki>//</​nowiki>​Displays the World Map Kit as a background. ​ \\             ​ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay(); ​ \\             ​winformsMap1.Overlays.Add(worldMapKitDesktopOverlay); ​ \\  \\             <​nowiki>//</​nowiki>​Adds the ZoomInToPointInteractiveOverlay to the InteractiveOverlays collection of the map.  \\             ​winformsMap1.InteractiveOverlays.Clear(); ​ \\  \\             ​ZoomInToPointInteractiveOverlay zoomInToPointInteractiveOverlay = new ZoomInToPointInteractiveOverlay(); ​ \\             ​winformsMap1.InteractiveOverlays.Add(zoomInToPointInteractiveOverlay); ​ \\  \\  \\  \\             ​winformsMap1.Refresh(); ​ \\         ​} ​ \\  \\  \\         ​private void winformsMap1_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(winformsMap1.CurrentExtent,​ new ScreenPointF(e.X,​ e.Y), winformsMap1.Width,​ winformsMap1.Height); ​ \\  \\             <​nowiki>//</​nowiki>​Displays world coordinates. ​ \\             ​statusStrip1.Items[["​toolStripStatusLabelWorld"​]].Text = "​(world) X:" + Math.Round(pointShape.X,​ 4) + " Y:" + Math.Round(pointShape.Y,​ 4);  \\         ​} ​ \\  \\         ​private void btnClose_Click(object sender, EventArgs e)  \\         ​{ ​ \\             ​this.Close(); ​ \\         ​} ​ \\  \\     ​} ​ \\ }  \\ </​source> ​  | 
  
 +<code csharp>
 +using System;
 +using System.Windows.Forms;​
 +using ThinkGeo.MapSuite.Core;​
 +namespace ​ ZoomInToPoint
 +{
 +    public partial class TestForm : Form
 +    {
 +        public TestForm()
 +        {
 +            InitializeComponent();​
 +        }
 +        private void TestForm_Load(object sender, EventArgs e)
 +        {
 +            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;​
 +            winformsMap1.CurrentExtent = new RectangleShape(-125,​ 47, -67, 25);
 +            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255,​ 198, 255, 255));
 +            //Displays the World Map Kit as a background.
 +            ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay();​
 +            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);​
 +            //Adds the ZoomInToPointInteractiveOverlay to the InteractiveOverlays collection of the map.
 +            winformsMap1.InteractiveOverlays.Clear();​
 +            ZoomInToPointInteractiveOverlay zoomInToPointInteractiveOverlay = new ZoomInToPointInteractiveOverlay();​
 +            winformsMap1.InteractiveOverlays.Add(zoomInToPointInteractiveOverlay);​
  
 +            winformsMap1.Refresh();​
 +        }
  
-====ZoomInToPointInteractiveOverlay.cs==== +        private void winformsMap1_MouseMove(object sender, MouseEventArgs e) 
-^ Code ^ +        { 
-| <source lang="​csharp"​ line="​1">​using ThinkGeo.MapSuite.Core; ​ \\ using ThinkGeo.MapSuite.DesktopEdition; ​ \\  \\ namespace ZoomInToPoint ​ \\ {  \\     class ZoomInToPointInteractiveOverlay:​ InteractiveOverlay ​ \\     ​{ ​ \\         <​nowiki>​//</​nowiki>​We override ​the MouseClickCore method to have the map centered ​and zoomed ​in to the location ​ \\         <​nowiki>//</​nowiki>​where the user click ​\\ ​        ​private InMemoryFeatureLayer iM = null;  \\  \\         ​protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments) ​ \\         ​{ ​ \\             ​return base.MouseDownCore(interactionArguments); ​ \\         ​} ​ \\  \\         ​protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments) ​ \\         ​{ ​ \\             <​nowiki>//</​nowiki>​return base.MouseMoveCore(interactionArguments); ​ \\  \\             ​InteractiveResult interactiveResult ​new InteractiveResult(); ​ \\             ​interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw ​\\ ​            ​interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays; ​ \\             ​return interactiveResult; ​ \\         ​} ​ \\  \\         <​nowiki>​//</​nowiki>​We override ​the MouseClickCore method to have the map centered and zoomed ​in to the location ​ \\         <​nowiki>//</​nowiki>​where the user click ​\\ ​        ​protected override InteractiveResult MouseClickCore(InteractionArguments interactionArguments) ​ \\         ​{ ​ \\            InteractiveResult interactiveResult ​new InteractiveResult();  \\            <​nowiki>//</​nowiki>​Calculates the offset in X and Y to center the map.  \\             ​PointShape centerPointShape = interactionArguments.CurrentExtent.GetCenterPoint(); ​ \\             ​PointShape newPointShape = new PointShape(interactionArguments.WorldXinteractionArguments.WorldY);  \\             ​double XOffset = newPointShape.X - centerPointShape.X ​\\ ​            ​double YOffset = newPointShape.Y - centerPointShape.Y;  \\  \\             ​RectangleShape newExtent ​= (RectangleShape)interactionArguments.CurrentExtent.CloneDeep();  \\             ​newExtent.TranslateByOffset(XOffsetYOffset);  \\  \\             <​nowiki>//</​nowiki>​Scales down the offset rectangle to have it set as the new extent of the map for zooming in ​\\ ​            ​RectangleShape scaledDownRectangleShape = RectangleShape.ScaleDown(newExtent85).GetBoundingBox();  ​\\ ​ \\             ​interactiveResult.NewCurrentExtent = scaledDownRectangleShape; ​ \\             ​interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays; ​ \\             ​interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw; ​ \\  \\             ​return interactiveResult; ​ \\          ​\\ ​ \\         ​protected override ​void DrawCore(GeoCanvas canvas ​\\ ​         ​\\ ​            <​nowiki>//</​nowiki>​base.DrawCore(canvas);  ​\\ ​           <​nowiki>//</​nowiki>​iM.Draw(GeoCanvas,​ new System.Collections.ObjectModel.Collection<​SimpleCandidate> ​ \\          ​\\ ​     ​\\ ​}</source  |+            //Displays ​the and 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(winformsMap1.CurrentExtentnew ScreenPointF(e.Xe.Y), winformsMap1.Width, winformsMap1.Height); 
 +            //Displays world coordinates. 
 +            statusStrip1.Items["​toolStripStatusLabelWorld"​].Text "(worldX:" + Math.Round(pointShape.X4+ " Y:" + Math.Round(pointShape.Y4); 
 +        ​} 
 +        private ​void btnClose_Click(object sender, EventArgs e) 
 +        ​{ 
 +            this.Close(); 
 +        ​} 
 +    ​} 
 +} 
 +</code>
  
  
 +
 +====ZoomInToPointInteractiveOverlay.cs====
 +
 +<code csharp>
 +using ThinkGeo.MapSuite.Core;​
 +using ThinkGeo.MapSuite.DesktopEdition;​
 +namespace ZoomInToPoint
 +{
 +    class ZoomInToPointInteractiveOverlay:​ InteractiveOverlay
 +    {
 +        //We override the MouseClickCore method to have the map centered and zoomed in to the location
 +        //where the user click.
 +        private InMemoryFeatureLayer iM = null;
 +        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
 +        {
 +            return base.MouseDownCore(interactionArguments);​
 +        }
 +        protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
 +        {
 +            //return base.MouseMoveCore(interactionArguments);​
 +            InteractiveResult interactiveResult = new InteractiveResult();​
 +            interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;​
 +            interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;​
 +            return interactiveResult;​
 +        }
 +        //We override the MouseClickCore method to have the map centered and zoomed in to the location
 +        //where the user click.
 +        protected override InteractiveResult MouseClickCore(InteractionArguments interactionArguments)
 +        {
 +           ​InteractiveResult interactiveResult = new InteractiveResult();​
 +           //​Calculates the offset in X and Y to center the map.
 +            PointShape centerPointShape = interactionArguments.CurrentExtent.GetCenterPoint();​
 +            PointShape newPointShape = new PointShape(interactionArguments.WorldX,​ interactionArguments.WorldY);​
 +            double XOffset = newPointShape.X - centerPointShape.X;​
 +            double YOffset = newPointShape.Y - centerPointShape.Y;​
 +            RectangleShape newExtent = (RectangleShape)interactionArguments.CurrentExtent.CloneDeep();​
 +            newExtent.TranslateByOffset(XOffset,​ YOffset);
 +            //Scales down the offset rectangle to have it set as the new extent of the map for zooming in.
 +            RectangleShape scaledDownRectangleShape = RectangleShape.ScaleDown(newExtent,​ 85).GetBoundingBox();​
 +            interactiveResult.NewCurrentExtent = scaledDownRectangleShape;​
 +            interactiveResult.ProcessOtherOverlays = ProcessOtherOverlaysMode.DoNotProcessOtherOverlays;​
 +            interactiveResult.DrawThisOverlay = InteractiveOverlayDrawType.Draw;​
 +            return interactiveResult;​
 +        }
 +        protected override void DrawCore(GeoCanvas canvas)
 +        {
 +            //​base.DrawCore(canvas);​
 +           //​iM.Draw(GeoCanvas,​ new System.Collections.ObjectModel.Collection<​SimpleCandidate>​
 +        }
 +    }
 +}</​code>​
source_code_desktopeditionsample_zoomintopoint_cs_091106.zip.1440040125.txt.gz · Last modified: 2015/09/02 07:52 (external edit)