Map layers not drawing on refresh

1088
4
10-05-2011 03:02 PM
ToddLighthizer
New Contributor
Hello,

I've created an Add-In that will zoom to a location in a user's map based off a selection from a layer in an AGS map service.  Once the user inputs their criteria, ArcMap will zoom to that location, but it will not redraw the existing layers in their map.  Any suggestions to get the existing map layers to draw would be greatly appreciated!


IGISServerConnection pGISServCon = new GISServerConnection();
            pGISServCon.Connect("myserver");
            IServerObjectManager pSOM = pGISServCon.ServerObjectManager;
            IServerContext pServerContext = pSOM.CreateServerContext("ZoomTools", "MapServer");
            IMapServer pMapServer = pServerContext.ServerObject as IMapServer;

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

            ILayer pFLayer = pMap.get_Layer(zoomMapServID) as ILayer;

            IFeatureLayer pFeatlayer = pFLayer as IFeatureLayer;
            IFeatureClass pFeatureClass = pFeatlayer.FeatureClass;

            IQueryFilter pQfilt = new QueryFilterClass();
            //pQfilt.WhereClause = "QS_NUMBER = '23-55'";
            pQfilt.WhereClause = zoomColumn + " = '" + textBox1.Text + "'";      


            IEnvelope pEnv = new EnvelopeClass();
            //Set envelope to the geometry collection from the method below
            pEnv = GeometryBag_Example(pFeatureClass, pQfilt).Envelope;
                     
            IMxDocument pMxd = ArcMap.Document;
           
            // Get the focus map
            IMap map = pMxd.FocusMap;

            // Cast from IMap to IActiveView
            IActiveView pActiveview = (IActiveView)map;             
            
            pActiveview.FullExtent = pEnv.Envelope;

            //zooms to the right area on the map, but will not draw existing layers in the mxd.
            pActiveview.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null);
            

0 Kudos
4 Replies
JakubSisak
Occasional Contributor III
Partial Refresh is flaky.  Does it work with full refresh? It's been a while but i remember endless discussions about the intricacies of Partial Refresh in the old forums. If you really need to optimize refreshing you could try searching there.  Also, i strongly recommend you try posting this this on GIS Stack Exchange. There are several ESRI Forums MVPs on there and these types of queries usually get answered pretty quick.
0 Kudos
DubravkoAntonic
New Contributor III
Your refresh method works exactly what you write, refreshes the screen on null Envelope 🙂 joke.

You forgot to input refresh area as third parameter, look in SDK
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/0012/0012000001nm000000.htm

In desktop SDK there is also a sample, if you didn't install desktop developer help there is code, only was available in VB6, sorry. But conversion is pretty straight forward.

[Visual Basic 6.0]
Public Sub SelectDataFrameGraphicsAndRefresh()
  ' selects data frame graphics in ArcMap, regardless of whether you are in data view or layout view
  Dim pMxDocument As IMxDocument
  Set pMxDocument = Application.Document
  
  Dim pMapView As IActiveView
  Set pMapView = pMxDocument.FocusMap
  
  If TypeOf pMxDocument.ActiveView Is IPageLayout Then
     pMxDocument.ActiveView.IsMapActivated = True   '<=== To show the activated border in layout view.  Doesn't work in data view.
     pMapView.ShowSelection = True                  '<=== In layout view data graphic selection is not normally shown
  End If
  
  ' Select graphics
  Dim pMapGraphicsSelect As IGraphicsContainerSelect
  Set pMapGraphicsSelect = pMxDocument.FocusMap     '<==== Map implements IGraphicsContainerSelect.
  pMapGraphicsSelect.SelectAllElements
  
  ' Refresh
  pMapView.PartialRefresh esriViewGraphicSelection, Nothing, Nothing  '<=== Refresh only the selectionEnd Sub Public Sub SelectMapFeaturesAndRefresh()
  Dim pMxDoc As IMxDocument
  Dim pMap As IMap
  Dim pActiveView As IActiveView
  Dim pFeatureLayer As IFeatureLayer
  Dim pFeatureSelection As IFeatureSelection
  Dim pQueryFilter As IQueryFilter
  
  Set pMxDoc = Application.Document
  Set pMap = pMxDoc.FocusMap
  Set pActiveView = pMap
  
  'For simplicity sake let's use the first layer in the map
  If Not TypeOf pMap.Layer(0) Is IFeatureLayer Then Exit Sub
  Set pFeatureLayer = pMap.Layer(0)
  Set pFeatureSelection = pFeatureLayer 'QI
  
  'Create the query filter
  Set pQueryFilter = New QueryFilter
  pQueryFilter.WhereClause = "NAME = 'Nova Scotia'"
  
  'Invalidate only the selection cache
  'Flag the original selection
  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
  'Perform the selection
  pFeatureSelection.SelectFeatures pQueryFilter, esriSelectionResultNew, False
  'Flag the new selection
  pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
  
End Sub
0 Kudos
ToddLighthizer
New Contributor
Thank you for the reply, unfortunately the full Refresh method gets me the same results.  The same can be said for adding an envelope variable in the PartialRefresh method.

Any other suggestions?

Todd
0 Kudos
ToddLighthizer
New Contributor
Figured it out. I'm not sure if this is proper coding but it works.  I created another envlope and passed the x and y's from the geometry bag.

            IEnvelope pEnv = new EnvelopeClass();
            //Set envelope to the geometry collection from the method below
            pEnv = GeometryBag_Example(pFeatureClass, pQfilt).Envelope;

             // new code
            //Create a new envelope to pass the values to from the geometry bag
            IEnvelope envelope = new EnvelopeClass();
            envelope.XMax = pEnv.Envelope.XMax;
            envelope.YMax = pEnv.Envelope.YMax;
            envelope.XMin = pEnv.Envelope.XMin;
            envelope.YMin = pEnv.Envelope.YMin;


            pActiveview.Extent = envelope;
            pActiveview.Refresh();
0 Kudos