private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { List <AddressCandidate> returnedCandidates = args.Results; AddressBorder.Visibility = System.Windows.Visibility.Collapsed; if (returnedCandidates.Count > 0) { AddressCandidate candidate = returnedCandidates[0]; Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol, Geometry = candidate.Location }; graphic.Attributes.Add("Address", candidate.Address); graphicsLayer.Graphics.Add(graphic); ResultsTextBlock.Visibility = System.Windows.Visibility.Visible; ResultsTextBlock.Text = candidate.Address; double displaySize = MyMap.MinimumResolution * 30; ESRI.ArcGIS.Client.Geometry.Envelope displayExtent = new ESRI.ArcGIS.Client.Geometry.Envelope( candidate.Location.X - (displaySize / 2), candidate.Location.Y - (displaySize / 2), candidate.Location.X + (displaySize / 2), candidate.Location.Y + (displaySize / 2)); MyMap.ZoomTo(displayExtent); } }
private void ArcGISLocator_GeocodeCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { List <LocationCandidate> results = new List <LocationCandidate>(); if (args.Results != null && args.Results.Count > 0) { foreach (AddressCandidate result in args.Results) { results.Add(new LocationCandidate(result.Score, result.Address, result.Location, locatorConfig.LocationSymbol.ImageSource)); if (locatorConfig.ArcGISLocator.ReturnFirst) { break; } } } OnResultReady(results, locatorConfig.ArcGISLocator.SRWKID, false); }
private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args) { _candidateGraphicsLayer.ClearGraphics(); CandidateListBox.Items.Clear(); List <AddressCandidate> returnedCandidates = args.Results; foreach (AddressCandidate candidate in returnedCandidates) { if (candidate.Score >= 80) { CandidateListBox.Items.Add(candidate.Address); Graphic graphic = new Graphic() { Symbol = LayoutRoot.Resources["DefaultMarkerSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol, Geometry = candidate.Location }; graphic.Attributes.Add("Address", candidate.Address); string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y); graphic.Attributes.Add("LatLon", latlon); if (candidate.Location.SpatialReference == null) { candidate.Location.SpatialReference = new SpatialReference(4326); } if (!candidate.Location.SpatialReference.Equals(MyMap.SpatialReference)) { if (MyMap.SpatialReference.Equals(new SpatialReference(102100)) && candidate.Location.SpatialReference.Equals(new SpatialReference(4326))) { graphic.Geometry = _mercator.FromGeographic(graphic.Geometry); } else if (MyMap.SpatialReference.Equals(new SpatialReference(4326)) && candidate.Location.SpatialReference.Equals(new SpatialReference(102100))) { graphic.Geometry = _mercator.ToGeographic(graphic.Geometry); } else if (MyMap.SpatialReference != new SpatialReference(4326)) { GeometryService geometryService = new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.ProjectCompleted += (s, a) => { graphic.Geometry = a.Results[0].Geometry; }; geometryService.Failed += (s, a) => { MessageBox.Show("Projection error: " + a.Error.Message); }; geometryService.ProjectAsync(new List <Graphic> { graphic }, MyMap.SpatialReference); } } _candidateGraphicsLayer.Graphics.Add(graphic); } } if (_candidateGraphicsLayer.Graphics.Count > 0) { CandidatePanelGrid.Visibility = Visibility.Visible; CandidateListBox.SelectedIndex = 0; } }