Highlight marker

Jul 2, 2010 at 2:19 PM
How can one detremine that while dragging a marker from one position to another it is over another marker?
Jul 2, 2010 at 2:20 PM

what version?

Jul 2, 2010 at 2:33 PM

GMap.NET.WindowsForms, Version 1.0.0.0

Jul 2, 2010 at 2:42 PM

check all other markers where IsMouseOver == true

Jul 2, 2010 at 3:08 PM

That doesn't seem to work. Below is a code snippet which I'm using to check whether a marker is over another marker. The event where I'm checking this is GmapControl "DragOver"

 

if (currentMarker is EmployeeMarker) { foreach (JobMarker jb in jobsOverlay.Markers) { if (jb.IsMouseOver) { RadMessageBox.Show("JobMarker"); } } }

 

Jul 2, 2010 at 3:12 PM

you can use OnMarkerEnter event, like in demo, then both markers become red

Jul 2, 2010 at 3:18 PM

But the "OnMarkerEnter" event doesn't work when I'm dragging a marker.

Jul 2, 2010 at 3:25 PM

yes it does ;}

Jul 2, 2010 at 3:30 PM

It does work when the cursor enters a marker. But once I grab it and start dragging it over another marker it doesn't fire.

Jul 2, 2010 at 3:36 PM

i guess it depends how you do that, can you tell what do you want to do?

Jul 2, 2010 at 3:42 PM

Sure. I have two types of markers(JobMarker and EmployeeMarker). I want whenever I drag any of the jobmarkers over any of the Employeemarkers, the EmployeeMarker beneath the JobMarker should get highlighted.

Jul 2, 2010 at 4:25 PM

well it should work, check demo, try to drag one rect over another, and both become red

Jul 2, 2010 at 9:09 PM

But in the demo its not the "DragOver" event where you check for any overlapping of markers. The "OnMarkerEnter" works only after I release the mouse.

I want to be able to detect any overlapping of markers while I'm dragging the marker.

Jul 2, 2010 at 9:44 PM

no, it works while you dragging too

Jul 2, 2010 at 10:20 PM

Would really appreciate if you could please post that code snippet to obtain the same functionality.

Jul 2, 2010 at 10:33 PM

just catch the events...

Jul 3, 2010 at 5:52 AM

if you start mainmap.dodragdrop event the onmarkerenter and onmarkerleave events do not fire until after you release the mouse is what she is saying. We could use the other method except we want to drag marker's ON the map from other controls (which is working) we just have not been able to fire the event as of yet. Any other hints?

Jul 3, 2010 at 11:21 AM

OnMarkerEnter/OnMarkerLeave fires always, while dragging and while not dragging. It doesn't matter who what are saying ;} it is as it is.

Jul 3, 2010 at 6:08 PM

After some more research it appears to be a feature of the DoDragDrop method from Win Forms. (As expected no fault of yours, really nice control did I mention that?)

No mouse events fire, period, after you start that method. Below is a workaround and a link to a forum (but a simple search will reveal tons of people having this problem)

MSDN Forum DODRAGDROP bad mouse events

two variables to manage current Marker and minimumDistancetoHover

        GMapMarker currentMarker = null;

        private int minimumDistanceToHover = 50;

 Some events on load to work with the map and dragdrop features

            // Set current marker to to actually drag
            mainMap.OnMarkerEnter += new MarkerEnter(mainMap_OnMarkerEnter);
            // Set current marker to null (will not allow drag)
            mainMap.OnMarkerLeave += new MarkerLeave(mainMap_OnMarkerLeave);

            // Start Drag Drop Event if onmarkerenter sets currentmarker
            mainMap.MouseDown += new MouseEventHandler(mainMap_MouseDown);

            // Checking position of drag to see if over a marker and set the marker bigger icon
            // Also removes other icon sizes
            mainMap.QueryContinueDrag += new QueryContinueDragEventHandler(mainMap_QueryContinueDrag);

            // Set a custom Icon for the cursor
            mainMap.GiveFeedback += new GiveFeedbackEventHandler(mainMap_GiveFeedback);

            // Finish Drag/Drop Operation
            mainMap.DragDrop += new DragEventHandler(mainMap_DragDrop);

Events to handle operation

        void mainMap_DragDrop(object sender, DragEventArgs e)
        {
            // Minimize all markers and grab the enter and drop marker for use
            GMapMarker dragFromMarker = currentMarker;
            GMapMarker dragToMarker = null;
            if (dragFromMarker != null)
            {
                if (currentMarker is JobMarker)
                {
                    // add stuff here later
                }
                else if (currentMarker is EmployeeMarker)
                {
                    // add stuff here later
                }
            }
        }

        // Set Custom Icons
        void mainMap_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
            bool foundMarker = false;
            if (currentMarker is JobMarker)
            {
                e.UseDefaultCursors = false;
                string fileName = ((JobMarker)currentMarker).IconFileName.Replace("16", "32");
                Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(fileName);
                try
                {
                    Cursor.Current = CreateCursor(bmp, 0, 0);
                    bmp.Dispose();
                    foundMarker = true;
                }
                catch { }
                foundMarker = true;
            }
            else if (currentMarker is EmployeeMarker)
            {
                e.UseDefaultCursors = false;
                string fileName = ((EmployeeMarker)currentMarker).IconFileName.Replace("32", "48");
                Bitmap bmp = (Bitmap)Properties.Resources.ResourceManager.GetObject(fileName);
                try
                {
                    Cursor.Current = CreateCursor(bmp, 0, 0);
                    bmp.Dispose();
                    foundMarker = true;
                }
                catch { }
                foundMarker = true;
            }

            if (!foundMarker)
                e.UseDefaultCursors = e.Effect != DragDropEffects.Copy;
        }

        // Variables to evaluate distance, worked MUCH better than m.LocalArea.Contains method of mousepoint
        int smallestDistance = -1;
        int distance = -1;
        void mainMap_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
        {
            if (currentMarker != null &&
                Control.MouseButtons == System.Windows.Forms.MouseButtons.Left)
            {
                mainMap.SuspendLayout();
                distance = 0;
                smallestDistance = 999999999;
                GMapMarker hoverMarker = null;
                if (currentMarker is JobMarker)
                {
                    foreach (GMapMarker m in jobsOverlay.Markers)
                    {
                        if (m is EmployeeMarker)
                        {
                            distance = 0;
                            distance += Math.Abs(PointToClient(Control.MousePosition).X - m.LocalPosition.X);
                            distance += Math.Abs(PointToClient(Control.MousePosition).Y - m.LocalPosition.Y);
                            if (smallestDistance > distance)
                            {
                                smallestDistance = distance;
                                if (distance < minimumDistanceToHover)
                                {
                                    hoverMarker = m;
                                }
                            }
                            toolStripStatusLabel2.Text = distance.ToString();
                            toolStripStatusLabel1.Text = smallestDistance.ToString();
                            ((EmployeeMarker)m).usebigImage = false;
                        }
                    }
                    if (hoverMarker != null)
                    {
                        ((EmployeeMarker)hoverMarker).usebigImage = true;
                        toolStripStatusLabel1.Text = "Job over Emp";
                    }
                }
                else if (currentMarker is EmployeeMarker)
                {
                    foreach (GMapMarker m in jobsOverlay.Markers)
                    {
                        if (m is JobMarker)
                        {
                            distance = 0;
                            distance += Math.Abs(PointToClient(Control.MousePosition).X - m.LocalPosition.X);
                            distance += Math.Abs(PointToClient(Control.MousePosition).Y - m.LocalPosition.Y);
                            if (smallestDistance < 0.00)
                                smallestDistance = distance;
                            if (smallestDistance > distance)
                            {
                                smallestDistance = distance;
                                if (distance < minimumDistanceToHover)
                                {
                                    hoverMarker = m;
                                }
                            }
                            toolStripStatusLabel2.Text = distance.ToString();
                            toolStripStatusLabel1.Text = smallestDistance.ToString();
                            ((JobMarker)m).useBigImage = false;
                        }
                    }
                    if (hoverMarker != null)
                    {
                        ((JobMarker)hoverMarker).useBigImage = true;
                        toolStripStatusLabel1.Text = "Emp over Job";
                    }
                }
                mainMap.ResumeLayout();
                mainMap.Invalidate(false);
            }
        }

        void mainMap_OnMarkerLeave(GMapMarker item)
        {
            currentMarker = null;
        }

        void mainMap_OnMarkerEnter(GMapMarker item)
        {
            if (item is JobMarker |
                item is EmployeeMarker)
            {
                currentMarker = item;
            }
        }

        void mainMap_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentMarker != null)
            {
                toolStripStatusLabel1.Text = "Start DragDrop";
                mainMap.DoDragDrop(currentMarker, DragDropEffects.Copy);
            }
        }

 


Jul 3, 2010 at 6:24 PM
Edited Jul 3, 2010 at 6:33 PM

O.o that's really something ;} ..is it possible to integrate that inside into control? ...would be definitely be easier for anyone else to deal with it

Jul 3, 2010 at 6:39 PM

Dunno how to do all that :) But I can give code snippets! lol

Jul 3, 2010 at 9:56 PM

One more thing I missed above, the PointToclient method needs to be from the map control.

 

                            distance += Math.Abs(mainMap.PointToClient(Control.MousePosition).X - m.LocalPosition.X);
                            distance += Math.Abs(mainMap.PointToClient(Control.MousePosition).Y - m.LocalPosition.Y);