コード例 #1
0
        private void GeoprocessorTask_JobCompleted(object sender, ESRI.ArcGIS.Client.Tasks.JobInfoEventArgs e)
        {
            WaitGrid.Visibility = Visibility.Collapsed;

            if (e.JobInfo.JobStatus == esriJobStatus.esriJobSucceeded)
            {
                Geoprocessor geoprocessorTask = sender as Geoprocessor;

                System.Threading.Thread.Sleep(2000);

                resultLayer = geoprocessorTask.GetResultMapServiceLayer(e.JobInfo.JobId);
                resultLayer.InitializationFailed += new EventHandler <EventArgs>(resultLayer_InitializationFailed);
                resultLayer.DisplayName           = e.JobInfo.JobId;
                if (resultLayer != null)
                {
                    _displayViewshedInfo = true;
                    MyMap.Layers.Add(resultLayer);
                }
            }
            else
            {
                MessageBox.Show("Geoprocessor service failed");
                _displayViewshedInfo = false;
            }
        }
コード例 #2
0
        async void gpAircraftComms_JobCompleted(object sender, JobInfoEventArgs e)
        {
            try
            {
                if (_graphicsLayerPoly != null)
                {
                    _graphicsLayerPoly.Graphics.Clear();
                }

                Geoprocessor gpAircraftComCov = sender as Geoprocessor;
                client.ArcGISDynamicMapServiceLayer gpLayer = gpAircraftComCov.GetResultMapServiceLayer(e.JobInfo.JobId);
                gpLayer.ID      = "AircraftCommunicationCoverageMap";
                gpLayer.Opacity = .65;

                _mapWidget.Map.Layers.Add(gpLayer);

                _mapWidget.Map.Layers.Add(_graphicsLayer);

                //get legend
                HttpClient client   = new HttpClient();
                string     response =
                    await client.GetStringAsync(_baseURL + "MapServer/legend?f=pjson");

                XmlDocument   doc      = (XmlDocument)JsonConvert.DeserializeXmlNode(response);
                XmlNodeList   xmlnode  = doc.GetElementsByTagName("legend");
                List <legend> pLegends = new List <legend>();
                _dtLegends.Clear();

                foreach (XmlNode node in xmlnode)
                {
                    legend pLegend = new legend();
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name == "label")
                        {
                            pLegend.label = child.InnerText;
                        }
                        if (child.Name == "url")
                        {
                            pLegend.url = _baseURL + "MapServer/1/images/" + child.InnerText;
                        }
                    }
                    _dtLegends.Add(pLegend);
                }

                if (pWin == null)
                {
                    pWin = new LegendDialog();
                }
                pWin.ListView.DataContext = _dtLegends;
                pWin.Closed += pWin_Closed;
                pWin.Show();
                pWin.Topmost = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        // Get the users click point on the map and fire off a GP Job to calculate the viewshed
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                uiPanel.IsEnabled = false;
                inputLayer.Graphics.Clear();
                mapView.Map.Layers.Remove("ViewshedResultsLayer");

                //get the user's input point
                var inputPoint = await mapView.Editor.RequestPointAsync();

                progress.Visibility = Visibility.Visible;
                inputLayer.Graphics.Add(new Graphic()
                {
                    Geometry = inputPoint
                });

                var parameter = new GPInputParameter()
                {
                    OutSpatialReference = SpatialReferences.WebMercator
                };
                parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
                parameter.GPParameters.Add(new GPString("Height", txtHeight.Text));
                parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(txtMiles.Text)));

                var result = await SubmitAndPollStatusAsync(parameter);

                if (result.JobStatus == GPJobStatus.Succeeded)
                {
                    txtStatus.Text = "Finished processing. Retrieving results...";

                    //get the results as a ArcGISDynamicMapServiceLayer
                    var resultLayer = _gpTask.GetResultMapServiceLayer(result.JobID);
                    if (resultLayer != null)
                    {
                        //Insert the results layer just beneath the input graphics layer.
                        //This allows us to see the input point at all times.
                        resultLayer.ID = "ViewshedResultsLayer";
                        mapView.Map.Layers.Insert(mapView.Map.Layers.IndexOf(inputLayer), resultLayer);
                        await mapView.LayersLoadedAsync(new List <Layer> {
                            resultLayer
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Sample Error");
            }
            finally
            {
                uiPanel.IsEnabled   = true;
                progress.Visibility = Visibility.Collapsed;
            }
        }
コード例 #4
0
        private void GeoprocessorTask_JobCompleted(object sender, JobInfoEventArgs e)
        {
            MyMap.Cursor = System.Windows.Input.Cursors.Hand;
            if (e.JobInfo.JobStatus == esriJobStatus.esriJobSucceeded)
            {
                Geoprocessor geoprocessorTask = sender as Geoprocessor;

                System.Threading.Thread.Sleep(2000);

                resultLayer = geoprocessorTask.GetResultMapServiceLayer(e.JobInfo.JobId);
                resultLayer.InitializationFailed += new EventHandler <EventArgs>(resultLayer_InitializationFailed);
                resultLayer.DisplayName           = e.JobInfo.JobId;
                if (resultLayer != null)
                {
                    _displayViewshedInfo = true;
                    MyMap.Layers.Add(resultLayer);
                }
            }
            else
            {
                MessageBox.Show("Geoprocessor service failed");
                _displayViewshedInfo = false;
            }
        }
コード例 #5
0
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            StartButton.IsEnabled = false;
            ClearResultsButton.Visibility = Visibility.Collapsed;

            //get the user's input point
            var inputPoint = await mapView1.Editor.RequestPointAsync();

            //update UI elements
            MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Visible;
            MyProgressRing.IsActive = true;

            inputLayer.Graphics.Clear();
            inputLayer.Graphics.Add(new Graphic() { Geometry = inputPoint });

            Geoprocessor task = new Geoprocessor(new Uri("http://serverapps101.esri.com/arcgis/rest/services/ProbabilisticViewshedModel/GPServer/ProbabilisticViewshedModel"));

            var parameter = new GPInputParameter()
            {
                OutSpatialReference = new SpatialReference(102100)
            };
            parameter.GPParameters.Add(new GPFeatureRecordSetLayer("Input_Features", inputPoint));
            parameter.GPParameters.Add(new GPString("Height", HeightTextBox.Text));
            parameter.GPParameters.Add(new GPLinearUnit("Distance", LinearUnits.Miles, Convert.ToDouble(MilesTextBox.Text)));


            var result = await task.SubmitJobAsync(parameter);

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

                //show the status
                StatusTextBlock.Text = string.Join(Environment.NewLine, result.Messages.Select(x => x.Description));


                await Task.Delay(2000);
            }
            if (result.JobStatus == GPJobStatus.Succeeded)
            {
                //get the results as a ArcGISDynamicMapServiceLayer
                StatusTextBlock.Text = "Finished processing. Retrieving results...";
                var resultLayer = task.GetResultMapServiceLayer(result.JobID);

                if (resultLayer != null)
                {
                    //Add an ID so that we can reference this layer (to remove it)
                    resultLayer.ID = "MyResultsLayer";

                    //Insert the results layer just beneath the input graphics layer.
                    //This allows us to see the input point at all times.
                    mapView1.Map.Layers.Insert(mapView1.Map.Layers.IndexOf(inputLayer), resultLayer);

                }

                //Reset the UI
                StatusTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                StartButton.IsEnabled = true;
                ClearResultsButton.Visibility = Visibility.Visible;
                MyProgressRing.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                MyProgressRing.IsActive = false;
            }
        }
コード例 #6
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     = "";
        }
コード例 #7
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 = "";
        }
コード例 #8
0
        async void gpFarthest_JobCompleted(object sender, JobInfoEventArgs e)
        {
            try
            {
                Geoprocessor gpFOC = sender as Geoprocessor;
                client.ArcGISDynamicMapServiceLayer gpLayer = gpFOC.GetResultMapServiceLayer(e.JobInfo.JobId);
                gpLayer.ID      = "Farthest On Circle";
                gpLayer.Opacity = .65;

                _mapWidget.Map.Layers.Add(gpLayer);

                //get legend
                HttpClient client   = new HttpClient();
                string     response =
                    await client.GetStringAsync(_baseURL + "MapServer/legend?f=pjson");

                XmlDocument   doc      = (XmlDocument)JsonConvert.DeserializeXmlNode(response);
                XmlNodeList   xmlnode  = doc.GetElementsByTagName("legend");
                List <legend> pLegends = new List <legend>();
                int           count    = 0;
                double        test     = System.Convert.ToInt16(Range.Text) / System.Convert.ToInt16(Speed.Text);
                int           theval   = System.Convert.ToInt16(test);
                _dtLegends.Clear();

                foreach (XmlNode node in xmlnode)
                {
                    legend pLegend = new legend();
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        if (child.Name == "label")
                        {
                            pLegend.label = child.InnerText + " Hours of Transit";
                        }
                        if (child.Name == "url")
                        {
                            pLegend.url = _baseURL + "MapServer/1/images/" + child.InnerText;
                        }
                    }
                    if (count <= theval && count < 24)
                    {
                        _dtLegends.Add(pLegend);
                    }

                    count++;
                }


                if (pWin == null)
                {
                    pWin = new LegendDialog();
                }
                pWin.ListView.DataContext = _dtLegends;
                pWin.Closed += pWin_Closed;
                pWin.Show();
                pWin.Topmost = true;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }