Select to view content in your preferred language

Custom MapAction?  (9.3.1)

2525
3
09-27-2010 10:38 AM
DavidMarley
Frequent Contributor
Has anyone ever created a custom MapAction by inheriting from the ESRI MapAction class?  Or better yet, the ZoomInMapAction class?  I have seen a couple posts on the old forum but they only snippets, or are old (9.2).

What I am trying to do is inherit from ZoomInMapAction to create a custom zoom tool with different zoombox color.  I have a related post in this topic here:

http://forums.arcgis.com/threads/13381-Change-color-of-zoom-box-in-9.3.1-Mobile-map-control

Have not had too many responses to that, so now just checking to see if anyone has succesfully created any kind of customized MapAction class.

What I would want to do is something along the lines of this (VERY incomplete - just pseudo code really; I don't know what methods etc. I need to implement to get this to work):

public class CustomZoomInMapAction : ZoomInMapAction
{
 public CustomZoomInMapAction()
 {
  this.Map.Paint += new System.EventHandler<ESRI.ArcGIS.Mobile.MapPaintEventArgs>(Map_Paint);

 }

 void Map_Paint(object sender, MapPaintEventArgs e)
 {
   e.Display.DrawEnvelope(. . .);
 }

}


The idea would be to paint my own envelope in the paint event rather than the envelope and other graphics the default zoom tool draws.

I know this is a bit of an obscure question.  I appreciate any tips/suggestions anyone might have.  Thanks.
0 Kudos
3 Replies
MaximilianGlas
Esri Contributor
I have no example iheriting from ZoomInMapAction, but I can give you an short example from another one.

using System;
using System.Windows.Forms;
using ESRI.ArcGIS.Mobile;
using ESRI.ArcGIS.Mobile.Geometries;
using ESRI.ArcGIS.Mobile.MapActions;
using ESRI.ArcGIS.Mobile.MobileServices;

namespace xyz
{
 /// <summary>
 /// Move a feature by mouse drag
 /// </summary>
 internal class MovePointMapAction : MapAction
 {
  private ToolStripButton _controlButton;

  public MovePointMapAction()
  {
   StatusChanged +=
    delegate(object o, MapActionStatusChangedEventArgs e)
     {
      if (e.StatusId == Activated)
      {
       if (Map != null)
       {
        Map.Focus();
        Map.Cursor = Cursors.Cross;
        if (_controlButton != null)
        {
         _controlButton.Checked = true;
        }
       }
      }
      if (e.StatusId == Deactivated)
      {
       ActionInProgress = false;
       if (Map != null)
       {
        if (_controlButton != null)
        {
         _controlButton.Checked = false;
        }
        Map.Cursor = Cursors.Default;
       }
      }
     };
  }

  public ToolStripButton ControlButton
  {
   set { _controlButton = value; }
  }

  protected override void OnMapMouseDown(MapMouseEventArgs e)
  {
   ActionInProgress = true;
   Map.SuspendDrawing = true;
  }


  protected override void OnMapMouseUp(MapMouseEventArgs e)
  {
   if (ActionInProgress == false && Map.IsValid == false) return;
   Point lPoint = new Point(e.MapCoordinate);

   if (Map.GetFullExtent().Contains(lPoint.Coordinate))
   {
    try
    {
     FormIdentifyNavi lIdentifyForm = ((FormMap) Map.Parent).FormIdentify;

     FeatureDataRow lDataRow = lIdentifyForm.CurrentRow;
     Point lOldPoint = lDataRow[lDataRow.FeatureLayer.GeometryColumnIndex] as Point;
     if (lOldPoint != null)
      lOldPoint.Coordinate = lPoint.Coordinate;
    }
    catch (Exception ee)
    {
     MessageBox.Show(ee.Message, Messages.Error);
    }
   }

   Map.SuspendDrawing = false;
   ActionInProgress = false;
   Map.Invalidate();
  }


  // Properties


  protected override void Dispose(bool disposing)
  {
   base.Dispose(disposing);
   ActionInProgress = false;
  }

  public override string ToString()
  {
   return "MovePointAction";
  }
 }
}
0 Kudos
DavidMarley
Frequent Contributor
Excellent! I will see if I can build on this for a custom zoom action.  Thanks for posting this.
0 Kudos
SamanZaidi
New Contributor
excellent. it helped me developing code for custom zoom.
0 Kudos