2

Is there button in ArcObjects "draw rectangle" such as in openlayers?

Update

Well, I use this code for drawing:

ESRI.ArcGIS.Display.IScreenDisplay screenDisplay = Map1.ActiveView.ScreenDisplay;
screenDisplay.StartDrawing(screenDisplay.hDC, (System.Int16)
    ESRI.ArcGIS.Display.esriScreenCache.esriNoScreenCache);
ESRI.ArcGIS.Display.IRgbColor rgbColor = new ESRI.ArcGIS.Display.RgbColor();
rgbColor.Red = 255;

ESRI.ArcGIS.Display.IColor color = rgbColor;
ESRI.ArcGIS.Display.ISimpleFillSymbol simpleFillSymbol = new
    ESRI.ArcGIS.Display.SimpleFillSymbol();
simpleFillSymbol.Color = color;

ESRI.ArcGIS.Display.ISymbol symbol = simpleFillSymbol as
    ESRI.ArcGIS.Display.ISymbol;
ESRI.ArcGIS.Display.IRubberBand rubberBand = new
    ESRI.ArcGIS.Display.RubberEnvelope();
ESRI.ArcGIS.Geometry.IGeometry geometry = rubberBand.TrackNew(screenDisplay,
    symbol);
screenDisplay.SetSymbol(symbol);
screenDisplay.DrawRectangle(geometry as ESRI.ArcGIS.Geometry.IEnvelope);
screenDisplay.FinishDrawing();
...
ArcGisToolbar.CurrentTool.Deactivate();
ArcGisToolbar.CurrentTool = null;
ICommand command = this.ArcGisToolbar.CommandPool.get_Command(3); // button "pan"
Map1.CurrentTool = (ITool)command;

But there is a problem. When I activate this instrument (button "select") again, I already start selecting the area (from the point, where I begin drawing the polygon)

  • what sdk Version do you use? – Chris P Oct 29 '13 at 12:51
3
+50

First of all I would use:

ESRI.ArcGIS.Display.IRubberBand rubberBand = new ESRI.ArcGIS.Display.RubberPolygonClass();

instead of using the RubberEnvelope method

then later do:

screenDisplay.DrawPolygon(geometry);

instead of screenDisplay.DrawRectangle(...)

see if that gets you further.

When getting Feedback for the rectangle via mouse Events I'd do the following: In OnMouseDown use:

INewEnvelopeFeedback envFb = new NewEnvelopeFeedback();
            envFb.Display = activeView.ScreenDisplay;
            envFb.Start(pt);

assign the envFb to a IDisplayfeedback df

In OnMouseMove do:

df.MoveTo(pt)

In OnMouseUp do:

IEnvelope env = ((INewEnvelopeFeedback)df).Stop();

pt is always the position of your mouse cursor.

  • 1
    Thanks. I draw rectangle, not polygon. Nowdays, I use two events: OnMouseDown (the left upper point) OnMouseUp (the right lower point, then draw rectangle) – novicegis Oct 29 '13 at 13:09
  • 1
    Yes that should work using the INewEnvelopeFeedback for instance. So is your issue solved or what is the remaining problem? – Chris P Oct 29 '13 at 13:13
  • I can draw rectangle on the Map. But I write additional code to functions: _OnMouseUp _OnMouseDown. I think it is not good. When I use example with "screenDisplay.DrawRectangle" I have the problem with instrument "select". When i activate this tool again I am already starting draw the rectangle (but I must only select the area). instrument "select". When i activate this tool again I already starting draw the polygone (but I must only select elemnts). – novicegis Oct 29 '13 at 13:32
  • what Instrument "select" are you referring to? Is that a custom tool made by you or some Standard selection tool in ArcMap? I edit my original answer to add some info on how I'd handle the mouse Events. – Chris P Oct 29 '13 at 14:01
  • I wonder whether the problem is that you don't call stop() for the envelopeFeedback (see my edited post above). Additional code in the mouseevent functions is generally seen not a problem. – Chris P Oct 29 '13 at 14:17
3

There are a lot of useful information and snippets of code in the ArcObjects online help from which you can start. For instance:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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