Ejemplo n.º 1
0
        /// <summary>
        /// Zoom to candidate depends on locator type.
        /// </summary>
        /// <param name="mapCtrl">Map control.</param>
        /// <param name="addressCandidate">Candidate to zoom.</param>
        public static void ZoomToCandidates(MapControl mapCtrl, AddressCandidate[] addressCandidates)
        {
            Debug.Assert(mapCtrl != null);
            Debug.Assert(addressCandidates != null);

            LocatorType?locatorType = null;

            if (addressCandidates.Length == 1)
            {
                locatorType = GeocodeHelpers.GetLocatorTypeOfCandidate(addressCandidates[0]);
            }

            if (locatorType == null)
            {
                // If not composite locator - zoom to candidate.
                List <ESRI.ArcLogistics.Geometry.Point> points = new List <ESRI.ArcLogistics.Geometry.Point>();
                foreach (AddressCandidate addressCandidate in addressCandidates)
                {
                    points.Add(addressCandidate.GeoLocation);
                }
                SetExtentOnCollection(mapCtrl, points);
            }
            else
            {
                _ZoomToCandidate(mapCtrl, addressCandidates[0], locatorType.Value);
            }
        }
        /// <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;
            }
            }
        }
Ejemplo n.º 3
0
        /// <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);
                }
            }
        }
Ejemplo n.º 4
0
        /// <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>
        /// React on beginning edit.
        /// </summary>
        /// <param name="sender">Ignored.</param>
        /// <param name="e">Event args.</param>
        private void _BeginningEdit(object sender, DataGridItemCancelEventArgs e)
        {
            _ShowLocateButton();

            if (GeocodeHelpers.IsActiveAddressFieldsEmpty(CurrentItem))
            {
                ButtonsPanel.IsEnabled = false;
            }
            else
            {
                ButtonsPanel.IsEnabled = true;
            }

            _geocodablePage.OnBeginningEdit(e);
            e.Handled = true;

            CurrentItem.Address.PropertyChanged += new PropertyChangedEventHandler(_AddressPropertyChanged);
            CurrentItem.PropertyChanged         += new PropertyChangedEventHandler(_CurrentItemPropertyChanged);
        }
        /// <summary>
        /// Do convertion. Set background to textbox if empty value.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType">Ignored.</param>
        /// <param name="parameter">Ignored.</param>
        /// <param name="culture">Ignored.</param>
        /// <returns>Null, if background was set. Cell value otherwise.</returns>
        public object Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
        {
            TextBlock textBlock = value[1] as TextBlock;

            if (textBlock == null)
            {
                return(null);
            }

            // Get datagridcontrol cell.
            DataCell cell = XceedVisualTreeHelper.FindParent <DataCell>(textBlock);

            if (cell == null)
            {
                return(null);
            }

            // Get location.
            Location location = cell.DataContext as Location;

            // Get background brush.
            Brush backgroundBrush = _GetBackgroundBrushForCell(cell);

            // Brush need to be set only if address fields is empty.
            if (GeocodeHelpers.IsActiveAddressFieldsEmpty(location))
            {
                // Workaround for .NET 4.0: Do not not change value if not needed.
                if (textBlock.Background != backgroundBrush)
                {
                    textBlock.Background = backgroundBrush;
                }
            }
            else if (textBlock.Background != null)
            {
                textBlock.Background = null;
            }
            else
            {
                // Do nothing.
            }

            return(value[0]);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Set "Locate" and "Delete" buttons availability.
        /// </summary>
        private void _ProcessLocateState()
        {
            // If item is not selected or it has whitespaces name - hide buttons.
            if (CurrentItem == null ||
                (CurrentItem.Name != "" && String.IsNullOrWhiteSpace(CurrentItem.Name)))
            {
                // If item is not selected - hide button.
                ButtonsPanel.Visibility = Visibility.Hidden;
            }
            else
            {
                // Show panel and enable "Locate" button.
                _ShowAndEnableButtons();

                // If address fields are empty - disable "Locate" button.
                if (GeocodeHelpers.IsActiveAddressFieldsEmpty(CurrentItem))
                {
                    ButtonLocate.IsEnabled = false;
                }
            }
        }
        /// <summary>
        /// Show hint.
        /// </summary>
        /// <param name="geocodableItem">Geocodable item.</param>
        /// <param name="candidatesToZoom">Candidates to zoom.</param>
        public void ShowHint(IGeocodable geocodableItem, AddressCandidate[] candidatesToZoom)
        {
            _candidatesToZoom = candidatesToZoom;

            string titleFmt = (string)App.Current.FindResource(GEOCODE_RESULT_NOT_ZOOMED_RESOURCE_NAME);

            TitleText.Text = string.Format(titleFmt, geocodableItem.ToString());

            if (candidatesToZoom == null || candidatesToZoom.Length == 0)
            {
                // If we cant zoom to candidtes - hide corresponding rextblocks.
                ZoomedToText.Visibility      = Visibility.Collapsed;
                ZoomedAddress.Visibility     = Visibility.Collapsed;
                ZoomedAddressType.Visibility = Visibility.Collapsed;
            }
            else
            {
                string zoomedAddress = GeocodeHelpers.GetZoomedAddress(geocodableItem, candidatesToZoom[0]);

                _InitZoomedAddressTypeText(candidatesToZoom[0]);

                // Show "Zoomed to..." text.
                ZoomedAddress.Text       = zoomedAddress;
                ZoomedAddress.Visibility = Visibility.Visible;
                ZoomedToText.Visibility  = Visibility.Visible;
            }

            Visibility = Visibility.Visible;

            UpdateLayout();

            Vector toolsPanelOffset = VisualTreeHelper.GetOffset(_mapControl.toolPanel);

            // Set top of hint under title, tools.
            Canvas.SetTop(this, _mapControl.toolPanel.Margin.Top + toolsPanelOffset.Y +
                          _mapControl.toolPanel.ActualHeight);
            Canvas.SetLeft(this, _mapControl.ActualWidth - this.ActualWidth - _mapControl.toolPanel.Margin.Right);
        }
        /// <summary>
        /// Set "Locate" button availability.
        /// </summary>
        private void _ProcessLocateState()
        {
            ButtonsPanel.IsEnabled = false;

            if (CurrentItem == null)
            {
                // If item is not selected - hide button.
                ButtonsPanel.Visibility = Visibility.Hidden;
            }
            else
            {
                if (GeocodeHelpers.IsActiveAddressFieldsEmpty(CurrentItem))
                {
                    // If address fields are empty - disable button.
                    ButtonsPanel.IsEnabled = false;
                }
                else
                {
                    _ShowLocateButton();
                    ButtonsPanel.IsEnabled = true;
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Make string like 'Bevmo couldn’t be located, we’ve zoomed to Pat’s Ranch Rd.  Use the pushpin tool to locate exactly.'
        /// 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.</returns>
        private string _MakeNotFoundButZoomedString(IGeocodable item, AddressCandidate candidateToZoom)
        {
            string messageFmt = (string)App.Current.FindResource(GEOCODE_RESULT_ZOOMED_RESOURCE_NAME);

            StringBuilder stringBuilder = new StringBuilder();

            // Add "Not located, but zoomed to..." string.
            stringBuilder.AppendFormat(messageFmt, item.ToString());

            // Add zoomed address.
            string zoomedAddress = GeocodeHelpers.GetZoomedAddress(item, candidateToZoom);

            stringBuilder.Append(zoomedAddress);

            // Add dot at the end of sentence.
            stringBuilder.Append(MESSAGE_STRING_PARTS_DELIMETER);

            // Add "Use pushpin" string.
            stringBuilder.Append((string)App.Current.FindResource(USE_PUSHPIN_RESOURCE_NAME));

            string result = stringBuilder.ToString();

            return(result);
        }