首页 > 代码库 > maptip属性
maptip属性
前台
<UserControl x:Class="ArcGISSilverlightSDK.GraphicsMapTip" 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"> <Grid x:Name="LayoutRoot">
<Grid.Resources> <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="#01FFFFFF" BorderBrush="#88000000" BorderThickness="2" /> <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="6" Style="Diamond" /> </Grid.Resources>
<esri:Map x:Name="MyMap" WrapAround="True" Extent="-15000000,2000000,-7000000,8000000"> <esri:ArcGISTiledMapServiceLayer ID="BaseMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" />
<esri:GraphicsLayer ID="StatesGraphicsLayer"> <esri:GraphicsLayer.MapTip> <Border esri:GraphicsLayer.MapTipHideDelay="00:00:01.5" CornerRadius="10" BorderBrush="#FF222957" BorderThickness="3" Margin="0,0,15,15"> <Border.Background> <LinearGradientBrush EndPoint="1.038,1.136" StartPoint="0.015,0.188"> <GradientStop Color="#FFD1DFF2"/> <GradientStop Color="#FF092959" Offset="0.946"/> </LinearGradientBrush> </Border.Background> <Border.Effect> <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" /> </Border.Effect> <StackPanel Orientation="Vertical" Margin="20,15,20,15"> <StackPanel Orientation="Horizontal" Margin="0,0,0,6"> <TextBlock Text="State Name: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="12" /> <TextBlock Text="{Binding [STATE_NAME]}" Foreground="#FFFFFFFF" FontSize="12" FontStyle="Italic" FontFamily="Portable User Interface" /> </StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Text="Population 2007: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="12" /> <TextBlock Text="{Binding [POP2007]}" Foreground="#FFFFFFFF" FontSize="12" FontStyle="Italic" FontFamily="Portable User Interface" /> </StackPanel> </StackPanel> </Border> </esri:GraphicsLayer.MapTip> </esri:GraphicsLayer>
<esri:GraphicsLayer ID="CitiesGraphicsLayer"> <esri:GraphicsLayer.MapTip> <Border BorderBrush="DarkGray" CornerRadius="13" BorderThickness="1" Margin="0,0,15,15"> <Border.Effect> <DropShadowEffect ShadowDepth="10" BlurRadius="14" Direction="300" /> </Border.Effect> <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="5" BorderBrush="#77FF0000"> <StackPanel Orientation="Vertical" HorizontalAlignment="Center" Margin="10"> <StackPanel Orientation="Horizontal"> <TextBlock Text="City Name: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center"/> <TextBlock Text="{Binding [CITY_NAME]}" HorizontalAlignment="Left" VerticalAlignment="Center" /> </StackPanel> <StackPanel Orientation="Horizontal"> <TextBlock Text="Population: " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center" /> <TextBlock Text="{Binding [POP1990]}" HorizontalAlignment="Left" VerticalAlignment="Center" /> </StackPanel> </StackPanel> </Border> </Border> </esri:GraphicsLayer.MapTip> </esri:GraphicsLayer>
</esri:Map>
<Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,10,0" > <Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" > <Rectangle.Effect> <DropShadowEffect/> </Rectangle.Effect> </Rectangle> <Rectangle Fill="#DDFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,14" Height="42" /> <TextBlock Text="Hover over a state or city to see the GraphicsLayer MapTip." TextAlignment="Center" Margin="25,25,25,25" /> </Grid>
</Grid> </UserControl>
后台
using System; using System.Windows.Controls; using ESRI.ArcGIS.Client.Tasks;
namespace ArcGISSilverlightSDK { public partial class GraphicsMapTip : UserControl { public GraphicsMapTip() { InitializeComponent();
MyMap.PropertyChanged += MyMap_PropertyChanged; }
void MyMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "SpatialReference") { StatesGraphicsLayerLoad(); CitiesGraphicsLayerLoad(); MyMap.PropertyChanged -= MyMap_PropertyChanged; } }
void StatesGraphicsLayerLoad() { ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { Geometry = new ESRI.ArcGIS.Client.Geometry.Envelope(-180, 0, 0, 90) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326) }, ReturnGeometry = true, OutSpatialReference = MyMap.SpatialReference }; query.OutFields.Add("*");
QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5"); queryTask.ExecuteCompleted += StatesGraphicsLayerQueryTask_ExecuteCompleted; queryTask.ExecuteAsync(query); }
void StatesGraphicsLayerQueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs queryArgs) { if (queryArgs.FeatureSet == null) return;
FeatureSet resultFeatureSet = queryArgs.FeatureSet; ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer = MyMap.Layers["StatesGraphicsLayer"] as ESRI.ArcGIS.Client.GraphicsLayer;
if (resultFeatureSet != null && resultFeatureSet.Features.Count > 0) { foreach (ESRI.ArcGIS.Client.Graphic graphicFeature in resultFeatureSet.Features) { graphicFeature.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(graphicFeature); } } }
private void CitiesGraphicsLayerLoad() { ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { Geometry = new ESRI.ArcGIS.Client.Geometry.Envelope(-180, 0, 0, 90) { SpatialReference = new ESRI.ArcGIS.Client.Geometry.SpatialReference(4326) }, ReturnGeometry = true, OutSpatialReference = MyMap.SpatialReference }; query.OutFields.Add("*"); query.Where = "POP1990 > 100000"; QueryTask queryTask = new QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StatesCitiesRivers_USA/MapServer/0"); queryTask.ExecuteCompleted += CitiesGraphicsLayerQueryTask_ExecuteCompleted; queryTask.ExecuteAsync(query); }
void CitiesGraphicsLayerQueryTask_ExecuteCompleted(object sender, QueryEventArgs queryArgs) { if (queryArgs.FeatureSet == null) return;
FeatureSet resultFeatureSet = queryArgs.FeatureSet; ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer = MyMap.Layers["CitiesGraphicsLayer"] as ESRI.ArcGIS.Client.GraphicsLayer;
if (resultFeatureSet != null && resultFeatureSet.Features.Count > 0) { foreach (ESRI.ArcGIS.Client.Graphic graphicFeature in resultFeatureSet.Features) { graphicFeature.Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; graphicsLayer.Graphics.Add(graphicFeature); } } } } }
maptip属性