Catch MouseEventArgs in OnMarkerClick (Winforms)

May 31, 2010 at 10:17 AM

Hi radioman!

First off all, thanks for this fantastic work!

I have some troubles with the OnMarkerClick event.

I like to show a ContextMenu on a right mouseclick. Unfortunatly you don't pass the MouseEventArguments in the OnMarkerClick event. Is there a nice way to do that?

 

The only thing i can do is to declare a own OnMarkerClick event, and hide your implementation, but i can't get the Core.IsDragging, cause it's declared as internal.

 

protected override void OnMouseClick(MouseEventArgs e)
{
	if (e.Button != MouseButtons.Left)
	{
		for (int i = Overlays.Count - 1; i >= 0; i--)
		{
			GMapOverlay o = Overlays[i];
			if (o != null && o.IsVisibile)
			{
				foreach (GMapMarker m in o.Markers)
				{
					if (m.Visible)
					{
						if (m.LocalArea.Contains(e.X, e.Y))
						{
							if (MarkerClickWithArguments != null)
							{
								MarkerClickWithArguments(m, e);
								break;
							}
						}
					}
				}
			}
		}
	}

	base.OnMouseClick(e);
}

 

Greetz from Austria,

Manuel

May 31, 2010 at 11:01 AM

hey!

..why do you need mouse arguments?

May 31, 2010 at 11:58 AM

Hey!

I'd like to show different context menus for different types of custom markers.

My actual solution works, but i'm scared to miss the Core.IsDragging in my overridden OnMouseClick event.

private void MapControl_OnMarkerClick(GMapMarker item)
{
    if (item is GMapMarkerSV)
        Controller.selectSVMarker((item as GMapMarkerSV).sv);
    if (item is GMapMarkerSF)
        Controller.selectSFMarker((item as GMapMarkerSF).sf);
    if (item is GMapMarkerZugewieseneKundentermine)
        Controller.selectZugewieseneKundentermineMarker((item as GMapMarkerZugewieseneKundentermine).sf);
}

void MapControl_MarkerClickWithArguments(GMapMarker item, MouseEventArgs e)
{
    if (e.Button == MouseButtons.Right)
    {
        ToolTipGridControl.Hide();
        if (item is GMapMarkerSV)
            Controller.showContextMenuSVMarker((item as GMapMarkerSV).sv, MousePosition);
        if (item is GMapMarkerSF)
            Controller.showContextMenuSFMarker((item as GMapMarkerSF).sf, MousePosition);
    }
}

May 31, 2010 at 12:02 PM

forgot the imporant thing.

i've got over 70k of markers, so creating a new context menu for each of the markers isn't not really fast... (was my first solution)

May 31, 2010 at 12:20 PM

70k o.O and how it's performance?

May 31, 2010 at 2:29 PM

it's not that bad :) But they are static (not moving, like in your transport-demo).

I'm using a own Caching-Provider for Asa11 (Sybase). Only a bit laggy if i'm zoomed out fully :D, but thats not the default case.

Do you think you can pass the MouseEventArgs by default? Or is my solution ok (Core.IsDragging doesn't seem to be needet in this case?)?

May 31, 2010 at 4:23 PM

Aye, i'll include it in the next update ;}

Jun 1, 2010 at 8:33 AM

Great!

I'm thinking about a own codeplex project to provide a range of custom markers, helpers and other stuff... :)