Tuesday, 28 June 2016

symbology - Drawing selection custom selection box using ArcObjects?


I have some code that I'm using to selecting features in a certain extent. I already rigged the tool properly, so it selected the objects as needed, but I want to draw interactively the selection box the user is making.


I'm using IScreenDisplay.DrawRectangle method, but it pollutes the screen with many small rectangles. is There a way to clear up the old drawings in the screen?


This Draw method is being called from a mouse move event. Any ideas?



Here are two methods I'm using to do the dirty work:


    public override void OnMouseMove(int button, int shift, int x, int y)
{
if (button != 1)
return;

if (!_IsSelectOperation)
return;

endPoint = focusScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

envelope.PutCoords(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);
DrawEnvelope(envelope, BuildSelectionSymbol(), focusScreenDisplay);
}

private void DrawEnvelope(IEnvelope envelope, ISymbol symbol, IScreenDisplay screenDisplay)
{
screenDisplay.StartDrawing(screenDisplay.WindowDC, 0);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawRectangle(envelope);
screenDisplay.FinishDrawing();

}

Here is the code for BuildSelectionSymbol


    private ISymbol BuildSelectionSymbol()
{
IColor fillColor = new RgbColorClass();
fillColor.Transparency = 0;

IRgbColor outlineColor = new RgbColorClass();
outlineColor.Red = 0;

outlineColor.Green = 0;
outlineColor.Blue = 0;

ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass();
lineSymbol.Color = outlineColor as IColor;
lineSymbol.Width = 1;
lineSymbol.Style = esriSimpleLineStyle.esriSLSDash;

ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass();
fillSymbol.Color = fillColor;

fillSymbol.Outline = lineSymbol;
fillSymbol.Style = esriSimpleFillStyle.esriSFSHollow;

ISymbol symbol = fillSymbol as ISymbol;
symbol.ROP2 = esriRasterOpCode.esriROPNOP;

return symbol;
}

Answer





It stills draws all the rectangles, but I still need a way to clean them.



For the linesymbol, fillsymbol and symbol, set ROP2 = esriRasterOpCode.esriROPNotXOrPen.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...