This sample demonstrates the Toolkit's MapTips control. Hover over
a state and you will see a MapTip appear. Click the MapTip to view
the state's attributes. The MapTip control is declared inside a
Canvas element in the sample's XAML. The state graphics are
generated using a QueryTask in the sample's code-behind. After the
GraphicsLayer has been populated with the state graphics, the
MapTips control is initialized by passing the GraphicsLayer to the
MapTips.GraphicsLayer property.
<UserControlx:Class="ArcGISWPFSDK.LocalMapTipWidget"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:esri="http://schemas.esri.com/arcgis/client/2009"><Gridx:Name="LayoutRoot"><Grid.Resources><LinearGradientBrushx:Key="PanelGradient"EndPoint="0.5,1"StartPoint="0.5,0"><LinearGradientBrush.RelativeTransform><TransformGroup><ScaleTransformCenterY="0.5"CenterX="0.5"/><SkewTransformCenterY="0.5"CenterX="0.5"/><RotateTransformAngle="176"CenterY="0.5"CenterX="0.5"/><TranslateTransform/></TransformGroup></LinearGradientBrush.RelativeTransform><GradientStopColor="#FF145787"Offset="0.16"/><GradientStopColor="#FF3D7FAC"Offset="0.502"/><GradientStopColor="#FF88C5EF"Offset="0.984"/></LinearGradientBrush><esri:SimpleFillSymbolx:Key="DefaultFillSymbol"Fill="#01FFFFFF"BorderBrush="#88000000"BorderThickness="2"/></Grid.Resources><esri:Mapx:Name="MyMap"Extent="-15000000,2000000,-7000000,8000000"WrapAround="True"><esri:ArcGISLocalTiledLayerID="myBaseMap"Path="..\\Data\\TPKs\\Topographic.tpk"/><esri:GraphicsLayerID="MyGraphicsLayer"/></esri:Map><GridHorizontalAlignment="Right"VerticalAlignment="Top"Margin="0,10,10,0"><RectangleStroke="Gray"RadiusX="10"RadiusY="10"Fill="{StaticResource PanelGradient}"Margin="0,0,0,5"><Rectangle.Effect><DropShadowEffect/></Rectangle.Effect></Rectangle><RectangleFill="#FFFFFFFF"Stroke="DarkGray"RadiusX="5"RadiusY="5"Margin="10,10,10,15"/><TextBlockText="Hover over a state and click to see the Toolkit MapTip."Margin="25,20,25,25"TextAlignment="Center"Foreground="Black"/></Grid><CanvasHorizontalAlignment="Left"VerticalAlignment="Top"><esri:MapTipx:Name="MyMapTip"BorderBrush="#99000000"BorderThickness="1"Title="{Binding [STATE_NAME]}"VerticalOffset="10"HorizontalOffset="10"Background="#DDFFFFFF"Foreground="Black"/></Canvas></Grid></UserControl>
using System;
using System.Windows.Controls;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Local;
namespace ArcGISWPFSDK
{
publicpartialclass LocalMapTipWidget : UserControl
{
LocalMapService _mapService;
public LocalMapTipWidget()
{
InitializeComponent();
LocalMapService.GetServiceAsync("..\\Data\\MPKS\\USCitiesStates.mpk", (localMapService) =>
{
_mapService = localMapService;
QueryTask queryTask = new QueryTask();
queryTask.Url = _mapService.UrlMapService + "/2";
queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
Query query = new ESRI.ArcGIS.Client.Tasks.Query();
query.OutSpatialReference = MyMap.SpatialReference;
query.ReturnGeometry = true;
query.Where = "1=1";
query.OutFields.Add("*");
queryTask.ExecuteAsync(query);
});
}
privatevoid QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
{
FeatureSet featureSet = args.FeatureSet;
GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
MyMapTip.GraphicsLayer = graphicsLayer;
if (featureSet != null && featureSet.Features.Count > 0)
{
foreach (Graphic feature in featureSet.Features)
{
feature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
graphicsLayer.Graphics.Add(feature);
}
}
}
}
}
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Local
Namespace ArcGISWPFSDK
PartialPublicClass LocalMapTipWidget
Inherits UserControl
Private _mapService As LocalMapService
PublicSubNew()
InitializeComponent()
LocalMapService.GetServiceAsync("..\Data\MPKS\USCitiesStates.mpk", Function(localMapService__1)
_mapService = localMapService__1
Dim queryTask AsNew QueryTask()
queryTask.Url = _mapService.UrlMapService & "/2"AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
Dim query As Query = New ESRI.ArcGIS.Client.Tasks.Query()
query.OutSpatialReference = MyMap.SpatialReference
query.ReturnGeometry = True
query.Where = "1=1"
query.OutFields.Add("*")
queryTask.ExecuteAsync(query)
EndFunction)
EndSubPrivateSub QueryTask_ExecuteCompleted(sender AsObject, args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
Dim featureSet As FeatureSet = args.FeatureSet
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
MyMapTip.GraphicsLayer = graphicsLayer
If featureSet IsNotNothingAndAlso featureSet.Features.Count > 0 ThenForEach feature As Graphic In featureSet.Features
feature.Symbol = TryCast(LayoutRoot.Resources("DefaultFillSymbol"), ESRI.ArcGIS.Client.Symbols.Symbol)
graphicsLayer.Graphics.Add(feature)
NextEndIfEndSubEndClassEndNamespace