ThinkGeo.com    |     Documentation    |     Premium Support

Adding a Draggable Point in Map

I am avaluating desktop edition of map suite to build a portable tool that will map customer address points. what i want to do is quite 'simple'.


I want to be able to load my own base map from sql server or shape file. I want co-ordinates obtained from the application to be compatible out present co ordinate system since will be putting back the co ordinates back in our GIS based on Map guide open source.


I want to be able to double click on a map and add a point. This point should be draggable and can be deleted if required. Each point will represent a customer address point having a unique Identifier.


I have downloaded the Dragging Icone and modified it slightly so features are added on double click event but i am getting errors.


eg  "An item with the same key has already been added." if i add using the same key value, or  The given key was not present in the dictionary if i add a unique key.


I must be missing something... your help is appreciated.


the modified solution is attached.


 



TestForm.zip (1.58 KB)

Adrian, Welcome you to ThinkGeo Desktop Discussion forum and thanks for your code.


Try the following code, it should work for you.
 

EditInteractiveOverlay editInteractiveOverlay = new EditInteractiveOverlay();
        ValueStyle valueStyle = new ValueStyle();
        PointShape pointShape;
 
        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));
 
            //Displays the World Map Kit as a background.
            ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new ThinkGeo.MapSuite.DesktopEdition.WorldMapKitWmsDesktopOverlay();
            winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);
 
            //EditInteractiveOverlay used because it already have the logic for dragging.
            //EditInteractiveOverlay editInteractiveOverlay = new EditInteractiveOverlay();
 
            //Sets the property IsActive for DragControlPointsLayer to false so that the control point (as four arrows) is not visible.
            editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false;
           editInteractiveOverlay.DragControlPointsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            //Sets the property IsActive for all the Styles of EditShapesLayer because we are using a ValueStyle instead.
            editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.IsActive = false; 
            editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.IsActive = false; 
            editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.IsActive = false; 
 
            //ValueStyle used for displaying the feature according to the value of the column "Type" for displaying with a bus or car icon.
            //ValueStyle valueStyle = new ValueStyle();
            valueStyle.ColumnName = "Type";
 
            PointStyle carPointStyle = new PointStyle(new GeoImage(@"..\..\Data\car_normal.png"));
            carPointStyle.PointType = PointType.Bitmap;
            PointStyle busPointStyle = new PointStyle(new GeoImage(@"..\..\Data\bus_normal.png"));
            busPointStyle.PointType = PointType.Bitmap;
 
            valueStyle.ValueItems.Add(new ValueItem("Car", carPointStyle));
            valueStyle.ValueItems.Add(new ValueItem("Bus", busPointStyle));
 
            editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(valueStyle);
            editInteractiveOverlay.EditShapesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            editInteractiveOverlay.EditShapesLayer.Open();
            editInteractiveOverlay.EditShapesLayer.Columns.Add(new FeatureSourceColumn("Type"));
            editInteractiveOverlay.EditShapesLayer.Close();
 
            Feature carFeature = new Feature(new PointShape(-97.7507, 30.3092));
            carFeature.ColumnValues["Type"] = "Car";
 
            Feature busFeature = new Feature(new PointShape(-97.7428, 30.3053));
            busFeature.ColumnValues["Type"] = "Bus";
 
            editInteractiveOverlay.EditShapesLayer.InternalFeatures.Add("Car", carFeature);
            editInteractiveOverlay.EditShapesLayer.InternalFeatures.Add("Bus", busFeature);
 
            //Sets the properties of EditInteractiveOverlay to have the appropriate behavior.
            //Make sure CanDrag is set to true.
            editInteractiveOverlay.CanAddVertex = false;
            editInteractiveOverlay.CanDrag = true;
            editInteractiveOverlay.CanRemoveVertex = false;
            editInteractiveOverlay.CanResize = false;
            editInteractiveOverlay.CanRotate = false;
            editInteractiveOverlay.CalculateAllControlPoints();
 
            winformsMap1.EditOverlay = editInteractiveOverlay;
 
            winformsMap1.Refresh();
 
            winformsMap1.DoubleClick += new EventHandler(winformsMap1_DoubleClick);
        }
 
        void winformsMap1_DoubleClick(object sender, EventArgs e)
        {
            Feature carFeature = new Feature(new PointShape(pointShape.X, pointShape.Y));
            carFeature.ColumnValues["Type"] = "Car";
 
            editInteractiveOverlay.EditShapesLayer.InternalFeatures.Add(DateTime.Now.Ticks.ToString(), carFeature);
            winformsMap1.Refresh(winformsMap1.EditOverlay);
        }
 
      
        private void winformsMap1_MouseMove(object sender, MouseEventArgs e)
        {
            //Displays the X and Y in screen coordinates.
            statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y;
 
            //Gets the PointShape in world coordinates from screen coordinates.
            pointShape = ExtentHelper.ToWorldCoordinate(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height);
 
            //Displays world coordinates.
            statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);
        }
        
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

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

I let everybody know that we have a more complete project in the Code Community that shows how to drag features. It also shows how to add a new one and remove existing ones by double click, etc. You can check it out at: code.thinkgeo.com/projects/show/draggingicon2



Hi, 
  
 Thanks very much. the solution worked. It is a good start. I will also take a look at the advanced drag and drop solution that is available 
  
 thanks for your help.

You are welcome and do not hesitate to give us some feedback.