Skip to content

Instantly share code, notes, and snippets.

@alamsal
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamsal/9fc1d54cdb3bf5650a99 to your computer and use it in GitHub Desktop.
Save alamsal/9fc1d54cdb3bf5650a99 to your computer and use it in GitHub Desktop.
Draw features in ArcMap using ArcGIS Addin tool (Arcobject's IRubberband Interface)
protected override void OnMouseDown(ESRI.ArcGIS.Desktop.AddIns.Tool.MouseEventArgs arg)
{
//create geometery
if (ArcMap.Document != null)
{
IScreenDisplay screenDisplay = ArcMap.Document.ActiveView.ScreenDisplay;
// Constants
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)esriScreenCache.esriNoScreenCache);
// Explicit Cast
IRgbColor rgbColor = new RgbColorClass();
rgbColor.Red = 255;
rgbColor.Transparency = 75;
IColor color = rgbColor; // Implicit Cast
ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();
simpleFillSymbol.Color = color;
//Draw geometry
ISymbol symbol = simpleFillSymbol as ISymbol; // Dynamic Cast
IRubberBand rubberBand = new RubberPolygonClass();
IGeometry geometry = rubberBand.TrackNew(screenDisplay, symbol);
//check for valid geometery
if (geometry != null)
{
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawPolygon(geometry);
screenDisplay.FinishDrawing();
//Open addattributes wpf form
AddAtrributesView addAtrributesView = new AddAtrributesView(geometry);
addAtrributesView.ShowInTaskbar = false;
addAtrributesView.ShowDialog();
ArcMap.Document.ActivatedView.Refresh();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment