ThinkGeo.com    |     Documentation    |     Premium Support

Panning while in trackmode

This seems like I am missing something, but when I am setting my trackmode on the trackoverlay to anything other than None, I lose my ability to pan the map.  That makes it very difficult to draw large and accurate boundaries for our users.  They complain about having to zoom out, then zoom in to move the screen.  What can I do to enable the pan while in a track mode?  I can use middle mouse button or right mouse button to start the pan if necessary and leave the left mouse button as is.

Hi Jake,



I think there are two ways for this case: One is using the right mouse button to pan and the other one is still using the left mouse button but with some complex.



Here is the first way:


wpfMap1.TrackOverlay = new MyTrackInteractiveOverlay();
 
public class MyTrackInteractiveOverlay : TrackInteractiveOverlay
    {
        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
        {
            InteractiveResult result = base.MouseDownCore(interactionArguments);
            result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;
            return result;
        }
    }

The second way:




private void HandleMapControlMouseMove(object sender, MouseEventArgs e)
       {
           if (e.LeftButton == MouseButtonState.Pressed && trackOverlay.TrackMode == TrackMode.Line)
           {
               trackOverlay.IsPan = true;
           }
       }
 
       private void HandleMapControlLeftButtonUp(object sender, MouseButtonEventArgs e)
       {
           if (trackOverlay.TrackMode == TrackMode.Line) trackOverlay.IsPan = false;
       }
 
       private void HandleMapControlMouseLeave(object sender, MouseEventArgs e)
       {
           if (trackOverlay.TrackMode == TrackMode.Line) trackOverlay.IsPan = false;
       }
 
 
 
 
   public class CustomTrackOverlay : TrackInteractiveOverlay
   {
       private bool isPan;
 
       public bool IsPan
       {
           get { return isPan; }
           set { isPan = value; }
       }
 
       public CustomTrackOverlay()
           : base()
       {
       }
 
       protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
       {
           if (!isPan)
           {
               InteractiveResult result = base.MouseDownCore(interactionArguments);
               result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;
               return result;
           }
           else
           {
               InteractiveResult result = new InteractiveResult();
               result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;
               return new InteractiveResult();
           }
       }
 
       protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
       {
           if (!isPan)
           {
               InteractiveResult result = base.MouseMoveCore(interactionArguments);
               return result;
           }
           else
           {
               InteractiveResult result = new InteractiveResult();
               result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;
               return new InteractiveResult();
           }
       }
   }

If there anything confused, please let us know.

Regards,

Troy

Hi,

As below is a update.

The code as below work for the first solution, left button to track and right button to pan.

 public class CustomTrackOverlay : TrackInteractiveOverlay
{
    public CustomTrackOverlay()
        : base()
    {
    }

    protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
    {
        InteractiveResult result = base.MouseDownCore(interactionArguments);
        if (this.TrackMode != TrackMode.Polygon)
        {
            return result;
        }

        result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;

        if (interactionArguments.MouseButton == MapMouseButton.Right)
        {
            result = new InteractiveResult();
        }

        return result;
    }

    protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
    {
        InteractiveResult result = base.MouseMoveCore(interactionArguments);
        if (this.TrackMode != TrackMode.Polygon)
        {
            return result;
        }

        result.ProcessOtherOverlaysMode = ProcessOtherOverlaysMode.ProcessOtherOverlays;

        if (interactionArguments.MouseButton == MapMouseButton.Right)
        {
            result = new InteractiveResult();
        }

        return result;
    }
}

Regards,

Don

Hi,

thanks for this code snippet. I would have never found a solution on my own.
I had to change it a bit, to recognize fast mouse clicks.

        protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
        {
            InteractiveResult result = base.MouseDownCore(interactionArguments);

            if (interactionArguments.MouseButton == MapMouseButton.Right)
            {
                result = new InteractiveResult();
                InteractiveClickInterval = 10;
            }

            return result;
        }

        protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
        {
            InteractiveResult result = base.MouseMoveCore(interactionArguments);

            if (interactionArguments.MouseButton == MapMouseButton.Right)
            {
                result = new InteractiveResult();
            }

            return result;
        }

        protected override InteractiveResult MouseUpCore(InteractionArguments interactionArguments)
        {
            InteractiveResult result = base.MouseUpCore(interactionArguments);
            
            if (interactionArguments.MouseButton == MapMouseButton.Right)
            {
                result = new InteractiveResult();
                InteractiveClickInterval = 400;
            }

            return result;
        }

I could however not get the code to facilitate the middle mouse button (i.e. mouse wheel click). Just changing the if-statement does not suffice.

Did anybody find a solution for this?

Peter

Hi Peter,

Our map don’t support pan by middle button, so it’s not easy to implement that.

If you don’t assign other function to right button, you can do hack like this based on my previous code.

public class CustomExtentOverlay : ExtentInteractiveOverlay
{
public CustomExtentOverlay()
: base()
{
}

    protected override InteractiveResult MouseDownCore(InteractionArguments interactionArguments)
    {
        InteractiveResult result = new InteractiveResult();

        if (interactionArguments.MouseButton == MapMouseButton.Middle)
        {
            interactionArguments.MouseButton = MapMouseButton.Right;
            result = base.MouseDownCore(interactionArguments);
        }

        return result;
    }

    protected override InteractiveResult MouseMoveCore(InteractionArguments interactionArguments)
    {
        InteractiveResult result = new InteractiveResult();

        if (interactionArguments.MouseButton == MapMouseButton.Middle)
        {
            interactionArguments.MouseButton = MapMouseButton.Right;
            result = base.MouseMoveCore(interactionArguments);
        }
        return result;
    }
}

Map1.ExtentOverlay = new CustomExtentOverlay();

Regards,

Don

Hi Don,

thank you for your answer.
But: Ouch! That’s really a hack!

Luckily I could get my users to accept to use the right mouse button for panning the map in track mode…

Best regards,
Peter

Hi Peter,

I am glad to hear that’s helpful.

Any question please let me know.

Regards,

Don