Select to view content in your preferred language

SetMapTipHorizontalOffset

941
6
03-24-2011 11:17 AM
KeithGanzenmuller
Frequent Contributor
I am trying to change the MapTip horizontal and vertical offsets in code.
The maptip is defined in XAML off of a FeatureLayer the like this:

Feature layer XAML followed by:
         <esri:GraphicsLayer.MapTip>
                    <Grid esri:GraphicsLayer.MapTipHideDelay="00:00:1.5" SizeChanged="MapTip_SizeChanged" x:Name="MapTipGrid" >
                        <Border Background="Bisque" BorderBrush="BurlyWood" BorderThickness="5" >
                        <StackPanel Orientation="Vertical">
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Project Number: "
                                           FontSize="9"
                                               Name="TextBlock2" />
...more XAML and then
                </esri:GraphicsLayer.MapTip>

            </esri:FeatureLayer>

Everything works fine, including the mouse events on the featurelayer and the size changed on the grid.
Can't figure the mapoffsets though.
Thanks for your help.
Keith.
0 Kudos
6 Replies
DominiqueBroux
Esri Frequent Contributor
The MapTip position is controlled by the 2 GraphicsLayer attached properties : MapTipHorizontalOffset and MapTipVerticalOffset.

Example of usage in XAML:
<esri:GraphicsLayer.MapTip>
<Grid esri:GraphicsLayer.MapTipHideDelay="00:00:1.5" SizeChanged="MapTip_SizeChanged" x:Name="MapTipGrid"
esri:GraphicsLayer.MapTipHorizontalOffset="20" esri:GraphicsLayer.MapTipVerticalOffset="20">
<Border Background="Bisque" BorderBrush="BurlyWood" BorderThickness="5" >
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Project Number: "
FontSize="9"
Name="TextBlock2" />
...more XAML and then
</esri:GraphicsLayer.MapTip>


It's also possible to set them by code.
Look at this excellent blog post : http://blogs.esri.com/Dev/blogs/silverlightwpf/archive/2010/09/30/How-to-keep-MapTips-in-the-Map.asp.... The maptip offsets are set by code in order to keep the maptip inside the map.
0 Kudos
KeithGanzenmuller
Frequent Contributor
Thanks Dominique.
I've read that blog post and its similar to what I want to do, I was hoping to access the GraphicsLayer.SetMapTipHorizontalOffset more directly. It might not be possible, in which case I will follow the directions in the blog.
My thought was, in the future, there might be other times I want to move the maptip based on some event other than its proximity to the edge of the screen.
0 Kudos
DominiqueBroux
Esri Frequent Contributor

I was hoping to access the GraphicsLayer.SetMapTipHorizontalOffset more directly. It might not be possible,

Once you have a graphicslayer, setting the maptip offsets is relatively direct:
graphicsLayer.MapTip.SetValue(GraphicsLayer.MapTipHorizontalOffsetProperty, horizontalOffset);
graphicsLayer.MapTip.SetValue(GraphicsLayer.MapTipVerticalOffsetProperty, verticalOffset);


Then the difficulty might be to calculate these offsets and to define the event to wire. The blog post is giving an example but for sure this can be adapted to your need.
0 Kudos
KeithGanzenmuller
Frequent Contributor
Ok, I see, I think that will be exactly what I need.
Thanks again for all of your help.
Keith
0 Kudos
KeithGanzenmuller
Frequent Contributor
This is what I came up with for a simple way to move my maptips.

    Private Sub CIP_MouseEnter(sender As System.Object, e As ESRI.ArcGIS.Client.GraphicMouseEventArgs) Handles CIP.MouseEnter
        mypoint = e.GetPosition(CType(myMap, System.Windows.UIElement))
    End Sub

    Private Sub CIP_MouseLeave(sender As System.Object, e As ESRI.ArcGIS.Client.GraphicMouseEventArgs)

    End Sub

    Private Sub MapTip_SizeChanged(sender As System.Object, e As System.Windows.SizeChangedEventArgs) Handles MapTipGrid.SizeChanged ' TextBlock2.SizeChanged
        Dim voffset, hoffset As Double ' vertical and horizontal offsets
        Dim CIPLayer As GraphicsLayer = CType(myMap.Layers("Capital Improvements"), GraphicsLayer) ' The graphicslayer in question
        If (myMap.ActualWidth - mypoint.X < e.NewSize.Width) Then  'if the point is withing maptip width of the edge, flip it to the other side by
            hoffset = -1 * (e.NewSize.Width + 10)                   'moving it the maptipwidth + 10 offest
        Else
            hoffset = 5
        End If

        If (myMap.ActualHeight - mypoint.Y < e.NewSize.Height) Then
            voffset = -1 * (e.NewSize.Height + 10)
        Else
            voffset = 5
        End If
        CIPLayer.MapTip.SetValue(GraphicsLayer.MapTipHorizontalOffsetProperty, hoffset)
        CIPLayer.MapTip.SetValue(GraphicsLayer.MapTipVerticalOffsetProperty, voffset)
    End Sub

It definitely works but if someone knows of a reason not to do it this way I am all ears or I suppose eyes in this case.
0 Kudos
JoshPorter
Occasional Contributor
Thanks kganz, this works great!
0 Kudos