ThinkGeo.com    |     Documentation    |     Premium Support

Using TrackZoomInWithoutShiftKey project disables shift+mouse down

I added the ModeInteractiveOverlay per the TrackZoomInWithoutShiftKey project, and can readily switch between the pan and trackzoomin using radio buttons on my form. So far so good.


However,  if the mode is set to pan and the user holds down the shift key, the mouse down merely draws a rectangle without zooming the map. I would like the shift+mousedown to automatically put the user in trackzoomin mode until they release the mouse. How can I add this behavior to the ModeInteractiveOverlay?


BTW the mode interactive overlay works great!


Thanks!



 


Gregory,
 
Just want to make sure we can use the same demo, I get the code from code community: code.thinkgeo.com/projects/show/trackzoomwithout
 
I think your problem is how to control the LeftClickDragMode. So I give you a sample code to show that, maybe you will have better idea for it.
 

        private void TestForm_Load(object sender, EventArgs e)
        {
            this.winformsMap1.KeyUp += new System.Windows.Forms.KeyEventHandler(this.winformsMap1_KeyUp);
            this.winformsMap1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.winformsMap1_KeyDown);
        }

        private void winformsMap1_KeyDown(object sender, KeyEventArgs e)
        {
            if (UnsafeHelper.IsKeyPressed(Keys.ShiftKey) && modeInteractiveOverlay.MapMode == ModeInteractiveOverlay.Mode.Pan)
            {
                modeInteractiveOverlay.LeftClickDragMode = MapLeftClickDragMode.ZoomInWithKey;
            }
        }

        private void winformsMap1_KeyUp(object sender, KeyEventArgs e)
        {
            if (modeInteractiveOverlay.MapMode == ModeInteractiveOverlay.Mode.Pan)
            {
                modeInteractiveOverlay.LeftClickDragMode = MapLeftClickDragMode.Disabled;
            }
        }

 
Please let me know if you have more questions.
 
Thanks,
James

James, thanks for the pointers - they worked perfectly! 
  
 Another side-effect I’ve found with the ModeInteractiveOverlay is that it seems to interfere with tracking. When I set the TrackMode to anything other than None, what’s the best way to disable the ModeInteractiveOverlay?

 


Gregory,
 
I think there is no interfere between track and your ModeInteractiveOverlay, the problem is caused by the sample code.
 
If you use the original code from code community, it will throw exception when you try to set TrackMode of TrackOverlay. Because that code just focus on how to implement the functions of ModeInteractiveOverlay, if you want to do more things, like you said that you want to do track either, you need change code a little bit like following:
 


        private void TestForm_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-125, 47, -67, 25);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

            //Displays the World Map Kit as a background.
            ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

            //Adds the ModeInteractiveOverlay to the InteractiveOverlays collection of the map.
            //winformsMap1.InteractiveOverlays.Clear();
            modeInteractiveOverlay = new ModeInteractiveOverlay();
            modeInteractiveOverlay.MapMode = ModeInteractiveOverlay.Mode.TrackZoomIn;
            winformsMap1.InteractiveOverlays[winformsMap1.InteractiveOverlays.Count - 1] = modeInteractiveOverlay;

            winformsMap1.Refresh();
        }

private void button_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;
            if (button != null)
            {
                switch (button.Name)
                {
                    case "btnTrackNormal":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
                        break;
                    case "btnTrackPoint":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Point;
                        break;
                    case "btnTrackLine":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Line;
                        break;
                    case "btnTrackRectangle":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;
                        break;
                    case "btnTrackSquare":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Square;
                        break;
                    case "btnTrackPolygon":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Polygon;
                        break;
                    case "btnTrackCircle":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Circle;
                        break;
                    case "btnTrackEllipse":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.Ellipse;
                        break;
                    default:
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
                        break;
                }
            }
        }

 
Please let me know if you have more questions.
 
Thanks
James
 
 

James, sorry to rehash an old issue, but I am still getting interference between the TrackOverlay mode and the interactive overlay. If I add the interactive overlay to the map and am also using the trackoverlay (in other words, I don’t clear the interactive overlays from the map) then switching into the pan or zoom to mode changes the behavior of the mouse. In zoom to mode, pressing the mouse button will display a rectangle which follows the location of the mouse as I drag it (as you would expect). However, when I release the mouse button the rectangle remains and the map is not resized. Further, in pan mode, pressing the mouse button will move the map (as you would expect) but releasing the mouse button does not “drop” the map to its new location - the map remains stuck in panning mode. 
  
 Can you send me a small project that demonstrates how you can work with both the interactive overlay AND the track overlay? 
  
 Thanks!

 


Gregory,
 
I think maybe you not look carefully my code, I also don't clear the interactive overlays. Please make sure your code is consistence with my code.
 
My code is that I don’t add a new interactive overlay, I replace the existing one. If like you said add a new interactive overlay, the result will like you said.
 
As you want, I create a small sample that just want to make it more clear, but the code is the same as I paste at previous reply.
If you want to track ellipse, you click Ellipse button and you can track, if you want to pan or track zoom in, you click None button.
 
Please let me know if you have more questions.
 
James

1509-TrackZoomInWithoutShiftKey.zip (37.7 KB)

James, you’re right! I didn’t read the source code clearly, and missed the fact that you were replacing the interactive ovelay. As soon as I adjusted my code accordingly, everything worked perfectly, just as you said. Thanks for your patience!

Gregory, 
  
 Don’t be self-accusation, it’s my honor to help you anytime. 
  
 I am very glad that you have solved your problem. 
  
 Just let me know if you have more questions. 
  
 James 


James, 
  
 What if I need TrackInteractiveOverlay and ModeInteractiveOverlay? I did this way: 
  
                Map.InteractiveOverlays.Clear(); 
                 ModeInteractiveOverlay = new ModeInteractiveOverlay(); 
                 ModeInteractiveOverlay.MapMode = ModeInteractiveOverlay.Mode.TrackZoomIn; 
                 Map.InteractiveOverlays.Add(ModeInteractiveOverlay); 
  
                 Map.TrackOverlay = new TrackInteractiveOverlay(); 
                 Map.TrackOverlay.TrackMode = TrackMode.None; 
                 Map.InteractiveOverlays.Add(Map.TrackOverlay); 
  
 When I set: 
  Map.TrackOverlay.TrackMode = TrackMode.Rectangle  
 for example, if I drag mouse over the map it draws the rectangle mut it  "pans" the map as well. 
 How can I deal with tihis, that is, stop pan while in Track mode? 
  
 Tks in advance, 
  
 Mauro Assis

Mauro, 
  
 I think you can hook up the event of track, and in the track starting you set modeInteractiveOverlay.LeftClickDragMode = MapLeftClickDragMode.Disabled, when the track ending you set it back. 
  
 Please let me know if it can not work. 
  
 Thanks 
 James