User Tools

Site Tools


source_code_desktopeditionsample_zoomintopoint_cs_091106.zip

This is an old revision of the document!


Source_Code_DesktopEditionSample_ZoomInToPoint_CS_091106.zip

<noinclude>article_rating</noinclude>

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
{
/// <summary>
/// The main entry point for the application.
/// </summary>
STAThread
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new TestForm());
}
}
}
</source>

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));

//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();
}


private void winformsMap1_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(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height);

//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>

ZoomInToPointInteractiveOverlay.cs

Code
<source lang=“csharp” line=“1”>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>
}
}
}</source>
source_code_desktopeditionsample_zoomintopoint_cs_091106.zip.1440040125.txt.gz · Last modified: 2015/09/02 07:52 (external edit)