Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I draw a polygon on button click to highlight a feature. Then I need to refresh the ActiveView to show the new polygon. This lines do work:

mapControl.ActiveView.ScreenDisplay.StartDrawing(StartDrawing(mapControl.ActiveView.ScreenDisplay.hDC, (System.Int16)ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
mapControl.ActiveView.ScreenDisplay.DrawPolygon(feature.Shape);
mapControl.ActiveView.ScreenDisplay.FinishDrawing();
mapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewAll, feature.Extent, null);

But it always reloads every layer. I tried nearly all ways of calling PartialRefresh with other esriViewDrawPhase but none of them did show the new polygon.

Is there a better solution than to redraw with esriViewDrawPhase.esriViewAll?

Update

I used an ILayerExtensionDraw.AfterDraw to test the draw phases and the AfterDraw only gets hit for PartialRefresh() with esriViewAll. The extension is added to all layers in MapControl.Layers. I expected that it gets hit everytime? On which layer does mapControl.ActiveView.ScreenDisplay.DrawPolygon(feature.Shape); draw so that the AfterDraw isn't even raised?

Answer

Thanks to Kirk here is the solution, which shows the new added graphic without reloading any layer.

IGraphicsContainer con = _mapControl.Map as IGraphicsContainer;
if (con != null)
{
  IFillShapeElement fillShapeElement = new PolygonElementClass();
  fillShapeElement.Symbol = fillSymbol;
  IElement element = (IElement)fillShapeElement;
  element.Geometry = feature.Shape;
  con.DeleteAllElements();
  con.AddElement(element, 0);
  _mapControl.ActiveView.ScreenDisplay.Invalidate(feature.Extent, true, _mapControl.ActiveView.get_ScreenCacheID(esriViewDrawPhase.esriViewGraphics, null));
}
share|improve this question
1  
[I think the ESRI documentation is wishful not descriptive.][1] [1]: gis.stackexchange.com/questions/17422/remove-layer-labels –  Chaz Jan 30 '12 at 15:42
1  
Since you are drawing directly to the display (esriScreenCache.esriNoScreenCache), you should not need to refresh at all. In fact refreshing would cause the graphic to disappear. Have you tried without the PartialRefresh line? –  blah238 Jan 30 '12 at 19:55
    
Try esriViewDrawPhase.esriViewGeography instead of esriViewAll –  patrick Jan 30 '12 at 20:13
    
@blah238 It's not showing up without a (Partial)Refresh. –  gumo Jan 31 '12 at 8:22
    
@iterationx I tested all values, but only esriViewAll worked for me. –  gumo Jan 31 '12 at 8:30
add comment

1 Answer

up vote 5 down vote accepted

I would try calling IScreenDisplay.InValidate, and pass in a cacheID for esriViewGraphics using IActiveView.ScreenCacheID. Do this after adding the graphics to the map by casting the map to IGraphicsContainer, and adding via AddElement.

share|improve this answer
1  
Thanks, it works. I didn't know I could use Invalidate() with unchached layers. See my update for implementation details. –  gumo Jan 31 '12 at 11:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.