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.

When we add a measure tool to the AxToolbarControl through the properties dialog, we can change to measure lenght and area in the dialog that pops up. But when we add a ControlsMapMeasureTool through code like this:

Dim control As AxMapControl = axMapControl1
Dim tool As New ControlsMapMeasureTool()
tool.OnCreate(control.[Object])
control.CurrentTool = DirectCast(tool, ITool)

We followed the instructions in the documentations How to create a command or tool to work with the controls The dialog pops up but when we choose "Measure An Area" a new Measure dialog pops up and we can still only measure lenght. What are we doing wrong?

Steps to reproduce:

  1. Create a new MapControlApplication in VS
  2. Create a new MenuItem in the Menu "Test"
  3. Create a new OnClick event handler TestToolStripMenuItem_Click
  4. Paste the code above into the event handler
  5. Run the application
  6. Load a map that has a spatialreference that is a projected coord system (not a geographic coord system).
  7. choose the Test menu item
  8. Change to "Measure An Area" in the dialog
  9. Drag the dialog to the side.
  10. Two dialogs are active but only lenght can be measured.
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

I think there are two separate issues.

1) Area measurement will only be enabled when the map's spatialreference is a projected coord system (not a geographic coord system).

2) You shouldn't create a tool if it is already in the toolbar control. Instead, you should find it and activate it.

private void activateMeasuretoolToolStripMenuItem_Click(object sender, EventArgs e)
{
    int idx = axToolbarControl1.Find("esriControls.ControlsMapMeasureTool");
    if(idx > -1)
    {
        // use the tool that's already in the toolbar
        axToolbarControl1.CurrentTool = (ITool)axToolbarControl1.GetItem(idx).Command;
    }
    else
    {
        // add the tool to the toolbar
        ControlsMapMeasureTool t = new ControlsMapMeasureToolClass();
        t.OnCreate(axMapControl1.Object);
        axToolbarControl1.AddItem(t);
        axMapControl1.CurrentTool = (ITool)t;
    }
}
share|improve this answer
    
1) True, I will update the description with a point that I load the Map. 2) True, but I can't use the AxToolBarControl. We are using the Composite Aplication Block from Microsoft Pattern and practices so I want to initiate the tool from commands in the CAB. Tried doing a workaround creating a temporary toolbar and adding the tool to it, but I get an error when I add the map as a buddy to the toolbar. Seems to be a problem with the OCXState is it possible to create without adding the toolbar to the GUI? Feels like the AxToolbarControl is communicatating with the Tool but how do it in my code? –  MathiasWestin Aug 23 '10 at 14:34
    
Ahh, I see. I'd call this a bug - more specifically a design bug. I bet it's expecting to live on a toolbar. ArcEngine is promoted as an engine that you build the UI for, and yet this tool is tightly coupled with a UI. IMO, ESRI should provide another interface to this class that would allow developers to pass a callback class as an arg. That way, if you used the tool without having it on a toolbar you could be required to implement a callback. For your immediate problem though, you might want to write you own measure tool using IDisplayFeedback. –  Kirk Kuykendall Aug 23 '10 at 15:10
    
Ok, I will take look at the IDisplayFeedback and send a bug report through the ESRI support channels. –  MathiasWestin Aug 23 '10 at 16:57
add comment

I know this thread is close to 2 years old but I'm seeing the exact same behavior.

Is anyone else still seeing this behavior? Apparently it was/is a documented bugs that was supposedly resolved in sp3...Bug NIM-068806, however I'm still seeing the behavior with SP4 installed?

Thanks Matt

share|improve this answer
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.