AddIn using AGS selection to update extent of ArcMap Activeview

1720
0
09-27-2011 03:34 PM
ToddLighthizer
New Contributor
I've created an addin button that goes to an ArcGIS Server map service, selects a feature and then sets the geometry envelope of that feature to the activeview view extent in ArcMap.   The code doesn't error out, but I can't seem to get the values for the new envelope to stick to the values of the activeview extent.  Any ideas?


private void button2_Click(object sender, EventArgs e)
        {
          
            IGISServerConnection pGISServCon = new GISServerConnection();
            pGISServCon.Connect("CC1wa126");
            IServerObjectManager pSOM = pGISServCon.ServerObjectManager;
            IServerContext pServerContext = pSOM.CreateServerContext("ZoomTest", "MapServer");
            IMapServer pMapServer = pServerContext.ServerObject as IMapServer;

            IMapServerObjects pMapServerObjs = pMapServer as IMapServerObjects;
            IMap pMap = pMapServerObjs.get_Map(pMapServer.DefaultMapName);

            ILayer pFLayer = pMap.get_Layer(0) as ILayer;
            IFeatureLayer pFeatureClass = pFLayer as IFeatureLayer;

            IQueryFilter pQfilt = new QueryFilterClass();
            pQfilt.WhereClause = "UTB_ACCOUNT = '031935'";
           
            IFeatureCursor pFC = pFeatureClass.Search(pQfilt, false);
            IFeature pFeat = pFC.NextFeature(); // all queries will return only 1 feature
            
            IGeometry pGeom = pFeat.ShapeCopy;
            IEnvelope pEnv = new EnvelopeClass();
            pEnv = pGeom.Envelope;

            IMxDocument pMxd = ArcMap.Document;
            IActiveView pActiveview = pMxd.ActiveView;


            pActiveview.Extent = pEnv;// pActiveview extent not updating to the envelope of pEnv

            pActiveview.Refresh();
 
        }
0 Kudos
0 Replies