The code below is what I use to draw a rectangle and Zoom up to fit the rectangle. The C# code is the same as the WPF code. The only difference is the control name. The first time you you draw the rectangle everything works as expected. The next time you do this the rectangle starts in an odd position. The C# handles this correctly. The WPF doesnt.
A bit of additional information it looks like the BaseShape is not cleared. When I look at the baseShape returned from winFormsMap1.TrackOverlay.GetTrackingShape() right after I set the WinFormsMap1.TrackOverlay.TrackMode to TrackMode.Rectangle it looks like it does not clear correctly.
I suspect the difference comes from the event you are using, instead of Winforms Map control and WPF map control.
Try the following corresponding sample from winforms Map control, hope it worksJ. wpfMap1.MouseDown += new MouseButtonEventHandler(wpfMap1_MouseDown); wpfMap1.MouseUp += new MouseButtonEventHandler(wpfMap1_MouseUp);
winformsMap1.MouseDown += new MouseEventHandler(winformsMap1_MouseLeftButtonDown); winformsMap1.MouseUp += new MouseEventHandler(winformsMap1_MouseLeftButtonUp);
I think I reused and slightly modified the code from an example. Bob
What I want to let you know before we going further is that if we use the events MouseDown and MouseUp directly then it seems works properly. Of course, we can do some judgment in the event to see if it is left button clicked.
if (e.ChangedButton == MouseButton.Right) { return; }
So, I doubt there probably some hidden magic in the process of those events procedure.
if (e.ChangedButton == MouseButton.Right) { return; } I use the right mouse button the left mouse button and even the control drag left mouse button and the mouse wheel. The app is pretty busy.
Yale here is what I have observed. First time works. Next time usually works. Third time hmm… Now each time I am altering the wpfMap1.CurrentExtent which basically Zooms in / resizes the images. I then try to evaluate and force the scale snap to a pre created tile scale.
I think I figured out the problem .Hope the following code works. Besides, I do not think you need to snap to zoom level manually if you did not change the default zoomlevel snapping mode.
wpfMap1.MouseLeftButtonDown += new MouseButtonEventHandler(wpfMap1_MouseLeftButtonDown); wpfMap1.MouseLeftButtonUp += new MouseButtonEventHandler(wpfMap1_MouseLeftButtonUp); wpfMap1.MouseUp +=new MouseButtonEventHandler(wpfMap1_MouseUp);