Beispiel #1
0
        private async void GeocodeButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility    = Visibility.Visible;
                listResults.Visibility = Visibility.Collapsed;
                _addressOverlay.Graphics.Clear();

                if (_locatorServiceInfo == null)
                {
                    _locatorServiceInfo = await _locatorTask.GetInfoAsync();
                }

                var candidateResults = await _locatorTask.GeocodeAsync(
                    GetInputAddressFromUI(), new List <string> {
                    "Addr_type", "Score", "X", "Y"
                }, MyMapView.SpatialReference, CancellationToken.None);

                if (candidateResults == null || candidateResults.Count == 0)
                {
                    throw new Exception("No candidates found.");
                }

                foreach (var candidate in candidateResults)
                {
                    AddGraphicFromLocatorCandidate(candidate);
                }

                var visibleGraphics = _addressOverlay.Graphics.Where(g => g.IsVisible);
                listResults.ItemsSource = visibleGraphics;
                listResults.Visibility  = Visibility.Visible;

                var extent = GeometryEngine.Union(visibleGraphics.Select(g => g.Geometry)).Extent.Expand(1.2);
                await MyMapView.SetViewAsync(extent);
            }
            catch (AggregateException ex)
            {
                var innermostExceptions = ex.Flatten().InnerExceptions;
                if (innermostExceptions != null && innermostExceptions.Count > 0)
                {
                    MessageBox.Show(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()));
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
		private async void GeocodeButton_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				progress.Visibility = Visibility.Visible;
				listResults.Visibility = Visibility.Collapsed;
				_addressOverlay.Graphics.Clear();

				if (_locatorServiceInfo == null)
					_locatorServiceInfo = await _locatorTask.GetInfoAsync();

				var candidateResults = await _locatorTask.GeocodeAsync(
					GetInputAddressFromUI(), new List<string> { "Addr_type", "Score", "X", "Y" }, MyMapView.SpatialReference, CancellationToken.None);

				if (candidateResults == null || candidateResults.Count == 0)
					throw new Exception("No candidates found.");

				foreach (var candidate in candidateResults)
					AddGraphicFromLocatorCandidate(candidate);

				listResults.ItemsSource = _addressOverlay.Graphics.Where(g => g.IsVisible);
				listResults.Visibility = Visibility.Visible;

				var extent = GeometryEngine.Union(_addressOverlay.Graphics.Select(g => g.Geometry)).Extent.Expand(1.1);
				await MyMapView.SetViewAsync(extent);
			}
			catch (AggregateException ex)
			{
				var innermostExceptions = ex.Flatten().InnerExceptions;
				if (innermostExceptions != null && innermostExceptions.Count > 0)
				{
					var _x = new MessageDialog(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()), "Sample Error").ShowAsync();
				}
				else
				{
					var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
				}
			}
			catch (System.Exception ex)
			{
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
			finally
			{
				progress.Visibility = Visibility.Collapsed;
			}
		}
Beispiel #3
0
        private async void DoGetDirections(object obj)
        {
            if (String.IsNullOrWhiteSpace(_networkingToolView.ViewModel.FromAddress) ||
                String.IsNullOrWhiteSpace(_networkingToolView.ViewModel.ToAddress))
            {
                return;
            }

            // geocode from and to address
            if (_locatorServiceInfo == null)
            {
                _locatorServiceInfo = await _locatorTask.GetInfoAsync();
            }

            Reset();

            // geocode from address
            var candidateFromResults = await _locatorTask.GeocodeAsync(
                GetInputAddressFromUI(_networkingToolView.ViewModel.FromAddress), new List <string> {
                "Addr_type", "Score", "X", "Y"
            }, _mapView.SpatialReference, CancellationToken.None);

            // geocode to address
            var candidateToResults = await _locatorTask.GeocodeAsync(
                GetInputAddressFromUI(_networkingToolView.ViewModel.ToAddress), new List <string> {
                "Addr_type", "Score", "X", "Y"
            }, _mapView.SpatialReference, CancellationToken.None);

            if (candidateFromResults.Any() && candidateToResults.Any())
            {
                var fromResult = candidateFromResults.First();
                var toResult   = candidateToResults.First();

                var fromMapPoint = fromResult.Extent.GetCenter();
                var toMapPoint   = toResult.Extent.GetCenter();

                _stopsOverlay.Graphics.Add(CreateStopGraphic(new MapPoint(fromMapPoint.X, fromMapPoint.Y, _mapView.SpatialReference), 1));
                _stopsOverlay.Graphics.Add(CreateStopGraphic(new MapPoint(toMapPoint.X, toMapPoint.Y, _mapView.SpatialReference), 2));

                await RunRouting();
            }
        }
        private async void DoGetDirections(object obj)
        {
            if (String.IsNullOrWhiteSpace(_networkingToolView.ViewModel.FromAddress) ||
                String.IsNullOrWhiteSpace(_networkingToolView.ViewModel.ToAddress))
            {
                return;
            }

            // geocode from and to address
            if (_locatorServiceInfo == null)
                _locatorServiceInfo = await _locatorTask.GetInfoAsync();

            Reset();

            // geocode from address
            var candidateFromResults = await _locatorTask.GeocodeAsync(
                GetInputAddressFromUI(_networkingToolView.ViewModel.FromAddress), new List<string> { "Addr_type", "Score", "X", "Y" }, _mapView.SpatialReference, CancellationToken.None);

            // geocode to address
            var candidateToResults = await _locatorTask.GeocodeAsync(
                GetInputAddressFromUI(_networkingToolView.ViewModel.ToAddress), new List<string> { "Addr_type", "Score", "X", "Y" }, _mapView.SpatialReference, CancellationToken.None);

            if (candidateFromResults.Any() && candidateToResults.Any())
            {
                var fromResult = candidateFromResults.First();
                var toResult = candidateToResults.First();

                var fromMapPoint = fromResult.Extent.GetCenter();
                var toMapPoint = toResult.Extent.GetCenter();

                _stopsOverlay.Graphics.Add(CreateStopGraphic(new MapPoint(fromMapPoint.X, fromMapPoint.Y, _mapView.SpatialReference), 1));
                _stopsOverlay.Graphics.Add(CreateStopGraphic(new MapPoint(toMapPoint.X, toMapPoint.Y, _mapView.SpatialReference), 2));

                await RunRouting();
            }
        }
        private async void FindButton_Click(object sender, RoutedEventArgs e)
        {
            _candidateAddressesGraphicsLayer.Graphics.Clear();

            string text = SearchTextBox.Text;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            try
            {
                LocatorServiceInfo locatorServiceInfo = await _locatorTask.GetInfoAsync();

                Dictionary <string, string> inputAddress = new Dictionary <string, string>()
                {
                    { locatorServiceInfo.SingleLineAddressField.FieldName, text }
                };

                _candidateResults = await _locatorTask.GeocodeAsync(inputAddress, new List <string> {
                    "Match_addr"
                }, mapView1.SpatialReference, CancellationToken.None);

                List <Graphic> candidategraphicsList = new List <Graphic>();

                foreach (LocatorGeocodeResult candidate in _candidateResults)
                {
                    Graphic graphic = new Graphic()
                    {
                        Geometry = candidate.Location
                    };
                    graphic.Attributes.Add("Match_addr", candidate.Attributes["Match_addr"]);
                    graphic.Attributes.Add("Score", candidate.Score);

                    string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y);
                    graphic.Attributes.Add("LatLon", latlon);
                    candidategraphicsList.Add(graphic);
                }

                _candidateAddressesGraphicsLayer.Graphics.AddRange(candidategraphicsList);

                UpdateCandidateGraphics();
            }
            catch (AggregateException ex)
            {
                var innermostExceptions = ex.Flatten().InnerExceptions;
                if (innermostExceptions != null && innermostExceptions.Count > 0)
                {
                    MessageBox.Show(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()));
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #6
0
        private async void FindButton_Click(object sender, RoutedEventArgs e)
        {
            _candidateAddressesGraphicsLayer.Graphics.Clear();

            try
            {
                LocatorServiceInfo locatorServiceInfo = await _locatorTask.GetInfoAsync();

                Dictionary <string, string> address = new Dictionary <string, string>();

                //Street, City, State, ZIP

                if (!string.IsNullOrEmpty(InputAddress.Text))
                {
                    string fieldName = _isOnline == true ? "Address" : "Street";
                    address.Add(fieldName, InputAddress.Text);
                }
                if (!string.IsNullOrEmpty(City.Text))
                {
                    string fieldName = _isOnline == true ? "City" : "City";
                    address.Add(fieldName, City.Text);
                }
                if (!string.IsNullOrEmpty(State.Text))
                {
                    string fieldName = _isOnline == true ? "Region" : "State";
                    address.Add(fieldName, State.Text);
                }
                if (!string.IsNullOrEmpty(Zip.Text))
                {
                    string fieldName = _isOnline == true ? "Postal" : "ZIP";
                    address.Add(fieldName, Zip.Text);
                }
                _candidateResults = await _locatorTask.GeocodeAsync(address, new List <string> {
                    "Match_addr"
                }, mapView1.SpatialReference, CancellationToken.None);

                List <Graphic> candidategraphicsList = new List <Graphic>();

                Envelope resultsEnvelope = null;

                foreach (LocatorGeocodeResult candidate in _candidateResults)
                {
                    MapPoint mapPoint = candidate.Location;
                    Graphic  graphic  = new Graphic()
                    {
                        Geometry = mapPoint
                    };
                    graphic.Attributes.Add("Match_addr", candidate.Attributes["Match_addr"]);
                    graphic.Attributes.Add("Score", candidate.Score);

                    string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y);
                    graphic.Attributes.Add("LatLon", latlon);
                    candidategraphicsList.Add(graphic);

                    if (resultsEnvelope == null)
                    {
                        resultsEnvelope = new Envelope(candidate.Location, candidate.Location);
                    }

                    if (mapPoint.X < resultsEnvelope.XMin)
                    {
                        resultsEnvelope.XMin = mapPoint.X;
                    }
                    if (mapPoint.Y < resultsEnvelope.YMin)
                    {
                        resultsEnvelope.YMin = mapPoint.Y;
                    }
                    if (mapPoint.X > resultsEnvelope.XMax)
                    {
                        resultsEnvelope.XMax = mapPoint.X;
                    }
                    if (mapPoint.Y > resultsEnvelope.YMax)
                    {
                        resultsEnvelope.YMax = mapPoint.Y;
                    }
                }

                _candidateAddressesGraphicsLayer.Graphics.AddRange(candidategraphicsList);

                UpdateCandidateGraphics();

                Envelope newExtent = null;
                if (resultsEnvelope != null)
                {
                    newExtent = resultsEnvelope.Expand(2);
                }
                else
                {
                    newExtent = _candidateResults.First(x => x.Score == 100).Extent.Expand(2);
                }
                await mapView1.SetViewAsync(newExtent);
            }
            catch (AggregateException ex)
            {
                var innermostExceptions = ex.Flatten().InnerExceptions;
                if (innermostExceptions != null && innermostExceptions.Count > 0)
                {
                    MessageBox.Show(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()));
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #7
0
        private async void GeocodeButton_Click(object sender, RoutedEventArgs e)
        {
            GeocodeButton.IsEnabled = false;
            geocodeText.IsEnabled   = false;
            try
            {
                GeoCodeProgress.Visibility = Visibility.Visible;

                if (_stopsOverlay.Graphics.Count() > 0)
                {
                    panelResults.Visibility = Visibility.Collapsed;
                    _stopsOverlay.Graphics.Clear();
                    _routesOverlay.Graphics.Clear();
                    MyMapView.Overlays.Items.Clear();
                    _directionsOverlay.GraphicsSource = null;
                }

                if (_locatorServiceInfo == null)
                {
                    _locatorServiceInfo = await _locatorTask.GetInfoAsync();
                }

                var candidateResults = await _locatorTask.GeocodeAsync(
                    GetInputAddressFromUI(), new List <string> {
                    "Addr_type", "Score", "X", "Y"
                }, MyMapView.SpatialReference, CancellationToken.None);

                if (candidateResults == null || candidateResults.Count == 0)
                {
                    throw new Exception("No se encontró la dirección.");
                }

                var found = false;
                foreach (var candidate in candidateResults)
                {
                    if (candidate.Score >= 90)
                    {
                        AddGraphicFromLocatorCandidate(candidate);
                        found = true;
                        MyMapView.SetView(candidate.Extent.Expand(1));
                        await MyMapView.ZoomToScaleAsync(5000);

                        break;
                    }
                }
                GeocodeFlyout.Hide();
                if (!found)
                {
                    throw new Exception("No se encontró la dirección.");
                }
            }
            catch (AggregateException ex)
            {
                var innermostExceptions = ex.Flatten().InnerExceptions;
                if (innermostExceptions != null && innermostExceptions.Count > 0)
                {
                    var _x = new MessageDialog(string.Join(" > ", innermostExceptions.Select(i => i.Message).ToArray()), "Error").ShowAsync();
                }
                else
                {
                    var _x = new MessageDialog(ex.Message, "Error").ShowAsync();
                }
            }
            catch (System.Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Error").ShowAsync();
            }
            finally
            {
                GeoCodeProgress.Visibility = Visibility.Collapsed;
                GeocodeButton.IsEnabled    = true;
                geocodeText.IsEnabled      = true;
            }
        }