/// <summary> /// Select candidate. /// </summary> /// <param name="item">Candidate.</param> public void SelectCandidate(AddressCandidate item) { if (item == null) { if (DataGridControl.SelectedItems.Count > 0) { DataGridControl.SelectedItems.Clear(); } Debug.Assert(DataGridControl.SelectedItems.Count == 0); } else { if (DataGridControl.SelectedItems.Count == 0) { DataGridControl.SelectedItems.Add(item); } else { Debug.Assert(DataGridControl.SelectedItems.Count == 1); DataGridControl.SelectedItems.Clear(); DataGridControl.SelectedItems.Add(item); } DataGridControl.BringItemIntoView(item); } _SetButtonApplyIsEnabled(); }
/// <summary> /// Get best candidates from locators. /// </summary> /// <param name="locators">Locators.</param> /// <param name="candidates">Candidates.</param> /// <returns>Best candidates from locators.</returns> private static AddressCandidate _GetBestCandidateFromLocators( IEnumerable <LocatorInfo> locators, IEnumerable <AddressCandidate> candidates) { Debug.Assert(locators != null); Debug.Assert(candidates != null); AddressCandidate bestCandidate = null; foreach (AddressCandidate candidate in candidates) { // Check candidate from locators. bool isCandidateFromLocators = _IsMatchMethodBelongsToLocators(locators, candidate.Address.MatchMethod); // If candidate from locators - find best. if (isCandidateFromLocators) { if (bestCandidate != null) { if (bestCandidate.Score < candidate.Score) { bestCandidate = candidate; } } else { bestCandidate = candidate; } } } return(bestCandidate); }
/// <summary> /// Convert cell context to cell content. /// </summary> /// <param name="value">Cell context.</param> /// <param name="targetType">Ignored.</param> /// <param name="parameter">Ignored.</param> /// <param name="culture">Ignored.</param> /// <returns>Cell content.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string result = string.Empty; AddressCandidate addressCandidate = value as AddressCandidate; if (addressCandidate != null) { // Show address line. int index = addressCandidate.Address.FullAddress.IndexOf(','); // Address line is before first separator. if (index != -1) { result = addressCandidate.Address.FullAddress.Substring(0, index); } else { // If separator is absent - show full address. result = addressCandidate.Address.FullAddress; } } return(result); }
/// <summary> /// Set geocoded fields to address. /// </summary> /// <param name="geocodable">Geocodable object to set address and position.</param> /// <param name="candidate">Source candidate.</param> public static void SetCandidate(IGeocodable geocodable, AddressCandidate candidate) { Debug.Assert(geocodable != null); Debug.Assert(candidate != null); // Set geolocation. geocodable.GeoLocation = new ESRI.ArcLogistics.Geometry.Point( candidate.GeoLocation.X, candidate.GeoLocation.Y); geocodable.Address.MatchMethod = candidate.Address.MatchMethod ?? string.Empty; if (App.Current.Geocoder.AddressFormat == AddressFormat.MultipleFields) { // Concatenate Full Address from other address fields. SetFullAddress(geocodable.Address); } else if (App.Current.Geocoder.AddressFormat == AddressFormat.SingleField) { // Do nothing: don't touch user entered\imported Full Address // and can't parse Full Address to address parts. } else { // Do nothing. Debug.Assert(false); } }
private List <AddressCandidate> GetAddressCandidatesFromGraphics(IList <Graphic> graphics, bool addAttributes) { List <AddressCandidate> candidates = new List <AddressCandidate>(); foreach (Graphic graphic in graphics) { object o; string addr = null; if (graphic.Attributes.TryGetValue("^^^address^^^", out o)) { addr = o as string; } int score = default(int); if (graphic.Attributes.TryGetValue("^^^score^^^", out o)) { if (o is int) { score = (int)o; } } Dictionary <string, object> dict = null; if (graphic.Attributes != null) { dict = new Dictionary <string, object>(); foreach (KeyValuePair <string, object> keyValuePair in graphic.Attributes) { dict.Add(keyValuePair.Key, keyValuePair.Value); } } AddressCandidate candidate = new AddressCandidate(addr, graphic.Geometry as MapPoint, score, addAttributes ? dict : null); candidates.Add(candidate); } return(candidates); }
void locator_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs e) { GraphicsLayer graphicsLayer = (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer); if (e.Results.Count > 0) { AddressCandidate address = e.Results[0]; Graphic graphicLocation = new Graphic() { Geometry = address.Location }; graphicLocation.Attributes.Add("address", address.Address); graphicLocation.Attributes.Add("score", address.Score); _stops.Add(graphicLocation); if ((string)e.UserState == "from") { graphicLocation.Symbol = LayoutRoot.Resources["FromSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; //Geocode to address _locator.AddressToLocationsAsync(ParseAddress(ToTextBox.Text), "to"); } else { graphicLocation.Symbol = LayoutRoot.Resources["ToSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; //Get route between from and to _routeParams.OutSpatialReference = MyMap.SpatialReference; _routeTask.SolveAsync(_routeParams); } graphicsLayer.Graphics.Add(graphicLocation); } }
/// <summary> /// Updates geocodable information. /// </summary> /// <param name="needMessage">Need show message.</param> /// <param name="candidate">Geocoded candidate (can be NULL).</param> /// <param name="obj">Source object to geocoded candidate.</param> private void _UpdateGeocodableInfo(bool needMessage, AddressCandidate candidate, AppData.DataObject obj) { Debug.Assert(null != obj); // Created. IGeocodable geocodable = _GetGeocodable(obj); geocodable.GeoLocation = null; if ((null == candidate) || (candidate.Score <= App.Current.Geocoder.MinimumMatchScore)) { // Not geocoded. geocodable.Address.MatchMethod = string.Empty; } else { GeocodeHelpers.SetCandidate(geocodable, candidate); ++_geocodedCount; // Store warning. if (needMessage) { string objectName = _informer.ObjectName; string errorTextFormat = App.Current.GetString("ImportProcessStatusRecordOutMapExtendGeocodedFormat", objectName.ToLower(), "{0}", objectName); var description = new MessageDetail(MessageType.Warning, errorTextFormat, obj); _details.Add(description); } } }
/// <summary> /// Try to find candidates in local storage and put in appropriate position in candidates array. /// Leave null if candidate not found. Return addresses, which not exists in local storage. /// </summary> /// <param name="nameAddresses">Name\Address pairs to geocode.</param> /// <param name="candidates">Candidates list.</param> /// <returns>Addresses, which not exists in local storage.</returns> private List <Address> _ProcessLocalBatchGeocoding(NameAddress[] nameAddresses, AddressCandidate[] candidates) { Debug.Assert(nameAddresses != null); Debug.Assert(candidates != null); List <Address> addressesToGeocode = new List <Address>(); for (int index = 0; index < nameAddresses.Length; index++) { AddressCandidate candidate = Geocode(nameAddresses[index]); // If candidate exists in local storage - put it to candidates list. // Otherwise add address to geocode on server. if (candidate != null) { candidates[index] = candidate; } else { addressesToGeocode.Add(nameAddresses[index].Address); } } return(addressesToGeocode); }
/// <summary> /// Geocode order, using local geocoder. /// </summary> /// <param name="order">Order to geocode.</param> /// <param name="useLocalAsPrimary">If true and record exists in storage, than dont use server geocoder.</param> /// <param name="includeDisabledLocators">Is need to add candidates from disabled locators.</param> /// <returns>Candidates list.</returns> private static List <AddressCandidate> _DoLocalOrderGeocode(Order order, bool useLocalAsPrimary, bool includeDisabledLocators) { LocalGeocoder localGeocoder = new LocalGeocoder(App.Current.Geocoder, App.Current.NameAddressStorage); NameAddress nameAddress = new NameAddress(); nameAddress.Name = order.Name; nameAddress.Address = (Address)order.Address.Clone(); List <AddressCandidate> candidates = new List <AddressCandidate>(); AddressCandidate candidateFromLocalGeocoder = localGeocoder.Geocode(nameAddress); if (useLocalAsPrimary && candidateFromLocalGeocoder != null) { candidates.Add(candidateFromLocalGeocoder); } else { AddressCandidate[] candidatesArray = localGeocoder.GeocodeCandidates(nameAddress, includeDisabledLocators); candidates.AddRange(candidatesArray); } return(candidates); }
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); } }
/// <summary> /// Hide text block if street candidate. Show and fill otherwise. /// </summary> /// <param name="zoomedCandidate">Candidate to zoom.</param> private void _InitZoomedAddressTypeText(AddressCandidate zoomedCandidate) { LocatorType?locatorType = GeocodeHelpers.GetLocatorTypeOfCandidate(zoomedCandidate); // Set text for citystate and zip candidates. Hide otherwise. switch (locatorType) { case LocatorType.CityState: { ZoomedAddressType.Text = (string)App.Current.FindResource(CITYSTATE_LOCATOR_TITLE_RESOURCE_NAME); ZoomedAddressType.Visibility = Visibility.Visible; break; } case LocatorType.Zip: { ZoomedAddressType.Text = (string)App.Current.FindResource(ZIP_LOCATOR_TITLE_RESOURCE_NAME); ZoomedAddressType.Visibility = Visibility.Visible; break; } case LocatorType.Street: { ZoomedAddressType.Visibility = Visibility.Collapsed; break; } default: { Debug.Assert(false); break; } } }
/// <summary> /// Parses batch geocoding result. Set geocode candidates values to relative object. /// </summary> /// <param name="candidates">Candidates from geocoding.</param> /// <param name="objects">Objects to geocoding.</param> private void _ParseBatchGeocodeResult(AddressCandidate[] candidates, IList <AppData.DataObject> objects) { Debug.Assert(null != objects); // created Debug.Assert(null != candidates); // created Debug.Assert(candidates.Length == objects.Count); // valid state Debug.Assert(null != _checker); // inited // valid check extent var importExtent = App.Current.Map.ImportCheckExtent; // init progress int count = objects.Count; for (int index = 0; index < count; ++index) { _checker.ThrowIfCancellationRequested(); // get current object AppData.DataObject obj = objects[index]; IGeocodable geocodable = _GetGeocodable(obj); bool needMessage = false; if (geocodable.IsGeocoded) { // add message - Could not locate object using X/Y attributes. // Order was located using address information instead Debug.Assert(!importExtent.IsPointIn(geocodable.GeoLocation.Value)); needMessage = true; } AddressCandidate candidate = candidates[index]; _UpdateGeocodableInfo(needMessage, candidate, obj); } }
private void LocatorTask_AddressToLocationsCompleted(object sender, AddressToLocationsEventArgs args) { List <AddressCandidate> returnedCandidates = args.Results; if (returnedCandidates.Count == 1) { AddressCandidate best = returnedCandidates[0]; Envelope env = new Envelope() { XMin = double.Parse(best.Attributes["West_Lon"].ToString(), CultureInfo.InvariantCulture), YMin = double.Parse(best.Attributes["South_Lat"].ToString(), CultureInfo.InvariantCulture), XMax = double.Parse(best.Attributes["East_Lon"].ToString(), CultureInfo.InvariantCulture), YMax = double.Parse(best.Attributes["North_Lat"].ToString(), CultureInfo.InvariantCulture) }; Map.ZoomTo(env); } else if (returnedCandidates.Count > 1) { locationResults.Visibility = Visibility.Visible; locationResults.ItemsSource = returnedCandidates; Dispatcher.BeginInvoke(() => { locationResults.Focus(); }); } }
/// <summary> /// Does batch geocoding. /// </summary> /// <param name="objects">Objects to geocoding.</param> private void _BatchGeocode(IList <AppData.DataObject> objects) { Debug.Assert(null != objects); // created Debug.Assert(0 < objects.Count); // not empty Debug.Assert(null != _checker); // inited try { // create list of addresses Address[] addresses = _CreateAddressList(objects); // start geocode App currentApp = App.Current; AddressCandidate[] candidates = null; if (objects[0] is Order) { // for orders - use local geocoding NameAddress[] namedAddress = _CreateNamedAddressList(objects); var localGeocoder = new LocalGeocoder(currentApp.Geocoder, currentApp.NameAddressStorage); candidates = localGeocoder.BatchGeocode(namedAddress); } else { // for other object - use server geocoder candidates = currentApp.Geocoder.BatchGeocode(addresses); } _checker.ThrowIfCancellationRequested(); // validate geocode _ValidateLocation(addresses, candidates); // If current geocoder is arcgiscomgeocoder - check that we got // candidates from "good" locators. var arcgisgeocoder = App.Current.Geocoder as ArcGiscomGeocoder; if (arcgisgeocoder != null) { for (int i = 0; i < candidates.Count(); i++) { var goodAddressType = arcgisgeocoder.ExactLocatorsTypesNames.Contains(candidates[i].AddressType); if (!goodAddressType) { candidates[i] = new AddressCandidate(); } } } // parse result _ParseBatchGeocodeResult(candidates, objects); } catch (Exception ex) { Logger.Error(ex); // store exception _detectedException = ex; } }
private CandidateGraphicObject(AddressCandidate candidate) : base(candidate) { _candidate = candidate; _candidate.PropertyChanged += new PropertyChangedEventHandler(_candidate_PropertyChanged); Geometry = _CreatePoint(candidate); }
/// <summary> /// Get candidates from not primary sublocators. City, Zip, Street candidates. /// </summary> /// <param name="geocodable">Geocodable object to validation</param> /// <param name="candidatesIncludedDisabledLocators">Candidates from all locators.</param> /// <returns>City, Zip, Street candidates.</returns> public static IEnumerable <AddressCandidate> GetBestCandidatesFromNotPrimaryLocators(IGeocoder geocoder, IGeocodable geocodable, IEnumerable <AddressCandidate> candidatesIncludedDisabledLocators) { Debug.Assert(geocodable != null); Debug.Assert(candidatesIncludedDisabledLocators != null); List <AddressCandidate> candidatesFromNotPrimaryLocators = new List <AddressCandidate>(); // If current geocoder is ArcGiscomGeocoder. var arcgisgeocoder = geocoder as ArcGiscomGeocoder; if (arcgisgeocoder != null) { // If we have candidates - return first of them as a result. if (candidatesIncludedDisabledLocators.Any()) { candidatesFromNotPrimaryLocators.Add(candidatesIncludedDisabledLocators.First()); } return(candidatesFromNotPrimaryLocators); } if (App.Current.Geocoder.IsCompositeLocator) { List <LocatorInfo> sublocators = new List <LocatorInfo>(); sublocators.AddRange(App.Current.Geocoder.Locators); // Get best street candidate. List <LocatorInfo> streetLocators = _ExtractLocators(AddressPart.AddressLine, sublocators); List <AddressCandidate> streetCandidates = _GetStreetCandidates(geocodable, streetLocators, candidatesIncludedDisabledLocators); if (streetCandidates != null) { candidatesFromNotPrimaryLocators.AddRange(streetCandidates); } if (candidatesFromNotPrimaryLocators.Count == 0) { // Get best zip candidate. List <LocatorInfo> zipLocators = _ExtractLocators(AddressPart.PostalCode1, sublocators); AddressCandidate bestCandidate = _GetBestCandidateFromLocators(zipLocators, candidatesIncludedDisabledLocators); if (bestCandidate == null) { // Get best cityState candidate. List <LocatorInfo> cityStateLocators = _ExtractLocators(AddressPart.StateProvince, sublocators); bestCandidate = _GetBestCandidateFromLocators(cityStateLocators, candidatesIncludedDisabledLocators); } if (bestCandidate != null) { candidatesFromNotPrimaryLocators.Add(bestCandidate); } } } return(candidatesFromNotPrimaryLocators); }
/// <summary> /// Check is location of geocodable object valid and replace it by candidate from local /// geocoder if exists. /// </summary> /// <param name="geocodable">Geocodable object to check.</param> /// <returns>Is geocodable object valid.</returns> private bool _SourceGeocodedObject(IGeocodable geocodable) { Debug.Assert(null != geocodable); // created bool isObjectGeocoded = false; // First check if name address pair exists in local geocoder database. // If exists - overwrite geolocation and address from it. App currentApp = App.Current; var localGeocoder = new LocalGeocoder(currentApp.Geocoder, currentApp.NameAddressStorage); var nameAddress = new NameAddress(); nameAddress.Name = geocodable.ToString(); nameAddress.Address = geocodable.Address.Clone() as Address; AddressCandidate localCandidate = localGeocoder.Geocode(nameAddress); if (localCandidate == null) { // Update from internal object information. AppGeometry.Envelope extent = currentApp.Map.ImportCheckExtent; if (extent.IsPointIn(geocodable.GeoLocation.Value)) { geocodable.Address.MatchMethod = currentApp.FindString("ImportSourceMatchMethod"); isObjectGeocoded = true; // Full address property must be combined from other fields, because // it is not importing field. if (App.Current.Geocoder.AddressFormat == AddressFormat.MultipleFields) { GeocodeHelpers.SetFullAddress(geocodable.Address); } else { // Do nothing: do not update full address since // it is used for geocoding in Single Address Field Format. } } // Else could not locate object using X/Y attributes - need geocode. } else { // Init from local candidate. // Set location. geocodable.GeoLocation = new AppGeometry.Point(localCandidate.GeoLocation.X, localCandidate.GeoLocation.Y); // Set address. localCandidate.Address.CopyTo(geocodable.Address); isObjectGeocoded = true; } return(isObjectGeocoded); }
/// <summary> /// Create graphic object for candidate /// </summary> /// <param name="candidate">Source candidate</param> /// <returns>Graphic object for candidate</returns> public static CandidateGraphicObject Create(AddressCandidate candidate) { CandidateGraphicObject graphic = new CandidateGraphicObject(candidate) { Symbol = new CandidateSymbol() }; graphic.SetZIndex(ObjectLayer.BACKZINDEX); return(graphic); }
/// <summary> /// Convert local storage record to address candidate. /// </summary> /// <param name="nameAddressRecord">Local storage record.</param> /// <returns>Address candidate.</returns> private AddressCandidate _ConvertToCandidate(NameAddressRecord nameAddressRecord) { Debug.Assert(nameAddressRecord != null); AddressCandidate candidateFromLocalStorage = new AddressCandidate(); // Candidate from local storage have maximum score. candidateFromLocalStorage.Score = MAXIMUM_SCORE; // Set candidate geolocation. candidateFromLocalStorage.GeoLocation = new ESRI.ArcLogistics.Geometry.Point( nameAddressRecord.GeoLocation.X, nameAddressRecord.GeoLocation.Y); // Set candidate address. Address candidateAddress = new Address(); candidateFromLocalStorage.Address = candidateAddress; Address matchedAddress = nameAddressRecord.MatchedAddress; Address address = nameAddressRecord.NameAddress.Address; Address addressToCopy; if (CommonHelpers.IsAllAddressFieldsEmpty(matchedAddress) && string.IsNullOrEmpty(matchedAddress.MatchMethod)) { addressToCopy = address; } else { addressToCopy = matchedAddress; } addressToCopy.CopyTo(candidateAddress); GeocodeHelpers.SetFullAddress(candidateAddress); // Set locator. foreach (LocatorInfo locator in App.Current.Geocoder.Locators) { if (locator.Title.Equals(candidateFromLocalStorage.Address.MatchMethod, System.StringComparison.OrdinalIgnoreCase) || locator.Name.Equals(candidateFromLocalStorage.Address.MatchMethod, System.StringComparison.OrdinalIgnoreCase)) { candidateFromLocalStorage.Locator = locator; break; } } candidateFromLocalStorage.AddressType = ArcGiscomGeocoder.LocalStorageAddressType; return(candidateFromLocalStorage); }
/// <summary> /// Get current candidate. Null if selection is empty. /// </summary> /// <returns>Current candidate.</returns> public AddressCandidate GetCandidate() { AddressCandidate candidate = null; // Selection can be empty. if (DataGridControl.SelectedItems.Count > 0) { candidate = (AddressCandidate)DataGridControl.SelectedItems[0]; } return(candidate); }
/// <summary> /// Zoom to candidate depends on locator type. /// </summary> /// <param name="mapCtrl">Map control.</param> /// <param name="addressCandidate">Candidate to zoom.</param> /// <param name="locatorType">Type of locator, which return this candidate.</param> private static void _ZoomToCandidate(MapControl mapCtrl, AddressCandidate addressCandidate, LocatorType locatorType) { Debug.Assert(mapCtrl != null); Debug.Assert(addressCandidate != null); double extentInc = 0; // Get extent size. switch (locatorType) { case LocatorType.CityState: { extentInc = ZOOM_ON_CITY_STATE_CANDIDATE; break; } case LocatorType.Zip: { extentInc = ZOOM_ON_ZIP_CANDIDATE; break; } case LocatorType.Street: { extentInc = ZOOM_ON_STREET_CANDIDATE; break; } default: { Debug.Assert(false); break; } } // Make extent rectangle. ESRI.ArcLogistics.Geometry.Envelope rect = new ESRI.ArcLogistics.Geometry.Envelope(); rect.SetEmpty(); rect.Union(addressCandidate.GeoLocation); rect.left -= extentInc; rect.right += extentInc; rect.top += extentInc; rect.bottom -= extentInc; ESRI.ArcGIS.Client.Geometry.Envelope extent = GeometryHelper.CreateExtent(rect, mapCtrl.Map.SpatialReferenceID); mapCtrl.ZoomTo(extent); }
/// <summary> /// Get address candidates from local storage and from server. /// </summary> /// <param name="nameAddress">Name\Address pair to geocode.</param> /// <param name="includeDisabledLocators">Is need to add candidates from disabled locators.</param> /// <returns>Candidates list.</returns> public AddressCandidate[] GeocodeCandidates(NameAddress nameAddress, bool includeDisabledLocators) { Debug.Assert(nameAddress != null); List <AddressCandidate> candidates = _GeocodeCandidates(nameAddress.Address, includeDisabledLocators); AddressCandidate candidateFromLocalStorage = Geocode(nameAddress); if (candidateFromLocalStorage != null) { // If candidate from local storage exists - insert it to first position. candidates.Insert(0, candidateFromLocalStorage); } return(candidates.ToArray()); }
/// <summary> /// Create map point for candidate /// </summary> /// <param name="candidate">Candidate to get geometry</param> /// <returns>Map point of candidate position</returns> private ESRI.ArcGIS.Client.Geometry.MapPoint _CreatePoint(AddressCandidate candidate) { ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = null; ESRI.ArcLogistics.Geometry.Point geoLocation = candidate.GeoLocation; // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator if (ParentLayer != null && ParentLayer.SpatialReferenceID != null) { geoLocation = WebMercatorUtil.ProjectPointToWebMercator(geoLocation, ParentLayer.SpatialReferenceID.Value); } mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(geoLocation.X, geoLocation.Y); return(mapPoint); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string result = string.Empty; if (value != null) { try { AddressCandidate currentAddress = value as AddressCandidate; result = currentAddress.Address.MatchMethod; } catch { } } return(result); }
/// <summary> /// Get address candidate from local storage. /// </summary> /// <param name="nameAddress">Name\Address pair to geocode.</param> /// <returns>Address candidate if exists in local storage. Null otherwise.</returns> public AddressCandidate Geocode(NameAddress nameAddress) { Debug.Assert(nameAddress != null); Debug.Assert(_nameAddressStorage != null); // Search record in storage. NameAddressRecord nameAddressRecord = _nameAddressStorage.Search( nameAddress, App.Current.Geocoder.AddressFormat); AddressCandidate candidateFromLocalStorage = null; // Extract candidate from record, if record exists. if (nameAddressRecord != null) { candidateFromLocalStorage = _ConvertToCandidate(nameAddressRecord); } return(candidateFromLocalStorage); }
private void locationResults_SelectionChanged(object sender, SelectionChangedEventArgs e) { AddressCandidate best = locationResults.SelectedItem as AddressCandidate; if (best == null) { return; } Envelope env = new Envelope() { XMin = double.Parse(best.Attributes["West_Lon"].ToString(), CultureInfo.InvariantCulture), YMin = double.Parse(best.Attributes["South_Lat"].ToString(), CultureInfo.InvariantCulture), XMax = double.Parse(best.Attributes["East_Lon"].ToString(), CultureInfo.InvariantCulture), YMax = double.Parse(best.Attributes["North_Lat"].ToString(), CultureInfo.InvariantCulture) }; Map.ZoomTo(env); locationResults.Visibility = Visibility.Collapsed; locationResults.ItemsSource = null; }
/// <summary> /// Make string parts like 'We couldn’t find… so we’ve zoomed to…' /// If street candidate - use Address Line from geocodable item, otherwise(citystate or zip) use full address. /// </summary> /// <param name="item">Geocodable item.</param> /// <param name="candidateToZoom">First candidate to zoom.</param> /// <returns>Geocode result string parts.</returns> public static string GetZoomedAddress(IGeocodable item, AddressCandidate candidateToZoom) { LocatorType?locatorType = GeocodeHelpers.GetLocatorTypeOfCandidate(candidateToZoom); string zoomedAddress; // If locator type of candidate is street than get Address Line. if (locatorType.HasValue && locatorType.Value == LocatorType.Street && !string.IsNullOrEmpty(item.Address.AddressLine)) { // Extract street name. zoomedAddress = GeocodeHelpers.ExtractStreet(item.Address.AddressLine); } else { // Otherwise use full address. zoomedAddress = candidateToZoom.Address.FullAddress; } return(zoomedAddress); }
/// <summary> /// Get locator type of candidate. /// </summary> /// <param name="candidate">Address candidate.</param> /// <returns>Locator type of candidate. Null in case of not composite locator.</returns> public static LocatorType?GetLocatorTypeOfCandidate(AddressCandidate candidate) { Debug.Assert(candidate != null); LocatorType?result = null; if (App.Current.Geocoder.IsCompositeLocator) { List <LocatorInfo> sublocators = new List <LocatorInfo>(); sublocators.AddRange(App.Current.Geocoder.Locators); // Check candidate is from street locator. List <LocatorInfo> streetLocators = _ExtractLocators(AddressPart.AddressLine, sublocators); if (_IsMatchMethodBelongsToLocators(streetLocators, candidate.Address.MatchMethod)) { result = LocatorType.Street; } else { // Check candidate is from cityState locator. List <LocatorInfo> cityStateLocators = _ExtractLocators(AddressPart.StateProvince, sublocators); if (_IsMatchMethodBelongsToLocators(cityStateLocators, candidate.Address.MatchMethod)) { result = LocatorType.CityState; } else { // Check candidate is from zip locator. List <LocatorInfo> zipLocators = _ExtractLocators(AddressPart.PostalCode1, sublocators); if (_IsMatchMethodBelongsToLocators(zipLocators, candidate.Address.MatchMethod)) { result = LocatorType.Zip; } } } } return(result); }
/// <summary> /// Geocode batch of of items. /// </summary> /// <param name="nameAddresses">Name\Address pairs to geocode.</param> /// <returns></returns> public AddressCandidate[] BatchGeocode(NameAddress[] nameAddresses) { Debug.Assert(nameAddresses != null); Debug.Assert(_geocoder != null); // Create candidates array. AddressCandidate[] candidates = new AddressCandidate[nameAddresses.Length]; // Try to find candidates in local storage and put in appropriate position in candidates array. // Leave null if candidate not found. Return not addresses, which not exists in local storage. List <Address> addressesToGeocode = _ProcessLocalBatchGeocoding(nameAddresses, candidates); if (addressesToGeocode.Count > 0) { // Make batch geocode at server. AddressCandidate[] candidatesFromServer = _geocoder.BatchGeocode(addressesToGeocode.ToArray()); // Fill results of batch geocoding in candidates array. _ProcessServerBatchGeocoding(candidatesFromServer, candidates); } return(candidates); }
/// <summary> /// Convert cell context to cell content. /// </summary> /// <param name="value">Cell context.</param> /// <param name="targetType">Ignored.</param> /// <param name="parameter">Ignored.</param> /// <param name="culture">Ignored.</param> /// <returns>Cell content.</returns> public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { string result = string.Empty; AddressCandidate addressCandidate = value as AddressCandidate; if (addressCandidate != null) { // Show all address, except address line. string fullAddress = addressCandidate.Address.FullAddress; // Address line is before first separator. int index = fullAddress.IndexOf(','); if (index != -1) { result = fullAddress.Substring(index + 1, fullAddress.Length - index - 1); result = result.Trim(); } } return(result); }
private bool getExtentFields(AddressCandidate candidate, out double xMin, out double yMin, out double xMax, out double yMax) { xMin = yMin = xMax = yMax = 0; if (candidate.Attributes.ContainsKey(ExtentFields.XMinField.Name) && double.TryParse(candidate.Attributes[ExtentFields.XMinField.Name].ToString(), out xMin)) { if (candidate.Attributes.ContainsKey(ExtentFields.YMinField.Name) && double.TryParse(candidate.Attributes[ExtentFields.YMinField.Name].ToString(), out yMin)) { if (candidate.Attributes.ContainsKey(ExtentFields.XMaxField.Name) && double.TryParse(candidate.Attributes[ExtentFields.XMaxField.Name].ToString(), out xMax)) { if (candidate.Attributes.ContainsKey(ExtentFields.YMaxField.Name) && double.TryParse(candidate.Attributes[ExtentFields.YMaxField.Name].ToString(), out yMax)) { return true; } } } } return false; }
private List<AddressCandidate> GetAddressCandidatesFromGraphics(IList<Graphic> graphics, bool addAttributes) { List<AddressCandidate> candidates = new List<AddressCandidate>(); foreach (Graphic graphic in graphics) { object o; string addr = null; if (graphic.Attributes.TryGetValue("^^^address^^^", out o)) addr = o as string; int score = default(int); if (graphic.Attributes.TryGetValue("^^^score^^^", out o)) { if (o is int) score = (int)o; } Dictionary<string, object> dict = null; if (graphic.Attributes != null) { dict = new Dictionary<string, object>(); foreach (KeyValuePair<string, object> keyValuePair in graphic.Attributes) dict.Add(keyValuePair.Key, keyValuePair.Value); } AddressCandidate candidate = new AddressCandidate(addr, graphic.Geometry as MapPoint, score, addAttributes ? dict : null); candidates.Add(candidate); } return candidates; }
public LocatorResultViewModel(AddressCandidate candidate) { Candidate = candidate; }