Clickable map items for SharpMap

Topics: SharpMap Project
Nov 25, 2013 at 4:38 PM
Dear all,

I am trying to perform a function, that is clickable items for mapbox, based on Sharpmap DLL. In this function I want to design events for specific GIS items (e.g. point/polyline), when they are imported and mouse over on the item, it can show relevant attribute information on the mapbox, or other GUI.

I plan to add a Marker class which includes Mapbox as field, I will rewrite click moue event and mouse hover event in the function as required. And then I might instance this class and hook relevant events when operate the mapbox. Could you please give me some suggestion on how could perform this, e.g. what type of function I need, and how do I program a popped information item ?
Nov 25, 2013 at 5:36 PM
Did you check sharpmap source? It has an "examples" solution, that shows you how to handle click events and draw on map.

Click download from:
Nov 25, 2013 at 5:50 PM
Dear ahmetkakici,

Thank you for your response. However, I have already looked around what you called "example" solution, it indeed have some code snaps like PointSymbolizer, but I cannot find the codes for clickable items. Could you provide more detailed information? Many thanks!
Nov 25, 2013 at 6:23 PM
For sure.
Here is a drawing example which both handles the click events and draws point/line/polygons
Nov 25, 2013 at 6:59 PM
Edited Nov 25, 2013 at 7:04 PM
Dear ahmetkakici,

Yes, I reviewed this code already. It provides a good example on how to draw point/line as these drawings are triggered by GeometryDefined event. But actually I really want is: if the mouse is move on the point/polyline, it will automatically pop up the information, or you can click the point that you have already defined in order to get other relevant information, like a query function. I guess I might need some SharpMarker class to define the behaviour/events for such point/polyline, but I just stuck here on how to actually integrate them with SharpMap.

I have done some works here, just want to know how to do next step, for example:


    public interface IMarker
        void Paint(Graphics g);

        void Move(PointF p);

        bool Contain(Point p);

        void FillRegion(Region region);

        void SetSelected(bool s);

internal CircleMarker() { }

                public CircleMarker(Coordinates coord)
                    _coordinate = coord;

                public CircleMarker(PointF point, float w, float h)
                    _border = new RectangleF(point.X - w / 2, point.Y - h / 2, w, h);


        #region Method

                 public void Paint(Graphics g)
                    g.FillPath(Brushes.Blue, gp);

                    if (_isSelected)
                        g.DrawPath(Pens.Red, gp);

                 public bool Contain(Point coord)
                     return gp.IsVisible(coord);

                public void Move(PointF point)
                    _border.X += point.X;
                    _border.Y += point.Y;

                public void FillRegion(Region r)

                public void SetSelected(bool s)
                    _isSelected = s;

Nov 26, 2013 at 7:39 AM
You need to subscribe to the
  • MapBox.MouseMove event to keep track of the current mouse position
  • MapBox.Hover event to perform the action you want.
If you want to react to a MouseClick you additionally need to subscribe to either
  • MapBox.MouseClick or
  • MapBox.MouseDown/MapBox.MouseUp