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));
}
Best Answer
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.