ThinkGeo.com    |     Documentation    |     Premium Support

Dragged Point Style

The "Dragged point style" is a great peace of code, but I would like to draw a point which I can drag.  Furthermore, the point must have a label. Any help on this would be appreciated.



Hi Alta,


To drag a point by the DragInteractiveOverlay, you could add the point feature to the EditShapeLayer of DragInteractiveOverlay and set the CanDrag property to true. And to have a label for the point, you could set the text style of the EditShapeLayer. The code could be like this:
 

private void TestForm_Load(object sender, EventArgs e)
{
    winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
    winformsMap1.CurrentExtent = new RectangleShape(-97.7591, 30.3126, -97.7317, 30.2964);
    winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));

    PointShape point = new PointShape(-97.74, 30.30);

    //DragtInteractiveOverlay for setting the PointStyles of the control points and dragged points.
    DragInteractiveOverlay dragInteractiveOverlay = new DragInteractiveOverlay();
   
    // Add a column to EditShapeLayer.
    dragInteractiveOverlay.EditShapesLayer.Open();
    dragInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("LabelColumn"));
    dragInteractiveOverlay.EditShapesLayer.Close();

    // Specify the label text.
    Dictionary<string, string> columnValues = new Dictionary<string,string>();
    columnValues.Add("LabelColumn", "LabelText");

    // Add the point feature and specify text style.
    dragInteractiveOverlay.EditShapesLayer.InternalFeatures.Add("Point", new Feature(point, columnValues));
    dragInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new TextStyle("LabelColumn", new GeoFont("Arial", 12), new GeoSolidBrush(GeoColor.SimpleColors.Black));

    dragInteractiveOverlay.CanAddVertex = false;
    dragInteractiveOverlay.CanRemoveVertex = false;
    dragInteractiveOverlay.CanResize = false;
    dragInteractiveOverlay.CanRotate = false;
    dragInteractiveOverlay.CalculateAllControlPoints();

    winformsMap1.EditOverlay = dragInteractiveOverlay;
    
    winformsMap1.Refresh();
}

 
Hope this helps and any more questions please let us know.
 
Thanks,
 
Sun

Fantastic, thanks!  :)

Alta, 
  
 I am glad that it’s working. And thank Sun’s help. 
  
 I want to close this post if you have no more questions. 
  
 James

Hi, when trying to add a point and drag it I just end up panning the map. Do you have to create controls to toggle between dragging and panning?

 Gary,


If you want the point to be draggable you will need to create a MarkerOverlay to contain these points.  To check out how the MarkerOverlay works with dragging you can look at the "Use a Draggable Marker" sample under the Markers section in the How Do I Samples.


I hope this helps.


Thanks!



I’ve looked at the “Dragged Point Style” sample. There is a custom Overlay class called DragInteractiveOverlay, the one mentioned earlier in this post. Everything in the sample works fine, but when I try to add a new point on the overlay with: 
 PointShape point = new PointShape(-97.74, 30.30); 
 dragInteractiveOverlay.EditShapesLayer.InternalFeatures.Add(“Point”, new Feature(point)); 
  
 I found this new point cannot be dragged untill another point is dragged first. 
 It’s weird, if I click on this new point and try to drag it the screen pans. 
 But if I drag one of the default point set up with the original sample I am now allowed to drag the new point I’ve created.

 Gary,


I think you are looking at the wrong sample, the code in this post is old and there is an easier way to add draggable markers now.  I was refering to the sample included in the How Do I Samples that get installed when you first downloaded the product.  Here is the code from that sample that shows two points that can be dragged:



            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = new RectangleShape(-155.733, 95.60, 104.42, -81.9);

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

            SimpleMarkerOverlay markerOverlay = new SimpleMarkerOverlay();
            markerOverlay.MapControl = winformsMap1;
            markerOverlay.DragMode = MarkerDragMode.Drag;
            winformsMap1.Overlays.Add("MarkerOverlay", markerOverlay);

            Marker marker = new Marker(-95.2806, 38.9554);
            marker.Image = Properties.Resources.AQUA;
            marker.Width = 20;
            marker.Height = 34;
            marker.YOffset = -17;
            markerOverlay.Markers.Add(marker);


            Marker marker2 = new Marker(-97.74, 30.30);
            marker2.Image = Properties.Resources.AQUA;
            marker2.Width = 20;
            marker2.Height = 34;
            marker2.YOffset = -17;
            markerOverlay.Markers.Add(marker2);

            winformsMap1.Refresh();


Hi, I figured out how the old code works. 
            
 you have to add this line of code to where you are creating the new point:  
 dragInteractiveOverlay.CalculateAllControlPoints(); 
  
 but this new markerOverlay looks better. Thank you for your help.

Thanks Gary, glad you got it working.