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);
}
-
yCoord looks > 90Kirk Kuykendall– Kirk Kuykendall2016年06月01日 15:44:02 +00:00Commented 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.cevondanady– cevondanady2016年06月01日 15:56:19 +00:00Commented Jun 1, 2016 at 15:56
1 Answer 1
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;