コード例 #1
0
        // On tap, either get related records for the tapped well or find nearby wells if no well was tapped
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            // Show busy UI
            BusyVisibility = Visibility.Visible;

            // Get the map
            if (m_mapView == null)
            {
                m_mapView = (MapView)sender;
            }


            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            // Buffer graphic by 100 meters, create graphic with buffer, add to buffers
            var buffer = GeometryEngine.Buffer(g.Geometry, 100);

            Buffers.Add(new Graphic()
            {
                Geometry = buffer
            });

            // Find intersecting parcels and show them on the map
            var result = await doQuery(buffer);

            if (result != null && result.FeatureSet != null && result.FeatureSet.Features.Count > 0)
            {
                // Instead of adding parcels one-by-one, update the Parcels collection all at once to
                // allow the map to render the new features in one rendering pass.
                Parcels = new ObservableCollection <Graphic>(Parcels.Union(result.FeatureSet.Features));
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
        }
コード例 #2
0
        // On tap, get an input line and perform a buffer and clip operation
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;

            // Clear previous results
            TapPoints.Clear();
            Currents.Clear();



            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the drive time calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
                                                         "Specialty/ESRI_Currents_World/GPServer/MessageInABottle"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            var projectedMapPoint = GeometryEngine.Project(e.Location, SpatialReferences.Wgs84);

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Point", projectedMapPoint));
            parameter.GPParameters.Add(new GPDouble("Days", Days));

            try
            {
                // Run the operation
                var result = await task.ExecuteAsync(parameter);

                // Check that layers were returned from the operation
                var outputLayers = result.OutParameters.OfType <GPFeatureRecordSetLayer>();
                if (outputLayers.Count() > 0)
                {
                    // Get the first layer returned - this will be the drive time areas
                    var outputLayer = outputLayers.First();
                    if (outputLayer.FeatureSet != null && outputLayer.FeatureSet.Features != null)
                    {
                        // Instead of adding ocean current features one-by-one, update the collection all at once to
                        // allow the map to render the new features in one rendering pass.
                        Currents = new ObservableCollection <Graphic>(outputLayer.FeatureSet.Features);
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "No results returned";
                }
            }
            catch (Exception ex)
            {
                error = "Calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
            {
                MessageBox.Show(error);
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
        }
コード例 #3
0
        private async void mapView1_Tap(object sender, MapViewInputEventArgs e)
        {
            if (BusyVisibility == Visibility.Visible)
            {
                MessageBox.Show("Please wait until the current operation is complete.");
                return;
            }

            // Show busy UI
            BusyVisibility = Visibility.Visible;
            StatusText     = "Executing...";

            // Clear previous results
            TapPoints.Clear();
            if (m_viewshedLayer != null)
            {
                Layers.Remove(m_viewshedLayer);
            }


            // Create graphic and add to tap points
            var g = new Graphic()
            {
                Geometry = e.Location
            };

            TapPoints.Add(g);

            string error = null;

            // Initialize the Geoprocessing task with the viewshed calculation service endpoint
            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/ArcGIS/rest/services/" +
                                                         "ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            // Initialize input parameters
            var parameter = new GPInputParameter()
            {
                OutSpatialReference = SpatialReferences.WebMercator
            };

            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", e.Location));
            parameter.GPParameters.Add(new GPString("Height", "50"));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, 10));

            try
            {
                var result = await task.SubmitJobAsync(parameter);

                // Poll the server for results every two seconds.
                while (result.JobStatus != GPJobStatus.Cancelled &&
                       result.JobStatus != GPJobStatus.Deleted &&
                       result.JobStatus != GPJobStatus.Failed &&
                       result.JobStatus != GPJobStatus.Succeeded &&
                       result.JobStatus != GPJobStatus.TimedOut)
                {
                    result = await task.CheckJobStatusAsync(result.JobID);

                    // show the status
                    var descriptions = result.Messages.Select(msg => msg.Description);
                    var status       = string.Join(Environment.NewLine, descriptions);
                    if (!string.IsNullOrEmpty(status))
                    {
                        StatusText = status;
                    }

                    await Task.Delay(2000);
                }

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    // get the results as a ArcGISDynamicMapServiceLayer
                    StatusText      = "Calculation complete. Retrieving results...";
                    m_viewshedLayer = task.GetResultMapServiceLayer(result.JobID);

                    if (m_viewshedLayer != null)
                    {
                        // Insert the results layer beneath the tap points layer.
                        // This allows the input point to be visible at all times.
                        Layers.Insert(Layers.IndexOf(m_tapPointsLayer), m_viewshedLayer);

                        // Wait until the viewshed layer is initialized
                        await m_viewshedLayer.InitializeAsync();
                    }
                    else
                    {
                        error = "No results returned";
                    }
                }
                else
                {
                    error = "Viewshed calculation failed";
                }
            }
            catch (Exception ex)
            {
                error = "Viewshed calculation failed: " + ex.Message;
            }

            // If operation did not succeed, notify user
            if (error != null)
            {
                MessageBox.Show(error);
            }

            // Hide busy UI
            BusyVisibility = Visibility.Collapsed;
            StatusText     = "";
        }