예제 #1
0
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            MyInfoWindow.IsOpen = false;
            FindResultLocationsGraphicsLayer.Graphics.Clear();

            // If locator already processing a request, cancel it.  Note, the request is not cancelled on the server.
            if (_locatorTask.IsBusy)
            {
                _locatorTask.CancelAsync();
            }

            // If search text is empty, return
            if (string.IsNullOrEmpty(SearchTextBox.Text))
            {
                return;
            }

            // In this sample, the center of the map is used as the location from which results will be ranked and distance calculated.
            // The distance from the location is optional.  Specifies the radius of an area around a point location which is used to boost
            // the rank of geocoding candidates so that candidates closest to the location are returned first. The distance value is in meters.
            LocatorFindParameters locatorFindParams = new LocatorFindParameters()
            {
                Text                = SearchTextBox.Text,
                Location            = MyMap.Extent.GetCenter(),
                Distance            = MyMap.Extent.Width / 2,
                MaxLocations        = 5,
                OutSpatialReference = MyMap.SpatialReference
            };

            locatorFindParams.OutFields.AddRange(new string[] { "PlaceName", "City", "Region", "Country", "Score", "Distance", "Type" });

            _locatorTask.FindAsync(locatorFindParams);
        }
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            MyInfoWindow.IsOpen = false;
            FindResultLocationsGraphicsLayer.Graphics.Clear();

            // If locator already processing a request, cancel it.  Note, the request is not cancelled on the server.
            if (_locatorTask.IsBusy)
                _locatorTask.CancelAsync();

            // If search text is empty, return
            if (string.IsNullOrEmpty(SearchTextBox.Text))
                return;

            // In this sample, the center of the map is used as the location from which results will be ranked and distance calculated.
            // The distance from the location is optional.  Specifies the radius of an area around a point location which is used to boost
            // the rank of geocoding candidates so that candidates closest to the location are returned first. The distance value is in meters.
            LocatorFindParameters locatorFindParams = new LocatorFindParameters()
            {
                Text = SearchTextBox.Text,
                Location = MyMap.Extent.GetCenter(),
                Distance = MyMap.Extent.Width / 2,
                MaxLocations = 5,
                OutSpatialReference = MyMap.SpatialReference
            };
            locatorFindParams.OutFields.AddRange(new string[] { "PlaceName", "City", "Region", "Country", "Score", "Distance", "Type" });

            _locatorTask.FindAsync(locatorFindParams);
        }
        private async void SingleLineAddressButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OnlineLocatorTask locatorTask = 
                    new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), "");

                var text = SingleLineAddressText.Text;
                if (string.IsNullOrEmpty(text))
                    return;

                _locatorFindParameter = new OnlineLocatorFindParameters(text)
                {
                    Text = text,
                    Location = mapView1.Extent.GetCenter(),
                    Distance = mapView1.Extent.Width / 2,
                    MaxLocations = 5,
                    OutSpatialReference = mapView1.SpatialReference,
                    OutFields = new List<string>() { "*" }
                };

                CancellationToken cancellationToken = new CancellationTokenSource().Token;
                var results = await locatorTask.FindAsync(_locatorFindParameter, cancellationToken);
                if (_candidateGraphicsLayer.Graphics != null && _candidateGraphicsLayer.Graphics.Count > 0)
                    _candidateGraphicsLayer.Graphics.Clear();

                if (results != null)
                {
                    foreach (var result in results)
                    {
                        var geom = result.Feature.Geometry;
                        Graphic graphic = new Graphic()
                        {
                            Geometry = geom
                        };

                        graphic.Attributes.Add("Name", result.Feature.Attributes["Match_addr"]);
                        if (geom.GeometryType == GeometryType.Point)
                        {
                            var pt = geom as MapPoint;
                            string latlon = String.Format("{0}, {1}", pt.X, pt.Y);
                            graphic.Attributes.Add("LatLon", latlon);
                        }

                        if (geom.SpatialReference == null)
                        {
                            geom.SpatialReference = mapView1.SpatialReference;
                        }

                        _candidateGraphicsLayer.Graphics.Add(graphic);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private LocatorFindParameters ParseSearchText(string searchText)
        {
            LocatorFindParameters locatorFindParams = new LocatorFindParameters()
            {
                Text                = searchText,
                Location            = MyMap.Extent.GetCenter(),
                Distance            = MyMap.Extent.Width / 2,
                MaxLocations        = 1,
                OutSpatialReference = MyMap.SpatialReference
            };

            return(locatorFindParams);
        }
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SearchTextBox.Text))
            {
                return;
            }

            // Clear existing graphics for a new search
            FindResultLocationsGraphicsLayer.Graphics.Clear();
            MyLocationGraphicsLayer.Graphics.Clear();
            MyRoutesGraphicsLayer.Graphics.Clear();

            // Initialize the LocatorTask with the Esri World Geocoding Service
            var locatorTask = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");

            // In this sample, the center of the map is used as the location from which results will be ranked and distance calculated.
            // The distance from the location is optional.  Specifies the radius of an area around a point location which is used to boost
            // the rank of geocoding candidates so that candidates closest to the location are returned first. The distance value is in meters.
            LocatorFindParameters locatorFindParams = new LocatorFindParameters()
            {
                Text                = SearchTextBox.Text,
                Location            = MyMap.Extent.GetCenter(),
                Distance            = MyMap.Extent.Width / 2,
                MaxLocations        = 5,
                OutSpatialReference = MyMap.SpatialReference,
                SearchExtent        = MyMap.Extent
            };

            locatorFindParams.OutFields.AddRange(new string[] { "PlaceName", "City", "Region", "Country", "Score", "Distance", "Type" });

            locatorTask.FindCompleted += (s, ee) =>
            {
                // When a Find operation is initiated, get the find results and add to a graphics layer for display in the map
                LocatorFindResult locatorFindResult = ee.Result;
                foreach (Location location in locatorFindResult.Locations)
                {
                    // Make sure results have the right spatial reference
                    location.Graphic.Geometry.SpatialReference = MyMap.SpatialReference;

                    FindResultLocationsGraphicsLayer.Graphics.Add(location.Graphic);
                }
            };

            locatorTask.Failed += (s, ee) =>
            {
                MessageBox.Show("Locator service failed: " + ee.Error);
            };

            locatorTask.FindAsync(locatorFindParams);
        }
        private void FindButton_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(SearchTextBox.Text))
                return;

            // Clear existing graphics for a new search
            FindResultLocationsGraphicsLayer.Graphics.Clear();
            MyLocationGraphicsLayer.Graphics.Clear();
            MyRoutesGraphicsLayer.Graphics.Clear();

            // Initialize the LocatorTask with the Esri World Geocoding Service
            var locatorTask = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");

            // In this sample, the center of the map is used as the location from which results will be ranked and distance calculated.
            // The distance from the location is optional.  Specifies the radius of an area around a point location which is used to boost
            // the rank of geocoding candidates so that candidates closest to the location are returned first. The distance value is in meters.
            LocatorFindParameters locatorFindParams = new LocatorFindParameters()
            {
                Text = SearchTextBox.Text,
                Location = MyMap.Extent.GetCenter(),
                Distance = MyMap.Extent.Width / 2,
                MaxLocations = 5,
                OutSpatialReference = MyMap.SpatialReference,
                SearchExtent = MyMap.Extent
            };
            locatorFindParams.OutFields.AddRange(new string[] { "PlaceName", "City", "Region", "Country", "Score", "Distance", "Type" });

            locatorTask.FindCompleted += (s, ee) =>
            {
                // When a Find operation is initiated, get the find results and add to a graphics layer for display in the map
                LocatorFindResult locatorFindResult = ee.Result;
                foreach (Location location in locatorFindResult.Locations)
                {
                    // Make sure results have the right spatial reference
                    location.Graphic.Geometry.SpatialReference = MyMap.SpatialReference;

                    FindResultLocationsGraphicsLayer.Graphics.Add(location.Graphic);
                }
            };

            locatorTask.Failed += (s, ee) =>
            {
                MessageBox.Show("Locator service failed: " + ee.Error);
            };

            locatorTask.FindAsync(locatorFindParams);
        }
 private LocatorFindParameters ParseSearchText(string searchText)
 {
     LocatorFindParameters locatorFindParams = new LocatorFindParameters()
     {
         Text = searchText,
         Location = MyMap.Extent.GetCenter(),
         Distance = MyMap.Extent.Width / 2,
         MaxLocations = 1,
         OutSpatialReference = MyMap.SpatialReference
     };
     return locatorFindParams;
 }
예제 #8
0
        private async void SingleLineAddressButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                OnlineLocatorTask locatorTask =
                    new OnlineLocatorTask(new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer", UriKind.Absolute), "");

                var text = SingleLineAddressText.Text;
                if (string.IsNullOrEmpty(text))
                {
                    return;
                }

                _locatorFindParameter = new OnlineLocatorFindParameters(text)
                {
                    Text                = text,
                    Location            = mapView1.Extent.GetCenter(),
                    Distance            = mapView1.Extent.Width / 2,
                    MaxLocations        = 5,
                    OutSpatialReference = mapView1.SpatialReference,
                    OutFields           = new List <string>()
                    {
                        "*"
                    }
                };

                CancellationToken cancellationToken = new CancellationTokenSource().Token;
                var results = await locatorTask.FindAsync(_locatorFindParameter, cancellationToken);

                if (_candidateGraphicsLayer.Graphics != null && _candidateGraphicsLayer.Graphics.Count > 0)
                {
                    _candidateGraphicsLayer.Graphics.Clear();
                }

                if (results != null)
                {
                    foreach (var result in results)
                    {
                        var     geom    = result.Feature.Geometry;
                        Graphic graphic = new Graphic()
                        {
                            Geometry = geom
                        };

                        graphic.Attributes.Add("Name", result.Feature.Attributes["Match_addr"]);
                        if (geom.GeometryType == GeometryType.Point)
                        {
                            var    pt     = geom as MapPoint;
                            string latlon = String.Format("{0}, {1}", pt.X, pt.Y);
                            graphic.Attributes.Add("LatLon", latlon);
                        }

                        if (geom.SpatialReference == null)
                        {
                            geom.SpatialReference = mapView1.SpatialReference;
                        }

                        _candidateGraphicsLayer.Graphics.Add(graphic);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }