ThinkGeo.com    |     Documentation    |     Premium Support

InMemoryMarkerOverlay blocking mouse clicks

I am adding custom markers to my map like this:

//Let's put an icon there
var viewLinkMarkerOverlay = new InMemoryMarkerOverlay() { Name = "view_" + tn.Text, MapControl = this };
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.Image = Properties.Resources.ViewLink;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
this.Overlays.Add(viewLinkMarkerOverlay.Name, viewLinkMarkerOverlay);

Feature vlFeature = new Feature(new PointShape(fc.Easting, fc.Northing));
viewLinkMarkerOverlay.FeatureSource.BeginTransaction();
viewLinkMarkerOverlay.FeatureSource.AddFeature(vlFeature);
viewLinkMarkerOverlay.FeatureSource.CommitTransaction();
this.Overlays.MoveToTop(viewLinkMarkerOverlay.Name);
this.Refresh();

It seems to work fine other than it blocks all Map_Mouse events. I have tested Map_MouseClick, Map_MouseDown, Map_MouseUp, and Map_MouseMove. None of them work if I click or move over my marker. If I move or click anywhere else on the map the events fire as expected.

Help??

Hi David,

That’s because the marker had accept the event and blocked it into map.

Please see this topic which should be helpful: PointMarkerStyle blocks MapClick event?

And as below is my test code:

 public class ClickableMarkerOverlay : InMemoryMarkerOverlay
{
    public event EventHandler Click;

    protected override GeoCollection<Marker> GetMarkersForDrawingCore(RectangleShape boundingBox)
    {
        var markers = base.GetMarkersForDrawingCore(boundingBox);
        foreach (var marker in markers)
        {
            marker.Click -= Click;
            marker.Click += Click;                
        }

        return markers;
    }

}

public class DisplayShapeMap : UserControl
{
    public DisplayShapeMap()
    {
        InitializeComponent();
    }

    private void DisplayMap_Load(object sender, EventArgs e)
    {
        winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
        winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
        winformsMap1.CurrentExtent = new RectangleShape(-139.2, 92.4, 120.9, -93.2);

        ClickableMarkerOverlay viewLinkMarkerOverlay = new ClickableMarkerOverlay() { Name = "test", MapControl = winformsMap1 };            
        viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.Image = Properties.Resources.ThinkGeoLogo;
        viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        winformsMap1.Overlays.Add(viewLinkMarkerOverlay.Name, viewLinkMarkerOverlay);

        Feature vlFeature = new Feature(new PointShape(10, 10));
        viewLinkMarkerOverlay.FeatureSource.BeginTransaction();
        viewLinkMarkerOverlay.FeatureSource.AddFeature(vlFeature);
        viewLinkMarkerOverlay.FeatureSource.CommitTransaction();
        winformsMap1.Overlays.MoveToTop(viewLinkMarkerOverlay.Name);
        

        winformsMap1.MapClick += WinformsMap1_MapClick;
        winformsMap1.MouseClick += WinformsMap1_MouseClick;
        winformsMap1.MouseDown += WinformsMap1_MouseDown;
        winformsMap1.MouseUp += WinformsMap1_MouseUp;
        winformsMap1.MouseMove += WinformsMap1_MouseMove;

        viewLinkMarkerOverlay.Click += ViewLinkMarkerOverlay_Click;

        winformsMap1.Refresh();
    }

    private void ViewLinkMarkerOverlay_Click(object sender, EventArgs e)
    {
        Debug.WriteLine("Marker clicked!!!!");
    }

    private void WinformsMap1_MouseMove(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseMove");
    }

    private void WinformsMap1_MouseUp(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseUp");
    }

    private void WinformsMap1_MouseDown(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseDown");
    }

    private void WinformsMap1_MouseClick(object sender, MouseEventArgs e)
    {
        Debug.WriteLine("MouseClick");
    }

    private void WinformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
    {
        Debug.WriteLine("MapClick");            
    }
}

This only implement click event, you should want to implement all other event which you need in the ClickableMarkerOverlay class.

Regards,

Don

That isn’t working for me. Here is my code, did I miss something?

public class ClickableInMemoryMarkerOverlay : InMemoryMarkerOverlay
{
    public event EventHandler Click;

    protected override GeoCollection<Marker> GetMarkersForDrawingCore(RectangleShape boundingBox)
    {
        var markers = base.GetMarkersForDrawingCore(boundingBox);
        foreach (var marker in markers)
        {
            marker.Click -= Click;
            marker.Click += Click;
        }

        return markers;
    }

Use:

var viewLinkMarkerOverlay = new ClickableInMemoryMarkerOverlay() { Name = "view_" + ViewName, MapControl = this };
var linkIcon = new Bitmap(Properties.Resources.ViewLink, new Size(30, 30));
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.Image = (System.Drawing.Image)linkIcon;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.Width = 30;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.Height = 30;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.XOffset = -15;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.DefaultPointMarkerStyle.YOffset = -15;
viewLinkMarkerOverlay.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
this.Overlays.Add(viewLinkMarkerOverlay.Name, viewLinkMarkerOverlay);

Feature vlFeature = new Feature(new PointShape(fc.Easting, fc.Northing));
viewLinkMarkerOverlay.FeatureSource.BeginTransaction();
viewLinkMarkerOverlay.FeatureSource.AddFeature(vlFeature);
viewLinkMarkerOverlay.FeatureSource.CommitTransaction();

this.Overlays.MoveToTop(viewLinkMarkerOverlay.Name);

viewLinkMarkerOverlay.Click += ViewLinkMarkerOverlay_Click;

this.Refresh();

The ViewLinkMarkerOverlay_Click handler is never called.

I understand the goal here and am mystified as to how the ClickableInMemoryMarkerOverlay.Click event ever gets raised. Isn’t there supposed to be a line like this somewhere in ClickableInMemoryMarkerOverlay?

if (Click != null) Click();

Hi David,

It looks the code you are using is the same as mine.

So please try to put the attached files into the HowDoISample project to replace your DisplayASimpleMap sample, and you should can see the debug write “Marker clicked!!!” when you click on ThinkgeoLogo on map.

8162.zip (4.8 KB)

Please let me know whether that works in your machine.

Regards,

Don

Running you sample produces the ‘Marker Clicked!!!’ message whenever I click inside the green box. Clicking outside of the green box results in a ‘Mouse Down Mouse Click Mouse Up’ triplet. Clicking on the Think Geo logo produced no events at all.

Hi David,

Why your screen shot shows Map Suite 4.5? Please make sure the dll you are using is or latest version.

Regards,

Don

It works in version 9 both in your sample application and in my application. Now to get ‘them’ to approve the cost to update.

These is an issue with moving up to version 9 however, please look for my next issue.

Dave

Hi Dave,

We will reply you in the other topic.

Regards,

Don

When I said ‘it works’ I had not tried right-clicking. The left-click event is coming through as hoped, but the right-click event is not. Should there be something like this in my ClickableMarkerOverlay class?

public event EventHandler RightClick;

Dave

Hi Dave,

I tested that today, it looks both left click or right click can fire the “Marker clicked!!!”.

Could you please double check that with my sample?

Regards,

Don

My problem turned out to be the ContextMenu attached to the map. It was intercepting the right-clicks.

One other issue is how to remove a marker layer. Continuing on with your sample app, I changed the Overlay Click event in an attempt to remove the Marker Overlay.

private void ViewLinkMarkerOverlay_Click(object sender, EventArgs e)
{            
    winformsMap1.Overlays.Remove(viewLinkMarkerOverlay);
    winformsMap1.Invalidate();
    winformsMap1.Refresh();
}

This runs without error, but the marker does not disappear. Am I removing the marker layer incorrectly?

Hi David,

It’s a known bug and have been fixed.

Please download the version 9.0.439.0 or higher version, which had fixed this bug.

Regards,

Don

Confirmed… 9.0.439.0 works correctly.

Thank you,
Dave

Hi Dave,

I am glad to hear that fixed.

Regards,

Don