private async void FindAddressButton_Click(object sender, RoutedEventArgs e)
        {
            OnlineLocatorTask locator = GetLocation();

            var findParams = new OnlineLocatorFindParameters(AddressTextBox.Text);
            findParams.OutSpatialReference = MyMapView.SpatialReference;
            findParams.SourceCountry = "US";

            var results = await locator.FindAsync(findParams, new System.Threading.CancellationToken());

            if (results.Count > 0)
            {
                var firstMatch = results[0].Feature;
                var matchLocation = firstMatch.Geometry as MapPoint;

                var matchSym = new PictureMarkerSymbol();
                var pictureURI = new Uri("http://static.arcgis.com/images/Symbols/Basic/GreenStickpin.png");
                await matchSym.SetSourceAsync(pictureURI);

                var matchGraphic = new Graphic(matchLocation, matchSym);

                var graphicsLayer = MyMap.Layers["GeocodeResults"] as GraphicsLayer;
                graphicsLayer.Graphics.Add(matchGraphic);

                var matchExtent = new Envelope(matchLocation.X - 100,
                                               matchLocation.Y - 100,
                                               matchLocation.X + 100,
                                               matchLocation.Y + 100);
                await MyMapView.SetViewAsync(matchExtent);
            }
        }
        // Find matching places, create graphics and add them to the UI
        private async void FindButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility    = Visibility.Visible;
                listResults.Visibility = Visibility.Collapsed;
                _addressOverlay.Graphics.Clear();

                // Get current viewpoints extent from the MapView
                var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
                var viewpointExtent  = currentViewpoint.TargetGeometry.Extent;

                var param = new OnlineLocatorFindParameters(SearchTextBox.Text)
                {
                    SearchExtent        = viewpointExtent,
                    Location            = viewpointExtent.GetCenter(),
                    MaxLocations        = 5,
                    OutSpatialReference = MyMapView.SpatialReference,
                    OutFields           = new string[] { "Place_addr" }
                };

                var candidateResults = await _locatorTask.FindAsync(param, CancellationToken.None);

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

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

                var extent = GeometryEngine.Union(_addressOverlay.Graphics.Select(g => g.Geometry)).Extent.Expand(1.1);
                await MyMapView.SetViewAsync(extent);

                listResults.Visibility = Visibility.Visible;
            }
            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 (Exception ex)
            {
                var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
            }
            finally
            {
                progress.Visibility = Visibility.Collapsed;
            }
        }
		// Find matching places, create graphics and add them to the UI
		private async void FindButton_Click(object sender, RoutedEventArgs e)
		{
			try
			{
				progress.Visibility = Visibility.Visible;
				listResults.Visibility = Visibility.Collapsed;
				_addressOverlay.Graphics.Clear();

				// Get current viewpoints extent from the MapView
				var currentViewpoint = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry);
				var viewpointExtent = currentViewpoint.TargetGeometry.Extent;

				var param = new OnlineLocatorFindParameters(SearchTextBox.Text)
				{

					SearchExtent = viewpointExtent,
					Location = viewpointExtent.GetCenter(),
					MaxLocations = 5,
					OutSpatialReference = MyMapView.SpatialReference,
					OutFields = new string[] { "Place_addr" }
				};

				var candidateResults = await _locatorTask.FindAsync(param, CancellationToken.None);

				if (candidateResults == null || candidateResults.Count == 0)
					throw new Exception("No candidates found in the current map extent.");

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

				var extent = GeometryEngine.Union(_addressOverlay.Graphics.Select(g => g.Geometry)).Extent.Expand(1.1);
				await MyMapView.SetViewAsync(extent);

				listResults.Visibility = Visibility.Visible;
			}
			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 (Exception ex)
			{
				var _x = new MessageDialog(ex.Message, "Sample Error").ShowAsync();
			}
			finally
			{
				progress.Visibility = Visibility.Collapsed;
			}
		}
示例#4
0
        private async void geocoording_Click(object sender, RoutedEventArgs e)
        {
            //マップが準備できていなければ処理を行わない
            if (!isMapReady)
            {
                return;
            }

            //住所検索用のパラメータを作成
            OnlineLocatorFindParameters parameters = new OnlineLocatorFindParameters(addressTextBox.Text)
            {
                MaxLocations        = 5,
                OutSpatialReference = SpatialReferences.WebMercator,
                OutFields           = OutFields.All
            };

            try
            {
                //住所の検索
                IList <LocatorFindResult> resultCandidates = await onlineLocatorTask.FindAsync(parameters, CancellationToken.None);

                //住所検索結果に対する処理(1つ以上候補が返されていれば処理を実行)
                if (resultCandidates != null && resultCandidates.Count > 0)
                {
                    //現在の結果を消去
                    geocodeResultGraphicsOverlay.Graphics.Clear();

                    //常に最初の候補を採用
                    LocatorFindResult candidate = resultCandidates.FirstOrDefault();

                    //最初の候補からグラフィックを作成
                    Graphic locatedPoint = new Graphic()
                    {
                        Geometry = candidate.Feature.Geometry,
                    };


                    //住所検索結果表示用のグラフィックスオーバーレイにグラフィックを追加
                    geocodeResultGraphicsOverlay.Graphics.Add(locatedPoint);

                    //追加したグラフィックの周辺に地図を拡大
                    await MyMapView.SetViewAsync((MapPoint)locatedPoint.Geometry, 36112);
                }
                //候補が一つも見つからない場合の処理
                else
                {
                    MessageBox.Show("住所検索:該当する場所がみつかりません。");
                }
            }
            //エラーが発生した場合の処理
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("住所検索:{0}", ex.Message));
            }
        }
        // Find matching places, create graphics and add them to the UI
        private async void FindButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;
                addressesGraphicsLayer.Graphics.Clear();

                var param = new OnlineLocatorFindParameters(SearchTextBox.Text)
                {
                    SearchExtent        = mapView.Extent,
                    Location            = mapView.Extent.GetCenter(),
                    Distance            = mapView.Extent.Width / 2,
                    MaxLocations        = 5,
                    OutSpatialReference = mapView.SpatialReference,
                    OutFields           = OutFields.All
                };

                var candidateResults = await _locatorTask.FindAsync(param, CancellationToken.None);

                var graphics = candidateResults
                               .Select(result => new Graphic(result.Feature.Geometry, new Dictionary <string, object> {
                    { "Locator", result }
                }));

                foreach (var graphic in graphics)
                {
                    addressesGraphicsLayer.Graphics.Add(graphic);
                }
            }
            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 Task <Graphic> FindAddress(string address)
        {
            var uri        = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            var locator    = new OnlineLocatorTask(uri, string.Empty);
            var findParams = new OnlineLocatorFindParameters(address);

            findParams.OutSpatialReference = new SpatialReference(4326);
            Graphic matchGraphic = new Graphic();
            var     results      = await locator.FindAsync(findParams, new System.Threading.CancellationToken());

            if (results.Count > 0)
            {
                matchGraphic.Geometry = results[0].Feature.Geometry;
                matchGraphic.Attributes.Add("Name", address);
            }
            return(matchGraphic);
        }
        // Find matching places, create graphics and add them to the UI
        private async void FindButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                progress.Visibility = Visibility.Visible;
                addressesGraphicsLayer.Graphics.Clear();

                var param = new OnlineLocatorFindParameters(SearchTextBox.Text)
                {
                    SearchExtent = mapView.Extent,
                    Location = mapView.Extent.GetCenter(),
                    Distance = mapView.Extent.Width / 2,
                    MaxLocations = 5,
                    OutSpatialReference = mapView.SpatialReference,
                    OutFields = OutFields.All
                };

                var candidateResults = await _locatorTask.FindAsync(param, CancellationToken.None);

                var graphics = candidateResults
                    .Select(result => new Graphic(result.Feature.Geometry, new Dictionary<string, object> { { "Locator", result } }));
                
                foreach (var graphic in graphics)
                    addressesGraphicsLayer.Graphics.Add(graphic);
            }
            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;
            }
        }
示例#8
0
        private async System.Threading.Tasks.Task<Graphic> FindAddress(string address)
        {
            var uri = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            var locator = new OnlineLocatorTask(uri, string.Empty);

            var findParams = new OnlineLocatorFindParameters(address);
            findParams.OutSpatialReference = new SpatialReference(4326);

            Graphic matchGraphic = null;
            var results = await locator.FindAsync(findParams, new System.Threading.CancellationToken());
            if (results.Count > 0)
            {
                var firstMatch = results[0].Feature;
                var matchLocation = firstMatch.Geometry as MapPoint;
                matchGraphic = new Graphic();
                matchGraphic.Geometry = matchLocation;
                matchGraphic.Attributes.Add("Name", address);
            }

            return matchGraphic;
        }
示例#9
0
        private async void FindAddressButton_Click(object sender, RoutedEventArgs e)
        {
            try {
                progress.Visibility = Visibility.Visible;

            //The constructor takes two arguments: the URI for the geocode service and a token (required for secured services).
            var uri = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            var token = String.Empty;
            var locator = new OnlineLocatorTask(uri, token);

            // OnlineLocatorFindParameters object, which holds all relevant information for the address search.
            //var findParams = new OnlineLocatorFindParameters(AddressTextBox.Text);
            var findParams = new OnlineLocatorFindParameters(InputAddress.Text + " " + City.Text + " " + State.Text + " " + Zip.Text);
            findParams.OutSpatialReference = MyMapView.SpatialReference;
            findParams.SourceCountry = "US";

            // 
            
            var results = await locator.FindAsync(findParams, new System.Threading.CancellationToken());

            if (results.Count > 0)
            {
                var firstMatch = results[0].Feature;
                var matchLocation = firstMatch.Geometry as MapPoint;

                //Add a point graphic at the address location
                var matchSym = new PictureMarkerSymbol();
                var pictureUri = new Uri("http://static.arcgis.com/images/Symbols/Basic/GreenStickpin.png");
                await matchSym.SetSourceAsync(pictureUri);

                var matchGraphic = new Graphic(matchLocation, matchSym);

                // Get a reference to the graphic layer you defined for the map, and add the new graphic.
                var graphicsLayer = MyMap.Layers["MyGraphics"] as GraphicsLayer;

                if (graphicsLayer.Graphics.Contains(oldGraphic))
                {
                    graphicsLayer.Graphics.Remove(oldGraphic);
                }

                graphicsLayer.Graphics.Add(matchGraphic);

                oldGraphic = matchGraphic;

               // _graphicsOverlay.Graphics.Add(matchGraphic);

                txtResult.Visibility = System.Windows.Visibility.Visible;
                txtResult.Text = ("Address Found:  " +  matchLocation.X +",  " +  matchLocation.Y);

                // zooms into pin point graphic:
                //The Envelope is created by subtracting 1000 meters from the location's
                //minimum X and Y values and adding 1000 meters to the maximum X and Y values.

                var matchExtent = new Envelope(matchLocation.X,
                               matchLocation.Y,
                               matchLocation.X,
                               matchLocation.Y);
                await MyMapView.SetViewAsync(matchExtent);

            }
            else
            {
                MessageBox.Show("Unable to find address. ");
                return;
            }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to find address. ", "");
            }
        }
示例#10
0
        private async void AddGraphics(string p_parameters, string p_textLabel )
        {
            // check if there is a previous pinpoint

           

            //The constructor takes two arguments: the URI for the geocode service and a token (required for secured services).
            var uri = new Uri("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
            var token = String.Empty;
            var locator = new OnlineLocatorTask(uri, token);

            // OnlineLocatorFindParameters object, which holds all relevant information for the address search.
            var findParams = new OnlineLocatorFindParameters(p_parameters);
            findParams.OutSpatialReference = MyMapView.SpatialReference;
            findParams.SourceCountry = "US";

            // 
            var results = await locator.FindAsync(findParams, new System.Threading.CancellationToken());

            if (results.Count > 0)
            {
                var firstMatch = results[0].Feature;
                var matchLocation = firstMatch.Geometry as MapPoint;
                

                //Add a point graphic at the address location
                var matchSym = new PictureMarkerSymbol();
                var pictureUri = new Uri("http://static.arcgis.com/images/Symbols/Animated/EnlargeGradientSymbol.png");
                await matchSym.SetSourceAsync(pictureUri);

                var matchGraphic = new Graphic(matchLocation, matchSym);

                // Get a reference to the graphic layer you defined for the map, and add the new graphic.
                var graphicsLayer = MyMap.Layers["MyGraphics"] as GraphicsLayer;


                graphicsLayer.Graphics.Add(matchGraphic);

                // create a text symbol: define color, font, size, and text for the label
                var textSym = new Esri.ArcGISRuntime.Symbology.TextSymbol();
                textSym.Color = Colors.DarkRed;
                
                textSym.Font = new Esri.ArcGISRuntime.Symbology.SymbolFont("Arial", 12);
                textSym.BackgroundColor = Colors.White;
                
                textSym.Text = p_textLabel;
                //textSym.Angle = -60;
               // create a graphic for the text (apply TextSymbol)
                var textGraphic = new Esri.ArcGISRuntime.Layers.Graphic(matchLocation, textSym);
                graphicsLayer.Graphics.Add(textGraphic);

                
            }
        }
        private async void geocoording_Click(object sender, RoutedEventArgs e)
        {
            //マップが準備できていなければ処理を行わない
            if (!isMapReady) return;

            //住所検索用のパラメータを作成
            OnlineLocatorFindParameters parameters = new OnlineLocatorFindParameters(addressTextBox.Text)
            {
                MaxLocations = 5,
                OutSpatialReference = SpatialReferences.WebMercator,
                OutFields = OutFields.All
            };

            try
            {
                //住所の検索
                IList<LocatorFindResult> resultCandidates = await onlineLocatorTask.FindAsync(parameters, CancellationToken.None);

                //住所検索結果に対する処理(1つ以上候補が返されていれば処理を実行)
                if (resultCandidates != null && resultCandidates.Count > 0)
                {
                    //現在の結果を消去
                    geocodeResultGraphicsOverlay.Graphics.Clear();

                    //常に最初の候補を採用
                    LocatorFindResult candidate = resultCandidates.FirstOrDefault();

                    //最初の候補からグラフィックを作成
                    Graphic locatedPoint = new Graphic()
                    {
                        Geometry = candidate.Feature.Geometry,

                    };


                    //住所検索結果表示用のグラフィックスオーバーレイにグラフィックを追加
                    geocodeResultGraphicsOverlay.Graphics.Add(locatedPoint);

                    //追加したグラフィックの周辺に地図を拡大
                    await MyMapView.SetViewAsync((MapPoint)locatedPoint.Geometry, 36112);
                }
                //候補が一つも見つからない場合の処理
                else
                {
                    MessageBox.Show("住所検索:該当する場所がみつかりません。");
                }
            }
            //エラーが発生した場合の処理
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("住所検索:{0}", ex.Message));
            }
        }