ThinkGeo.com    |     Documentation    |     Premium Support

Problem with WPF TrackingOverlay


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.




void winformsMap1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)

   {

    if (winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)

     {

      Mouse.OverrideCursor = Cursors.Wait;

      foreach (Feature feature in winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)

       {

        winformsMap1.CurrentExtent = feature.GetBoundingBox();       

       }


      int lastIndex = winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1;

       

      if (lastIndex >= 0)

       {

        winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.RemoveAt(lastIndex);

       }

      winformsMap1.TrackOverlay.TrackMode = TrackMode.None;

      // Find the closest scale for       

      winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();

      

      int index = FindClosestZoom(winformsMap1.CurrentScale);

      // this sets the CurrentZoomLevel;

      Zoom.ZoomSlide.Value = (double)index;

      Zoom.ZoomSlide.Refresh();

      Mouse.OverrideCursor = Cursors.Arrow;

     }

   }


  void winformsMap1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

   {

    if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)

       {

        winformsMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;

       }


   }


 




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.

?? Any fix ??

Bob,


Sorry for the delay.
 
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);
 
void wpfMap1_MouseUp(object sender, MouseButtonEventArgs e)
{
   if (e.ChangedButton == MouseButton.Right) { return; }
   if (wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)
   {
        //Mouse.OverrideCursor = Cursors.Wait;
        foreach (Feature feature in wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)
        {
           wpfMap1.CurrentExtent = feature.GetBoundingBox();
        }
 
        int lastIndex = wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1;
 
        if (lastIndex >= 0)
        {
           wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.RemoveAt(lastIndex);
        }
        wpfMap1.TrackOverlay.TrackMode = TrackMode.None;
        // Find the closest scale for       
        wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
 
        wpfMap1.Refresh();
        //int index = FindClosestZoom(winformsMap1.CurrentScale);
        //// this sets the CurrentZoomLevel;
        //Zoom.ZoomSlide.Value = (double)index;
        //Zoom.ZoomSlide.Refresh();
        //Mouse.OverrideCursor = Cursors.Arrow;
    }
}
 
void wpfMap1_MouseDown(object sender, MouseButtonEventArgs e)
{
   if (e.ChangedButton == MouseButton.Right) { return; }
   if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)
   {
       wpfMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;
   }
}


 
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Yale this is what I am using.  
  
           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

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.
 
Thanks.
 
Yale

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.  
  
 Thats commented out code is for.  
        //int index = FindClosestZoom(winformsMap1.CurrentScale); 
         //// this sets the CurrentZoomLevel; 
         //Zoom.ZoomSlide.Value = (double)index; 
         //Zoom.ZoomSlide.Refresh(); 
         //Mouse.OverrideCursor = Cursors.Arrow; 


 Bob,


Thanks for your reply.
 
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);
 
 
void wpfMap1_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{            System.Diagnostics.Debug.WriteLine("wpfMap1_MouseLeftButtonUp Start");
 
if (wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)
{
      //Mouse.OverrideCursor = Cursors.Wait;
foreach (Feature feature in wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)
      {
          wpfMap1.CurrentExtent = feature.GetBoundingBox();             
      }
 
      int lastIndex = wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Count - 1;
 
      if (lastIndex >= 0)
      {              wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.RemoveAt(lastIndex);
      }
      wpfMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();
 
      wpfMap1.Refresh();
 }
 
            System.Diagnostics.Debug.WriteLine("wpfMap1_MouseLeftButtonUp End");
}
 
void wpfMap1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
          System.Diagnostics.Debug.WriteLine("wpfMap1_MouseLeftButtonDown Start");
 
if (System.Windows.Forms.Control.ModifierKeys == System.Windows.Forms.Keys.Control)
{
     wpfMap1.TrackOverlay.TrackMode = TrackMode.Rectangle;
}
 
          System.Diagnostics.Debug.WriteLine("wpfMap1_MouseLeftButtonDown End");
}
 
void wpfMap1_MouseUp(object sender, MouseButtonEventArgs e)
{
    wpfMap1.TrackOverlay.TrackMode = TrackMode.None;
}

 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale