ThinkGeo.com    |     Documentation    |     Premium Support

TrackMode problem

I am having an issue with the TrackMode and switching away from line to none and back to line.  I see this issue as well in the How Do I samples (Track and edit shapes).  If you click on the TrackLine button, draw some lines but don't doubleclick or commit the line, then switch to either TrackMode.None or TrackMode.Polygon the original lines you drew do not go away.


Sample Scenario:


1. Click on Line button

2. Single click on map to start line

3. Single click on map to draw 1 line segment

4. Click on Track Mode none button.  Your line should remain on the map, with 1 more segment drawn.

5. Click on Line Button

6. You should gain control of the last line segment.


I have tried to clear the trackoverlay with:

 


  wpfMap.TrackOverlay.Lock.EnterWriteLock();                 try                 {                     wpfMap.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();                     wpfMap.TrackOverlay.TrackShapeLayer.BuildIndex();                 }                 finally                 {                     wpfMap.TrackOverlay.Lock.ExitWriteLock();                     wpfMap.TrackOverlay.TrackMode = TrackMode.None;                     wpfMap.Refresh();                 } 


This doesn't seem to help.  Is there a way to clear/cancel the current track line when I switch to trackmode none?



Jake,


Thanks for your reporting.
 
Try to replace the following code into HowDoI samples (Track and edit shapes), hope it was your expected effect.

        private void TrackAndEditShapes_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);

            winformsMap1.CurrentExtent = new RectangleShape(-139.2, 92.4, 120.9, -93.2);
            winformsMap1.TrackOverlay.TrackEnding += new EventHandler<TrackEndingTrackInteractiveOverlayEventArgs>(TrackOverlay_TrackEnding);
            winformsMap1.Refresh();
        }

       
        void TrackOverlay_TrackEnding(object sender, TrackEndingTrackInteractiveOverlayEventArgs e)
        {
            if (changedTrackMode)
            {
                winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Remove("InTrackingFeature");
                e.Cancel = true;
                changedTrackMode = false;

                winformsMap1.Refresh(winformsMap1.TrackOverlay);
            }
        }

        private bool changedTrackMode;
        private void button_Click(object sender, EventArgs e)
        {
            if (winformsMap1.TrackOverlay.TrackMode == TrackMode.Line || winformsMap1.TrackOverlay.TrackMode == TrackMode.Polygon)
            {
                changedTrackMode = true;
                winformsMap1.TrackOverlay.MouseDoubleClick(new InteractionArguments());
               
            }

            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;
                    case "btnTrackEdit":
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
                        foreach (Feature feature in winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures)
                        {
                            winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Add(feature);
                        }
                        winformsMap1.EditOverlay.CalculateAllControlPoints();
                        winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();

                        winformsMap1.Refresh(new Overlay[] { winformsMap1.EditOverlay, winformsMap1.TrackOverlay });
                        break;
                    case "btnTrackDelete":
                        int lastIndex = winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.Count - 1;

                        if (lastIndex >= 0)
                        {
                            winformsMap1.EditOverlay.EditShapesLayer.InternalFeatures.RemoveAt(lastIndex);
                            winformsMap1.EditOverlay.CalculateAllControlPoints();
                        }

                        winformsMap1.Refresh(winformsMap1.EditOverlay);
                        break;
                    default:
                        winformsMap1.TrackOverlay.TrackMode = TrackMode.None;
                        break;
                }
            }

            winformsMap1.Refresh();
        }

 
Thanks.
 
Yale

 



Yale, 
     
      That doesn’t work for me still.  I see where you are trying to catch the trackending function with the direct call to doublclick().  At least in the sample I tried this was never firing.  So I went ahead and placed that code inside the button_click function so it would be called there.  The same issue still occurs.  The double click will fire and commit the line, but it won’t get removed correctly, so now there is a committed line/polygon instead of an active line.  What I would like to see is the line disappear. 
  
  I am using version .404, so maybe there was an update that changed that behavior, I will try with the latest public release as well to see if any changes were made. 
  
 Jake

I tested in the Release Client and it looks like it will work there, I will reference the latest release client for my project and test it there as well.  I notice you have to commit the line before removing it, is there no way to just clear the current tracking shape?

Hi Jake,


You should use the latest public release version (3.0.426) to use these codes. Actually, it doesn’t commit the line before removing it. This line of code just aims to do some internal clear work but not commit the tracking line:


winformsMap1.TrackOverlay.MouseDoubleClick(new InteractionArguments());


 
And this line of code is used to clear the current tracking shape:


winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Remove("InTrackingFeature");


Any more questions please let us know.
Thanks,
sun