<Grid.Resources> <esri:SimpleMarkerSymbol x:Key="DefaultMarkerSymbol" Color="Red" Size="6" Style="Diamond" /> </Grid.Resources> <esri:Map x:Name="map1" Background="White" WrapAround="True" Margin="0,22,0,0" Extent="-928323.6071, 502054.310, -295465.584, 1113500.0197" ZoomFactor="2" IsLogoVisible="False" > <!--Map Layers--> <esri:ArcGISTiledMapServiceLayer ID="BaseMapLayer" Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" /> <esri:GraphicsLayer ID="MyGraphicsLayer"> <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="Cacao : " FontWeight="Bold" Foreground="#FF0F274E" FontSize="10" VerticalAlignment="Center" /> <TextBlock Text="{Binding [CACAO11_12]}" HorizontalAlignment="Left" VerticalAlignment="Center" /> </StackPanel> </StackPanel> </Border> </Border> </esri:GraphicsLayer.MapTip> </esri:GraphicsLayer> </esri:Map>
void MyMap_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == "SpatialReference") { map1.PropertyChanged -= MyMap_PropertyChanged; _legendGridCollapsed = false; _classGridCollapsed = false; LegendCollapsedTriangle.MouseLeftButtonUp += Triangle_MouseLeftButtonUp; LegendExpandedTriangle.MouseLeftButtonUp += Triangle_MouseLeftButtonUp; // Set query where clause to include features with an area greater than 70 square miles. This // will effectively exclude the District of Columbia from attributes to avoid skewing classifications. ESRI.ArcGIS.Client.Tasks.Query query = new ESRI.ArcGIS.Client.Tasks.Query() { Where = "CAFE11_12 > 0 and CACAO11_12 > 0", OutSpatialReference = map1.SpatialReference, ReturnGeometry = true }; query.OutFields.Add("*"); QueryTask queryTask = new QueryTask("http://services1.arcgis.com/yt621kzsRO05k21r/arcgis/rest/services/PRODUCTION_CACAO/FeatureServer/0"); queryTask.ExecuteCompleted += (evtsender, args) => { if (args.FeatureSet == null) return; _featureSet = args.FeatureSet; SetRangeValues(); _valeurSetRangeValue = true; }; queryTask.ExecuteCompleted += queryTask_ExecuteCompleted; queryTask.ExecuteAsync(query); CreateColorList1(); CreateThematicList(); } } void queryTask_ExecuteCompleted(object sender, QueryEventArgs queryArgs) { if (queryArgs.FeatureSet == null) return; FeatureSet resultFeatureSet = queryArgs.FeatureSet; ESRI.ArcGIS.Client.GraphicsLayer graphicsLayer = map1.Layers["MyGraphicsLayer"] 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); } } }
GraphicsLayer l = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer; TextBlock tb = new TextBlock(); Binding b = new Binding("[Location]"); tb.SetBinding(TextBlock.TextProperty, b); l.MapTip = tb;
void QueryTask_ExecuteCompleted(object sender, QueryEventArgs e) { foreach (var g in e.FeatureSet.Features) g.Attributes["Location"] = g.Geometry; // if not in the OutFields. }
I am also trying to define maptips from code behind. Jennifer, looking at your response, it seems to assume that you have created the graphics layer in XAML. I need to define everything in code-behind, the graphics layer, the template to display the maptip, the service to get the data from and getting the fields/data to display.
<esri:GraphicsLayer.MapTip> <TextBlock Text="{Binding [Location], FallbackValue=BindingFailed}"/> </esri:GraphicsLayer.MapTip>
private void GraphicsLayer_Initialized(object sender, EventArgs e) { GraphicsLayer l = sender as GraphicsLayer; TextBlock tb = new TextBlock(); Binding b = new Binding("[Location]"); tb.SetBinding(TextBlock.TextProperty, b); l.MapTip = tb; foreach (var g in l.Graphics) g.Attributes["Location"] = g.Geometry; }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.