1). Can we put Map Tips on a dynamic map layer (we want to use the symbology from the map service)? If not then we need to use a Feautre Layer or Graphics layer and then define the symbology which would be very painful, correct??
2). Assuming we need to create a Graphics/Feature layer for the Map Tips how do we define a standard map Tip / Info Window template that can be used for all Graphics/Feature Layers added to the map given that each Graphics/Feature Layer will have a different set of attribtutes to display? Is the Binding for this straight forward.
<DataTemplate x:Key="MyDynamicMapInfoWindowTemplate"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <ItemsControl ItemsSource="{Binding Keys}" Grid.Column="0" /> <ItemsControl ItemsSource="{Binding Values}" Grid.Column="1" /> </Grid> </DataTemplate>
<esri:Map x:Name="MyMap" MouseClick="MyMap_MouseClick"> <esri:ArcGISDynamicMapServiceLayer ID="MyLayer" Url="http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer" /> </esri:Map> <esri:InfoWindow x:Name="MyInfoWindow" Map="{Binding ElementName=MyMap}" ContentTemplate="{StaticResource MyDynamicMapInfoWindowTemplate}" MouseLeftButtonUp="MyInfoWindow_MouseLeftButtonUp" />
private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e) { ArcGISDynamicMapServiceLayer layer = MyMap.Layers["MyLayer"] as ArcGISDynamicMapServiceLayer; IdentifyParameters identifyParams = new IdentifyParameters() { Geometry = e.MapPoint, MapExtent = MyMap.Extent, Width = (int)MyMap.ActualWidth, Height = (int)MyMap.ActualHeight, LayerOption = LayerOption.visible, SpatialReference = MyMap.SpatialReference }; IdentifyTask identifyTask = new IdentifyTask(layer.Url); identifyTask.ExecuteCompleted += identifyTask_ExecuteCompleted; identifyTask.ExecuteAsync(identifyParams, e.MapPoint); } void identifyTask_ExecuteCompleted(object sender, IdentifyEventArgs e) { if (e.IdentifyResults != null && e.IdentifyResults.Count > 0) { MapPoint clickPoint = e.UserState as MapPoint; foreach (var result in e.IdentifyResults) { MyInfoWindow.Anchor = clickPoint; MyInfoWindow.IsOpen = true; //Since a ContentTemplate is defined, Content will define the DataContext for the ContentTemplate MyInfoWindow.Content = result.Feature.Attributes; return; } } }
If you require your map tip to open on mouse hover, you can only do so by using a GraphicsLayer (FeatureLayer inherits from GraphicsLayer). If you want to use the symbology defined by the map service, you should use FeatureLayer.
The optimal way is to open map tip on mouse click so you would not need to use GraphicsLayer. You can perform an IdentifyTask and use the IdentifyResults to display in your InfoWindow.
The FeatureLayer default symbology (for polygons) is opaque red fill. How do I get it to read the symbology defined in the MapService (it is a regular 9.3.1 MapService not a FeatureService)?
The IdentifyTask would return all attributes from the Layer in question. What if I only wanted a subset of attributes. In a FeatureLayer I can specify the OutFields??
IDictionary<string, object> attributes = new Dictionary<string, object>(); foreach (var item in result.Feature.Attributes) if (outfields.Contains(item.Key)) attributes.Add(item.Key, item.Value); MyInfoWindow.Content = attributes;
<Canvas HorizontalAlignment="Left" VerticalAlignment="Top" > <esri:MapTip x:Name="MyMapTip" BorderBrush="#99000000" BorderThickness="1" VerticalOffset="10" Opacity="0.7" HorizontalOffset="10" Background="#DDFFFFFF" /> </Canvas>
..snippet MyMapTip.GraphicsLayer = _foodFeatureLayer; MyMapTip.Expand(false); MyMapTip.Title = _foodFeatureLayer.ID; Map.Layers.Add(_foodFeatureLayer);
If you need to change the behavior of the Toolkit.MapTip, you can download source from here: http://esrisilverlight.codeplex.com/.
void MyMapTip_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e) { if (e.NewSize != null && e.NewSize.Height > 0 && e.NewSize.Width > 0) MyMapTip.Expand(true); }
Is there a way to add a Title or label to info window? I'm looking to make it the layer name.
void featureLayer_Initialized(object sender, System.EventArgs e) { FeatureLayer featureLayer = sender as FeatureLayer; Map.Layers.Add(featureLayer); string layerName = featureLayer.LayerInfo.Name.ToString(); MapTip maptip= new MapTip(); maptip.Title = layerName; maptip.GraphicsLayer = featureLayer; }
<DataTemplate x:Key="MyInfoWindowTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock Text="{Binding [LayerName]}" FontWeight="Bold" /> <TextBlock Text="{Binding [STATE_NAME]}" Foreground="Black" FontSize="12" Grid.Row="1" /> </Grid> </DataTemplate>
void it_ExecuteCompleted(object sender, IdentifyEventArgs e) { MapPoint clickPoint = e.UserState as MapPoint; foreach (var result in e.IdentifyResults) { MyInfoWindow.Anchor = clickPoint; MyInfoWindow.IsOpen = true; result.Feature.Attributes ["LayerName"] = result.LayerName; MyInfoWindow.Content = result.Feature.Attributes; return; } }
<DataTemplate x:Key="MyInfoWindowTemplate"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock Text="{Binding [LayerName]}" FontWeight="Bold" /> <slDataataGrid AutoGenerateColumns="False" HeadersVisibility="None" ItemsSource="{Binding}" Grid.Row="1" /> ... </Grid> </DataTemplate>
Jennifer,
I have a project where we are using the esriToolkit:InfoWindow to display information about a vessel at a given location
I see where we are Binding the information to the window in a Binding[START_DATE] tag
My question is, how can I take the date/time received and then convert it an acceptable format for our users?
Thanks!
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.