GMap.NET is "great and Powerful, Free, cross platform, open source .NET control. Enable use routing, geocoding, directions and maps from Coogle, Yahoo!, Bing, OpenStreetMap, ArcGIS, Pergo, SigPac, Yendux, Mapy.cz, Maps.lt, iKarte.lv, NearMap, OviMap, CloudMade, WikiMapia, MapQuest in Windows Forms & Presentation, supports caching and runs on windows mobile!"
Readers could find more information on its website at: https://greatmaps.codeplex.com/
Now all of its source code is on GitHub: https://github.com/radioman/greatmaps
Readers are also very encouraged to read some introductions on use of GMap.NET. Among numerous introductions and tutorials available online, I strongly recommend these three as "must read":
GMAP.NET TUTORIAL – MAPS, MARKERS AND POLYGONS
Using GMap.NET – Great Maps for Windows Forms & Presentation
GMap.NET - Great Maps for Windows Forms and Presentation
What makes this control more interesting is though it's open source, you can hardly find a well organized documentation for it. No HELP, no (active enough) forum. So no matter when you encounter a problem while using, do not waste time on searching for documentation, but go to 1: stackoverflow.com and 2: github repository.
In very very rare case, you will be the first on asking question on a particular topic. So do search on stackoverflow before asking. You will find the answers solving your problem, most of the time, partially. If the answers could not sovle you problem completely, at least they will give you some hints. Now you can go to GMap.NET's source code to see what you can find.
Recently when I was working on it, I was stuck in a situation: don't know how to display information (like a TEXT) on the overlays of the control. More precisely, I have to show some polygons on the map, each associate with a property. I need to display this property at the middle of each polygon.
After tons of search, this article almost solved my problem:
http://stackoverflow.com/questions/31267357/how-to-add-tooltip-to-gmap-net-polygon (there is a typo for the original post. the keyword value for IsVisible should be true instead of false, otherwise the marker doesnot show up.)
The solution, in short, is add a marker at the polygon, and put the property information in the tooltip for the marker. The marker used in the answer is a cross, default color is red. So, how to edit it? You may think you should specify some keywords like Pen, Color etc. Yes. After I went to the source code, I found the GMapMarkerCross, which is inherented from GMarker, does have such properties. First you specify the Pen style and Color for the marker itself (make is transparent so you will not see the marker). Then you can edit the tooltip, give it a value (the property as a string), make its bacground Color transparent, make its outline transparent etc.
Here is the code for this purpose:
// gmap is the name of your GMap.NET control in your form
GMapOverlay textOverlay = new GMapOverlay("text");
gmap.Overlays.Add(textOverlay);
textOverlay = addTextOverlays(textOverlay, polygons);
gMapOnLoad(sender, e);
private GMapOverlay addTextOverlays(GMapOverlay overlay, List<Polygon> polygons)
{
// add texts to the overlay, one by one
foreach (polygon in plygons)
{
// the offset of the marker
Point offset = new Point(0, 0));
GMarkerCross crtMarker = new GMarkerCross(new PointLatLng(polygon.lat, polygon.lng)); // position of the marker
crtMarker.Pen = new Pen(Color.Transparent); // marker has lines, draw them with transparent color (i.e., not show them)
crtMarker.ToolTipText = polygon.property.ToString(); // marker's text is the property
crtMarker.IsVisible = true; // marker visible
crtMarker.ToolTipMode = MarkerTooltipMode.Always; // marker always show its tooltip
crtMarker.ToolTip.Offset = offset; // move the tooltip to the appro. center of the cell
crtMarker.ToolTip.Fill = new SolidBrush(Color.Transparent); // the marker's text is in a box, make the box transparent
crtMarker.ToolTip.Stroke = new Pen(Color.Transparent); // no border for the marker's box
// add this marker to the overlay
overlay.Markers.Add(crtMarker);
}
return overlay;
}
I will post a following blog on related to this topic and you will see the outcome of the code.
Note: this code only show the property of the polygon, you need similar codes to add you polygons onto the overlay. For this purpose, please refer to GMAP.NET TUTORIAL – MAPS, MARKERS AND POLYGONS.
Comments, proofread, questions, better ideas and share are all welcome!
public GMarkerCross TextIcon()
ReplyDelete{
GMarkerCross crtMarker = new GMarkerCross(_gmap.FromLocalToLatLng(0, 100)); // position of the marker
crtMarker.Pen = new Pen(Color.Transparent, 10); // marker has lines, draw them with transparent color (i.e., not show them)
crtMarker.ToolTipText = "testttt"; // marker's text
crtMarker.IsVisible = true; // marker visible
crtMarker.ToolTipMode = MarkerTooltipMode.Always; // marker always show its tooltip
crtMarker.ToolTip.Offset = new Point(0, 0); // move the tooltip to the appro. center of the cell
crtMarker.ToolTip.Fill = new SolidBrush(Color.FromArgb(255, Color.Azure)); // background color
crtMarker.ToolTip.Stroke = new Pen(Color.Red); // border color
crtMarker.ToolTip.Font = new Font(FontFamily.GenericMonospace, 10);//font
crtMarker.ToolTip.Foreground = new SolidBrush(Color.Red);//font color
return crtMarker;
}
Thanks in advance.
Delete