1

I'm testing a simple portion of my add in and can't get it to center/pan to a specified point, I've included what is currently in my OnClick() method. No errors appear it just refreshes and nothing happens (10.1 SP1, C#.NET VS 2010).

IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;
IActiveView actView = mxdoc.FocusMap as IActiveView;
IPageLayout pLayout = actView as IPageLayout;
ISpatialReferenceFactory srFactory = new SpatialReferenceEnvironmentClass();
int gcsCode = (int)esriSRGeoCSType.esriSRGeoCS_NAD1983;
ISpatialReference spatRef = srFactory.CreateGeographicCoordinateSystem(gcsCode);
try
{
 IPoint point = new PointClass();
 double xCoord = 33.217918;
 double yCoord = -98.158749;
 point.PutCoords(xCoord, yCoord);
 point.Project(spatRef);
 actView.Extent.CenterAt(point);
 actView.Refresh();
}
catch (Exception ex)
{
 MessageBox.Show(ex.Message);
}
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked May 31, 2016 at 23:05
2
  • yCoord looks > 90 Commented Jun 1, 2016 at 15:44
  • That seems to be my next issue, no matter what projection I put it in it puts me in the Atlantic Ocean. I believe this is because it is taking me x meters from the origin but it was my understanding that a geographic coordinate system read these coordinates differently. Commented Jun 1, 2016 at 15:56

1 Answer 1

2

There's a few problems here. First IMxDocument.FocusMap is read only, you can't change the extent from here, use IMxDocument.ActiveView instead.

Instead of projecting your point (point.Project(spatRef);) you need to set it by using IPoint.SpatialReference (inheritied from IGeometry class): point.SpatialReference = spatRef;

I have found it better to pan an envelope rather than trying to modify with CenterAt:

IEvelope pEnv = mxdoc.ActiveView.Extent;
pEnv.CenterAt(point);
mxdoc.ActiveView.Extent = pEnv;
answered Jun 1, 2016 at 0:11
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.