Map map = MapApplication.Current.Map; MapPoint mapPoint = (MapPoint)matchGraphic.Geometry; Point screenPoint = map.MapToScreen(mapPoint, true); GeneralTransform t; if (Application.Current != null) { if (map.FlowDirection == FlowDirection.RightToLeft) t = map.TransformToVisual(null); else t = map.TransformToVisual(Application.Current.RootVisual); } else t = map.TransformToVisual(null); screenPoint = t.Transform(screenPoint); string layerId = "a0105e7ed35a4618ab0d052611dc0298"; GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers[layerId] as GraphicsLayer; IEnumerable<Graphic> graphics = graphicsLayer.FindGraphicsInHostCoordinates(screenPoint); Graphic graphic = graphics.FirstOrDefault(); MapApplication.Current.ShowPopup(graphic, graphicsLayer);
Hi Tanya,Are you saying that the default on-click pop-up (Identify functionality) that come with the Viewer is not giving you the information that you need? Or do you want it to automatically show as soon as they click Find on the Address Locator and zoom to the location? One problem I could foresee with that is that often times a list of "candidates" are returned from the Locator Task, in which case it would be tough to decide which spot on the map should automatically show the pop-up. Katy
private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { // Check whether results were found. if (args.Results.Count > 0) { // Get the best match. AddressCandidate bestCandidate = args.Results[0]; foreach (AddressCandidate candidate in args.Results) bestCandidate = (candidate.Score > bestCandidate.Score) ? candidate : bestCandidate; // Create a graphic for the match. Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["AddressToLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = bestCandidate.Location }; //Zoom to Graphic - Location to Address Envelope env = new Envelope(bestCandidate.Location.X - 4000, bestCandidate.Location.Y - 4000, bestCandidate.Location.X + 4000, bestCandidate.Location.Y + 4000); MyMap.ZoomTo(env); //Identify Parameters for Address to Location Point ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters() { //This is where the xy coords are passed into the parameters Geometry = bestCandidate.Location, MapExtent = MyMap.Extent, Width = (int)MyMap.ActualWidth, Height = (int)MyMap.ActualHeight, LayerOption = LayerOption.all, SpatialReference = MyMap.SpatialReference }; identifyParams.LayerIds.AddRange(new int[] { 2, 3, 4 }); IdentifyTask identifyTask = new IdentifyTask("website"); identifyTask.ExecuteCompleted += IdentifyTask_ExecuteCompleted; identifyTask.Failed += IdentifyTask_Failed; identifyTask.ExecuteAsync(identifyParams); // Add the address and coordinates to the graphic. graphic.Attributes.Add("Address", bestCandidate.Address); string latLon = String.Format("{0}, {1}", bestCandidate.Location.X, bestCandidate.Location.Y); graphic.Attributes.Add("LatLon", latLon); // Show the graphic by adding it to a graphics layer. GraphicsLayer graphicsLayer = MyMap.Layers["AddressToLocationGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); graphicsLayer.Graphics.Add(graphic); } else { // Notify user. MessageBox.Show("No results found"); } }
<UserControl x:Class="AddressLocationTool.AddIns.MyConfigDialog" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:slData="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" xmlns:extensibility="clr-namespace:ESRI.ArcGIS.Client.Extensibility;assembly=ESRI.ArcGIS.Client.Extensibility"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <esri:PictureMarkerSymbol x:Key="AddressToLocationSymbol" OffsetX="0" OffsetY="31" Source="C:\TOwens\Viewer_Apps\AddressLocationTool\AddressLocationTool\AddressLocationTool\Images\MarkerSymbols\Basic\BlueStickpin.png" /> </Grid.Resources> <!-- LOCATOR TASK INTERFACE --> <StackPanel Margin="10" HorizontalAlignment="Left"> <Grid> <Rectangle Fill="#CC5C90B2" Stroke="Gray" RadiusX="10" RadiusY="10" /> <StackPanel Margin="10" HorizontalAlignment="Center" > <TextBlock Text="Click Find to locate an address" HorizontalAlignment="Center" Margin="0,0,0,5" Foreground="White" FontStyle="Italic" /> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" > <TextBlock Text="Address: " Foreground="White" /> <TextBox x:Name="Address" Text="177 N Church Ave" Width="125" /> </StackPanel> <Button x:Name="FindAddressButton" Content="Find" Width="100" HorizontalAlignment="Center" Click="FindAddressButton_Click" Margin="0,5,0,0" /> <Line HorizontalAlignment="Center" X1="0" Y1="10" X2="180" Y2="10" StrokeThickness="1" Stroke="White" /> </StackPanel> </Grid> </StackPanel> </Grid> </UserControl>
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Interactivity; using System.ComponentModel.Composition; using System.ComponentModel; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Extensibility; using ESRI.ArcGIS.Client.Tasks; using ESRI.ArcGIS.Client.Symbols; using ESRI.ArcGIS.Client.Geometry; using System.Collections.Generic; namespace AddressLocationTool.AddIns { public partial class AddressLocationTool : UserControl { public AddressLocationTool() { InitializeComponent(); } // Find the location of an address when the Find button is clicked. private void FindAddressButton_Click(object sender, RoutedEventArgs e) { // Initialize the Locator. Locator locatorTask = new Locator("GeocodeServer web address" + "Locators/ESRI_Geocode_USA/GeocodeServer"); locatorTask.AddressToLocationsCompleted += LocatorTask_AddressToLocationsCompleted; locatorTask.Failed += LocatorTask_Failed; // Initialize the address. AddressToLocationsParameters addressParameters = new AddressToLocationsParameters(); Dictionary<string, string> address = addressParameters.Address; address.Add("Address", Address.Text); // Call method to locate the address. locatorTask.AddressToLocationsAsync(addressParameters); } // When the address has been located, show the best match on the map. private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { // Check whether results were found. if (args.Results.Count > 0) { // Get the best match. AddressCandidate bestCandidate = args.Results[0]; foreach (AddressCandidate candidate in args.Results) bestCandidate = (candidate.Score > bestCandidate.Score) ? candidate : bestCandidate; // Create a graphic for the match. Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["AddressToLocationSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = bestCandidate.Location }; // Add the address and coordinates to the graphic. graphic.Attributes.Add("Address", bestCandidate.Address); string latLon = String.Format("{0}, {1}", bestCandidate.Location.X, bestCandidate.Location.Y); graphic.Attributes.Add("LatLon", latLon); // Show the graphic by adding it to a graphics layer. GraphicsLayer graphicsLayer = MapApplication.Current.Map.Layers["AddressToLocationGraphicsLayer"] as GraphicsLayer; graphicsLayer.ClearGraphics(); graphicsLayer.Graphics.Add(graphic); } else { // Notify user. MessageBox.Show("No results found"); } } // Notify the user if the task fails to execute. private void LocatorTask_Failed(object sender, TaskFailedEventArgs e) { MessageBox.Show("Locator service failed: " + e.Error); } } }
using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using System.Windows.Interactivity; using System.ComponentModel.Composition; using System.ComponentModel; using ESRI.ArcGIS.Client; using ESRI.ArcGIS.Client.Extensibility; namespace AddressLocationTool.AddIns { [Export(typeof(ICommand))] [DisplayName("Address Location")] public class AddressTool : ICommand { private AddressLocationTool addressUI; public AddressTool() { addressUI = new AddressLocationTool(); } public void Execute(object parameter) { MapApplication.Current.ShowWindow("Address Location", addressUI); } public bool CanExecute(object parameter) { // Return true so that the command can always be executed return true; } public event EventHandler CanExecuteChanged; } }
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.