# Feature Tooltip or hover text while over feature(line, multiline, poly, etc.)

**URL:** <https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082>\
**Category:** WPF\
**Created:** [October 9, 2011, 7:28am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082 "2011-10-09T07:28:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/michael4/32/24915_2.png) [@Michael4](https://community.thinkgeo.com/u/Michael4)\
**Post date:** [October 9, 2011, 7:28am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/1 "2011-10-09T07:28:41Z")

</div>

What&nbsp;is&nbsp;the&nbsp;easiest&nbsp;way&nbsp;to&nbsp;programatically&nbsp;add&nbsp;a&nbsp;tooltip&nbsp;like&nbsp;effect&nbsp;to&nbsp;a&nbsp;feature?&nbsp;&nbsp;For&nbsp;instance&nbsp;I&nbsp;have&nbsp;a&nbsp;lineshape&nbsp;that&nbsp;I&nbsp;want&nbsp;to&nbsp;display&nbsp;a&nbsp;tooltip&nbsp;when&nbsp;the&nbsp;user&nbsp;hovers&nbsp;over&nbsp;the&nbsp;line.&nbsp;&nbsp;Same&nbsp;goes&nbsp;for&nbsp;polygons&nbsp;and&nbsp;multilineshapes...e.g.,&nbsp;I&nbsp;was&nbsp;thinking&nbsp;of&nbsp;something&nbsp;like&nbsp;this:

&nbsp;

`Dim multilineShape As MultilineShape = CType(BaseShape.CreateShapeFromWellKnownData(mLineTxt), MultilineShape)   'Would like to do something like this:multilineShape.Tooltip = _myTooltipTextDim feature As New Feature(multilineShape) 'Or...Would like to do something like this: feature.Tooltip = _myTooltipText  Dim MyinMemoryFeatureLayer As New InMemoryFeatureLayerMyinMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(clr, lineWidth, False)MyinMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20  MyinMemoryFeatureLayer.InternalFeatures.Add(feature)  LinesOverlay.Layers.Add("SF_LineLayer_" & i.ToString, MyinMemoryFeatureLayer)`

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [October 10, 2011, 2:47pm UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/2 "2011-10-10T14:47:01Z")

</div>

Hello&nbsp;Michael,&nbsp;  
  
  
  
Thank&nbsp;you&nbsp;for&nbsp;your&nbsp;post&nbsp;and&nbsp;idea,&nbsp;but&nbsp;sorry&nbsp;to&nbsp;say,&nbsp;we&nbsp;only&nbsp;allow&nbsp;to&nbsp;set&nbsp;tooltip&nbsp;to&nbsp;a&nbsp;feature&nbsp;in&nbsp;2.x&nbsp;version,&nbsp;for&nbsp;now&nbsp;popup&nbsp;or&nbsp;tooltip&nbsp;is&nbsp;not&nbsp;allowed&nbsp;to&nbsp;add&nbsp;to&nbsp;a&nbsp;feature.&nbsp;This&nbsp;feature&nbsp;is&nbsp;supposed&nbsp;to&nbsp;be&nbsp;added&nbsp;to&nbsp;a&nbsp;layer&nbsp;overlay&nbsp;(be&nbsp;added&nbsp;to&nbsp;a&nbsp;layer&nbsp;first&nbsp;and&nbsp;then&nbsp;add&nbsp;the&nbsp;layer&nbsp;to&nbsp;a&nbsp;layer&nbsp;overlay).&nbsp;  
  
  
  
But&nbsp;there&nbsp;is&nbsp;a&nbsp;sample&nbsp;that&nbsp;can&nbsp;show&nbsp;you&nbsp;how&nbsp;to&nbsp;add&nbsp;tooltip&nbsp;to&nbsp;a&nbsp;layer,&nbsp;I&nbsp;hope&nbsp;it&nbsp;can&nbsp;help&nbsp;you.&nbsp;  
  
  
  
Any&nbsp;more&nbsp;questions&nbsp;please&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
  
  
  
Regards,&nbsp;  
  
  
  
Gary

[MapToolTipSample.zip](https://community.thinkgeo.com/uploads/default/original/2X/6/666052b4de986fbaa07731fd90a77cefe1cd08df.zip) (13.9 KB)

---

<div class="post-metadata">

**Author:** ![Michael4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/michael4/32/24915_2.png) [@Michael4](https://community.thinkgeo.com/u/Michael4)\
**Post date:** [October 15, 2011, 6:08am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/3 "2011-10-15T06:08:07Z")

</div>

Thanks&nbsp;Gary…&nbsp;this&nbsp;looks&nbsp;like&nbsp;it&nbsp;will&nbsp;help,&nbsp;but&nbsp;I&nbsp;will&nbsp;have&nbsp;to&nbsp;convert&nbsp;it&nbsp;to&nbsp;a&nbsp;WPF&nbsp;version&nbsp;when&nbsp;I&nbsp;get&nbsp;some&nbsp;time.

---

<div class="post-metadata">

**Author:** ![Michael4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/michael4/32/24915_2.png) [@Michael4](https://community.thinkgeo.com/u/Michael4)\
**Post date:** [October 15, 2011, 1:38pm UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/4 "2011-10-15T13:38:02Z")

</div>

Here&nbsp;is&nbsp;what&nbsp;I&nbsp;did&nbsp;to&nbsp;get&nbsp;it&nbsp;to&nbsp;work:

First,&nbsp;I&nbsp;created&nbsp;a&nbsp;label&nbsp;in&nbsp;XAML:

`<Label Visibility="Hidden" Content="Label" Height="28" HorizontalAlignment="Left" Margin="452,524,0,0" Name="lblMouseOver" VerticalAlignment="Top" />`

The&nbsp;margin&nbsp;is&nbsp;arbitrary,&nbsp;but&nbsp;I&nbsp;stuck&nbsp;the&nbsp;label&nbsp;in&nbsp;the&nbsp;middle&nbsp;of&nbsp;the&nbsp;map&nbsp;for&nbsp;now.

Then&nbsp;in&nbsp;the&nbsp;mousemove:

`    Private Sub WpfMap1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Input.MouseEventArgs) Handles WpfMap1.MouseMove        Dim worldPointShape As PointShape = ExtentHelper.ToWorldCoordinate(WpfMap1.CurrentExtent, New ScreenPointF(e.GetPosition(WpfMap1).X, e.GetPosition(WpfMap1).Y), WpfMap1.ActualWidth, WpfMap1.ActualHeight)        Dim MyOverlay As LayerOverlay = DirectCast(WpfMap1.Overlays("MyOverlay"), LayerOverlay)        Dim showTooltipTolerance As Double = 0.1        For j = 0 To MyOverlay.Layers.Count - 1            Dim MouseChkBox As New RectangleShape(worldPointShape.X - showTooltipTolerance, _                                                       worldPointShape.Y + showTooltipTolerance, _                                                       worldPointShape.X + showTooltipTolerance, _                                                       worldPointShape.Y - showTooltipTolerance)            Dim bitmapLayer As InMemoryFeatureLayer = MyOverlay.Layers(j)            Dim crossed As Boolean = False            For i As Integer = 0 To bitmapLayer.InternalFeatures.Count - 1                If MouseChkBox.GetDistanceTo(bitmapLayer.InternalFeatures(i), GeographyUnit.DecimalDegree, DistanceUnit.Mile) <= showTooltipTolerance Then crossed = True            Next            If crossed Then                lblMouseOver.Margin = New Thickness(Border2.Margin.Left + e.GetPosition(WpfMap1).X _                                                    , Border2.Margin.Top + e.GetPosition(WpfMap1).Y _                                                    , Border2.Margin.Right - e.GetPosition(WpfMap1).X _                                                    , Border2.Margin.Bottom - e.GetPosition(WpfMap1).Y)                lblMouseOver.Content = "some content"                lblMouseOver.Visibility = Visibility.Visible            Else                lblMouseOver.Visibility = Visibility.Hidden            End If        Next    End Sub`

Then&nbsp;I&nbsp;did&nbsp;not&nbsp;need&nbsp;the&nbsp;tooltip&nbsp;class&nbsp;and&nbsp;the&nbsp;performance&nbsp;seem&nbsp;great.&nbsp;&nbsp;I&nbsp;had&nbsp;the&nbsp;map&nbsp;inside&nbsp;a&nbsp;border&nbsp;(border2)&nbsp;with&nbsp;no&nbsp;margin&nbsp;between&nbsp;the&nbsp;map&nbsp;and&nbsp;the&nbsp;border:

`        <Border BorderBrush="Silver" BorderThickness="1" Height="582" HorizontalAlignment="Center" Margin="328,36,-1,263" Name="Border2" VerticalAlignment="Center" Width="1046">            <my:WpfMap Name="WpfMap1" BorderThickness="1" BorderBrush="#FFBA3939" />        </Border>`

---

<div class="post-metadata">

**Author:** ![Gary2](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/g/49beb7/32.png) [@Gary2](https://community.thinkgeo.com/u/Gary2)\
**Post date:** [October 17, 2011, 11:33am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/5 "2011-10-17T11:33:43Z")

</div>

Hello&nbsp;Michael,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I’m&nbsp;glad&nbsp;you&nbsp;made&nbsp;it&nbsp;and&nbsp;thank&nbsp;you&nbsp;very&nbsp;much&nbsp;to&nbsp;post&nbsp;it,&nbsp;that&nbsp;will&nbsp;help&nbsp;others&nbsp;need&nbsp;this.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Regards,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Gary

---

<div class="post-metadata">

**Author:** ![Kris](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/k/82dd89/32.png) [@Kris](https://community.thinkgeo.com/u/Kris)\
**Post date:** [April 22, 2013, 10:13am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/6 "2013-04-22T10:13:22Z")

</div>

Hi,&nbsp;  
&nbsp;&nbsp;  
&nbsp;I&nbsp;was&nbsp;looking&nbsp;through&nbsp;the&nbsp;forum&nbsp;to&nbsp;find&nbsp;how&nbsp;to&nbsp;put&nbsp;in&nbsp;tooltips&nbsp;and&nbsp;thankfully&nbsp;found&nbsp;this&nbsp;example.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Is&nbsp;there&nbsp;any&nbsp;plan&nbsp;to&nbsp;integrate&nbsp;this&nbsp;functionality&nbsp;into&nbsp;WpfMap&nbsp;natively?&nbsp;  
&nbsp;&nbsp;  
&nbsp;Personally,&nbsp;I&nbsp;think&nbsp;that&nbsp;it&nbsp;is&nbsp;a&nbsp;fundamental&nbsp;service&nbsp;that&nbsp;needs&nbsp;to&nbsp;be&nbsp;there&nbsp;and&nbsp;I&nbsp;would&nbsp;rather&nbsp;not&nbsp;write&nbsp;it&nbsp;in&nbsp;myself&nbsp;if&nbsp;it&nbsp;is&nbsp;planned&nbsp;to&nbsp;be&nbsp;integrated&nbsp;in&nbsp;some&nbsp;release.&nbsp;  
&nbsp;&nbsp;  
&nbsp;Kris

---

<div class="post-metadata">

**Author:** ![Edgar](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/e/b487fb/32.png) [@Edgar](https://community.thinkgeo.com/u/Edgar)\
**Post date:** [April 23, 2013, 10:36pm UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/7 "2013-04-23T22:36:00Z")

</div>

Hi&nbsp;Kris  
&nbsp;  
Thanks&nbsp;for&nbsp;your&nbsp;post,&nbsp;sorry&nbsp;to&nbsp;say&nbsp;that&nbsp;we&nbsp;don’t&nbsp;support&nbsp;“feature&nbsp;tooltip”&nbsp;for&nbsp;now.&nbsp;You&nbsp;can&nbsp;vote&nbsp;this&nbsp;enhancement&nbsp;to&nbsp;[helpdesk.thinkgeo.com/EnhancementTracker](http://helpdesk.thinkgeo.com/EnhancementTracker).&nbsp;This&nbsp;captures&nbsp;the&nbsp;enhancement&nbsp;request&nbsp;and&nbsp;provides&nbsp;visibility&nbsp;to&nbsp;the&nbsp;customer&nbsp;letting&nbsp;them&nbsp;know&nbsp;that&nbsp;the&nbsp;enhancement&nbsp;is&nbsp;on&nbsp;a&nbsp;list&nbsp;somewhere&nbsp;and&nbsp;that&nbsp;popularity&nbsp;of&nbsp;the&nbsp;enhancement&nbsp;helps&nbsp;set&nbsp;the&nbsp;priority&nbsp;of&nbsp;when&nbsp;the&nbsp;enhancement&nbsp;would&nbsp;be&nbsp;added&nbsp;to&nbsp;the&nbsp;product.&nbsp;This&nbsp;option&nbsp;doesn’t&nbsp;carry&nbsp;any&nbsp;cost&nbsp;for&nbsp;you.  
&nbsp;  
Or&nbsp;if&nbsp;you&nbsp;need&nbsp;this&nbsp;function&nbsp;immediately,&nbsp;your&nbsp;account&nbsp;rep&nbsp;can&nbsp;contact&nbsp;you&nbsp;for&nbsp;a&nbsp;professional&nbsp;services.&nbsp;  
&nbsp;  
Another&nbsp;thing&nbsp;is&nbsp;that&nbsp;there&nbsp;is&nbsp;an&nbsp;elevation&nbsp;place&nbsp;in&nbsp;Micheal’s&nbsp;solution.  
In&nbsp;Wpf\_MouseMove()&nbsp;we&nbsp;could&nbsp;add&nbsp;a&nbsp;timer,&nbsp;and&nbsp;move&nbsp;the&nbsp;code&nbsp;to&nbsp;the&nbsp;timer&nbsp;and&nbsp;let&nbsp;the&nbsp;timer&nbsp;to&nbsp;do&nbsp;the&nbsp;work,&nbsp;that&nbsp;way&nbsp;we&nbsp;don’t&nbsp;need&nbsp;to&nbsp;do&nbsp;the&nbsp;work&nbsp;every&nbsp;time&nbsp;the&nbsp;mouse&nbsp;moves.  
&nbsp;  
Regards,  
Edgar

---

<div class="post-metadata">

**Author:** ![Michael4](https://community.thinkgeo.com/user_avatar/community.thinkgeo.com/michael4/32/24915_2.png) [@Michael4](https://community.thinkgeo.com/u/Michael4)\
**Post date:** [July 13, 2013, 11:17am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/8 "2013-07-13T11:17:57Z")

</div>

As&nbsp;I&nbsp;use&nbsp;the&nbsp;above&nbsp;code&nbsp;for&nbsp;a&nbsp;large&nbsp;number&nbsp;of&nbsp;polygons&nbsp;(20k&nbsp;+),&nbsp;I&nbsp;was&nbsp;getting&nbsp;impacted&nbsp;by&nbsp;performance&nbsp;due&nbsp;to&nbsp;iteration.&nbsp;&nbsp;So&nbsp;I&nbsp;modified&nbsp;the&nbsp;code&nbsp;to:

> `Private`&nbsp;`Sub`&nbsp;`WpfMap1_MouseMove(``ByVal`&nbsp;`sender ``As`&nbsp;`Object``, ``ByVal`&nbsp;`e ``As`&nbsp;`System.Windows.Input.MouseEventArgs) ``Handles`&nbsp;`wpfMap1.MouseMove`  
> `    ``Dim`&nbsp;`imfLayer ``As`&nbsp;`InMemoryFeatureLayer = ``CType``(wpfMap1.FindFeatureLayer(``"MyIMFL"``), InMemoryFeatureLayer)`  
> `    ``If`&nbsp;`imfLayer ``Is`&nbsp;`Nothing`&nbsp;`Then`&nbsp;`Exit`&nbsp;`Sub`&nbsp;`'No layer exists so exit`  
> `    ``'Define bounary in pixels aroun poygon to trigger tooltip`  
> `    ``Dim`&nbsp;`screenBuffer ``As`&nbsp;`Integer`&nbsp;`= 5`  
> `    ``'Maintain buffer at any zoom level`  
> `    ``Dim`&nbsp;`currentPointF ``As`&nbsp;`New`&nbsp;`ScreenPointF(e.GetPosition(wpfMap1).X, e.GetPosition(wpfMap1).Y)`  
> `    ``Dim`&nbsp;`bufferPointF ``As`&nbsp;`New`&nbsp;`ScreenPointF(currentPointF.X + screenBuffer, currentPointF.Y)`  
> `    ``Dim`&nbsp;`distanceBuffer ``As`&nbsp;`Double`&nbsp;`= ExtentHelper.GetWorldDistanceBetweenTwoScreenPoints(wpfMap1.CurrentExtent, currentPointF, bufferPointF, wpfMap1.ActualWidth, wpfMap1.ActualHeight, wpfMap1.MapUnit, DistanceUnit.Meter)`  
> `    ``'Make sure there are features`  
> `    ``If`&nbsp;`imfLayer.InternalFeatures.Count > 0 ``Then`  
> `        ``'ToWorldCoordinate requires a column name, so just use a dummy or a real name if there is one`  
> `        ``Dim`&nbsp;`columnNames ``As`&nbsp;`New`&nbsp;`List(Of ``String``)()`  
> `        ``columnNames.Add(``"dummy"``)`  
> &nbsp;  
> `        ``Dim`&nbsp;`features ``As`&nbsp;`Collections.ObjectModel.Collection(Of Feature)`  
> `        ``Dim`&nbsp;`worldPointShape ``As`&nbsp;`PointShape = ExtentHelper.ToWorldCoordinate(wpfMap1.CurrentExtent, ``New`&nbsp;`ScreenPointF(e.GetPosition(wpfMap1).X, e.GetPosition(wpfMap1).Y), wpfMap1.ActualWidth, wpfMap1.ActualHeight)`  
> `        ``SyncLock`&nbsp;`imfLayer   ``'Lock the layer while opening it`  
> `            ``imfLayer.FeatureSource.Open()`  
> `            ``'Get features within the buffer zone distance`  
> `            ``features = imfLayer.FeatureSource.GetFeaturesNearestTo(worldPointShape, wpfMap1.MapUnit, 1, columnNames, distanceBuffer, DistanceUnit.Meter)`  
> `            ``imfLayer.FeatureSource.Close()`  
> `        ``End`&nbsp;`SyncLock`  
> `        ``If`&nbsp;`features.Count > 0 ``Then`&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;`'We got some features`  
> `            ``Dim`&nbsp;`f ``As`&nbsp;`Feature = ``DirectCast``(features(0), Feature) ``'We are only interested in the first one`  
> `            ``Dim`&nbsp;`moc ``As`&nbsp;`MyOwnClass = ``DirectCast``(f.Tag, MyOwnClass)   ``'Get the instance of MyOwnClass from the Tag property`  
> `            ``tblMouseOver.Text = moc.TooltipText     ``'Set the TexBlock text to our tooltip text`  
> &nbsp;  
> `            ``'Show tooltip at top right of pointer, offset by 3 pixels`  
> `            ``tblMouseOver.Margin = ``New`&nbsp;`Thickness(Border2.Margin.Left + e.GetPosition(wpfMap1).X + 3 _`  
> `                                                ``, Border2.Margin.Top + e.GetPosition(wpfMap1).Y - 3 - tblMouseOver.ActualHeight _`  
> `                                                ``, Border2.Margin.Right - e.GetPosition(wpfMap1).X - 3 _`  
> `                                                ``, Border2.Margin.Bottom - e.GetPosition(wpfMap1).Y + 3 + tblMouseOver.ActualHeight)`  
> `            ``tblMouseOver.Visibility = Visibility.Visible`  
> `        ``Else`  
> `            ``tblMouseOver.Visibility = Visibility.Hidden`  
> `        ``End`&nbsp;`If`  
> `    ``Else`  
> `        ``tblMouseOver.Visibility = Visibility.Hidden`  
> `    ``End`&nbsp;`If`  
> `End`&nbsp;`Sub`

  
Using&nbsp;this&nbsp;code&nbsp;appears&nbsp;give&nbsp;very&nbsp;good&nbsp;performance&nbsp;and&nbsp;changing&nbsp;the&nbsp;label&nbsp;to&nbsp;a&nbsp;textblock&nbsp;allows&nbsp;for&nbsp;additional&nbsp;formatting&nbsp;and&nbsp;multiple&nbsp;lines.  
  
I’ve&nbsp;attached&nbsp;a&nbsp;complete&nbsp;working&nbsp;sample&nbsp;that&nbsp;has&nbsp;some&nbsp;very&nbsp;small&nbsp;polygons&nbsp;as&nbsp;a&nbsp;way&nbsp;of&nbsp;testing.  
  
[ThinkGeoExampleMouseOverTooltip.zip](https://community.thinkgeo.com/uploads/default/original/2X/c/c9c9c5b68b37c90e94ec8cb97f7e3fa94da9385a.zip) (1.7 MB)

---

<div class="post-metadata">

**Author:** ![Summer1](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/s/c89c15/32.png) [@Summer1](https://community.thinkgeo.com/u/Summer1)\
**Post date:** [July 15, 2013, 6:05am UTC](https://community.thinkgeo.com/t/feature-tooltip-or-hover-text-while-over-feature-line-multiline-poly-etc/3082/9 "2013-07-15T06:05:00Z")

</div>

Hi&nbsp;Micheal,&nbsp;  
  
  
  
Thank&nbsp;you&nbsp;very&nbsp;much&nbsp;for&nbsp;your&nbsp;sharing&nbsp;this,&nbsp;this&nbsp;will&nbsp;be&nbsp;also&nbsp;helpful&nbsp;to&nbsp;other&nbsp;customers&nbsp;who&nbsp;meet&nbsp;similar&nbsp;problem.&nbsp;&nbsp;And&nbsp;if&nbsp;you&nbsp;have&nbsp;any&nbsp;more&nbsp;question&nbsp;,&nbsp;please&nbsp;feel&nbsp;free&nbsp;to&nbsp;let&nbsp;us&nbsp;know.&nbsp;  
  
  
  
Best&nbsp;Regards&nbsp;  
  
  
  
Summer
