I have a map program that uses 2 overlays with markers on both overlays. The problem I am having is if I hover on a marker in the overlay[0] the tooltip is underneath the markers on overlay[1]. I can override GMapBaloonTool. Is there a way when the tooltip is rendered to force it to the top?
Asked
Active
Viewed 1,021 times
1 Answers
0
3 years later...
The problem is that the map draws overlays one by one. Each overlay has it's own tooltips. Overlays draw later are drawn above the other layers. This may be by design. For me was not ok. So, I changed GmapOverlays.cs, method OnRender: added new parameter, drawOnlyToolTips
.
public virtual void OnRender(Graphics g, bool drawOnlyToolTips = false)
{
if (Control != null)
{
if (Control.RoutesEnabled && !drawOnlyToolTips)
{
foreach (GMapRoute r in Routes)
{
if (r.IsVisible)
{
r.OnRender(g);
}
}
}
if (Control.PolygonsEnabled && !drawOnlyToolTips)
{
foreach (GMapPolygon r in Polygons)
{
if (r.IsVisible)
{
r.OnRender(g);
}
}
}
if (Control.MarkersEnabled)
{
// markers
if (!drawOnlyToolTips)
{
foreach (GMapMarker m in Markers)
{
//if(m.IsVisible && (m.DisableRegionCheck || Control.Core.currentRegion.Contains(m.LocalPosition.X, m.LocalPosition.Y)))
if (m.IsVisible || m.DisableRegionCheck)
{
m.OnRender(g);
}
}
}
// tooltips above
foreach (GMapMarker m in Markers)
{
//if(m.ToolTip != null && m.IsVisible && Control.Core.currentRegion.Contains(m.LocalPosition.X, m.LocalPosition.Y))
if (m.ToolTip != null && m.IsVisible && drawOnlyToolTips)
{
if (!string.IsNullOrEmpty(m.ToolTipText) && (m.ToolTipMode == MarkerTooltipMode.Always || (m.ToolTipMode == MarkerTooltipMode.OnMouseOver && m.IsMouseOver)))
{
m.ToolTip.OnRender(g);
}
}
}
}
}
}
Next, in GMapControl.cs, method protected virtual void OnPaintOverlays(Graphics g), I changed the code in:
foreach (GMapOverlay o in Overlays)
{
if (o.IsVisibile)
{
o.OnRender(g, false); //call without drawing the tooltips
}
}
foreach (GMapOverlay o in Overlays)
{
if (o.IsVisibile)
{
o.OnRender(g, true); //draw only tooltips, after everything else is drawn
}
}

Nițu Alexandru
- 714
- 1
- 11
- 33