コード例 #1
0
        void locator_FindCompleted(object sender, LocatorFindEventArgs e)
        {
            GraphicsLayer graphicsLayer = (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer);

            if (e.Result != null)
            {
                LocatorFindResult findResult      = e.Result;
                Graphic           graphicLocation = findResult.Locations[0].Graphic;
                graphicLocation.Geometry.SpatialReference = MyMap.SpatialReference;
                graphicLocation.Attributes.Add("name", findResult.Locations[0].Name);

                _stops.Add(graphicLocation);
                if ((string)e.UserState == "from")
                {
                    graphicLocation.Symbol = LayoutRoot.Resources["FromSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;
                    //Geocode to address
                    _locator.FindAsync(ParseSearchText(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);
            }
        }
コード例 #2
0
        private void GetDirections_Click(object sender, RoutedEventArgs e)
        {
            //Reset
            DirectionsStackPanel.Children.Clear();
            _stops.Clear();

            (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer).Graphics.Clear();
            _locator.CancelAsync();
            _routeTask.CancelAsync();

            //Geocode from address
            _locator.FindAsync(ParseSearchText(FromTextBox.Text), "from");
        }
コード例 #3
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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 private void FindLocationsWithSearchText(string searchText)
 {
     if(MyMap == null) return;
     EnableSearchMenuItem(false);
     EnableDirectionsButton(false);
     UpdateLayer("HighlightLayer", true, false);
     UpdateLayer("DestinationLayer", true, false);
     var l = UpdateLayer("FindResultsLayer", true, true);
     #region Locator - Finds nearest business and triggers reverse geocode to get addresses for locations
     var locator = new Locator(GEOCODE_URL);
     locator.FindCompleted += (s, e) =>
     {
         MyProgressBar.IsIndeterminate = false;
         var locations = e.Result.Locations;
         if (locations.Count > 0)
         {
             UpdateSearchResultsPanel(locations);
             GetAddressesOfLocations(l.Graphics); // Reverse geocode locations
         }
         else
             MessageBox.Show(string.Format("No locations found for '{0}'", searchText));
     };
     locator.Failed += (s, e) =>
     {
         MyProgressBar.IsIndeterminate = false;
         MessageBox.Show(string.Format("Find '{0}' failed with error '{1}'", SearchFieldTb.Text.Trim(), e.Error.Message));
         ShowElement(MyMap);
     };
     MyProgressBar.IsIndeterminate = true;
     locator.FindAsync(new LocatorFindParameters()
     {
         Text = searchText,
         OutSpatialReference = MyMap.SpatialReference,
         SearchExtent = MyMap.Extent,
         Location = (MyMap.Layers["MyGpsLayer"] as GpsLayer).Position,
         Distance = DISTANCE,
         MaxLocations = MAX_RESULTS
     });
     #endregion
 }