private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            _geoprocessorTask.CancelAsync();

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            MapPoint mapPoint = e.MapPoint;

            mapPoint.SpatialReference = new SpatialReference(4326);

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                Geometry = mapPoint
            };

            graphicsLayer.Graphics.Add(graphic);

            MyMap.Cursor = System.Windows.Input.Cursors.Wait;

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Observation_Point", mapPoint));
            parameters.Add(new GPLinearUnit("Viewshed_Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));

            _geoprocessorTask.OutputSpatialReference = new SpatialReference(4326);
            _geoprocessorTask.ExecuteAsync(parameters);
        }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            _geoprocessorTask.CancelAsync();

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();

            Graphic graphic = new Graphic()
            {
                Symbol   = LayoutRoot.Resources["DefaultMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint,
            };

            graphic.Attributes.Add("Info", "Start location");
            string latlon = String.Format("{0}, {1}", e.MapPoint.X, e.MapPoint.Y);

            graphic.Attributes.Add("LatLon", latlon);
            graphic.SetZIndex(1);
            graphicsLayer.Graphics.Add(graphic);

            List <GPParameter> parameters = new List <GPParameter>();

            parameters.Add(new GPFeatureRecordSetLayer("Input_Location", e.MapPoint));
            parameters.Add(new GPString("Drive_Times", "1 2 3"));

            _geoprocessorTask.ExecuteAsync(parameters);
        }
Beispiel #3
0
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            MapPoint mapPoint = e.MapPoint;

            if (_displayViewshedInfo && resultLayer != null)
            {
                ESRI.ArcGIS.Client.Tasks.IdentifyParameters identifyParams = new IdentifyParameters()
                {
                    Geometry         = mapPoint,
                    MapExtent        = MyMap.Extent,
                    Width            = (int)MyMap.ActualWidth,
                    Height           = (int)MyMap.ActualHeight,
                    LayerOption      = LayerOption.visible,
                    SpatialReference = MyMap.SpatialReference
                };

                IdentifyTask identifyTask = new IdentifyTask(resultLayer.Url);
                identifyTask.ExecuteCompleted += (s, ie) =>
                {
                    if (ie.IdentifyResults.Count > 0)
                    {
                        foreach (var identifyresult in ie.IdentifyResults)
                        {
                            if (identifyresult.LayerId == 1)
                            {
                                Graphic g = identifyresult.Feature;
                                MyInfoWindow.Anchor  = e.MapPoint;
                                MyInfoWindow.Content = g.Attributes;
                                MyInfoWindow.IsOpen  = true;
                                break;
                            }
                        }
                    }
                };
                identifyTask.ExecuteAsync(identifyParams);
            }
            else
            {
                _geoprocessorTask.CancelAsync();

                graphicsLayer.Graphics.Clear();

                mapPoint.SpatialReference = new SpatialReference(102100);

                Graphic graphic = new Graphic()
                {
                    Symbol   = LayoutRoot.Resources["StartMarkerSymbol"] as Symbol,
                    Geometry = mapPoint
                };
                graphicsLayer.Graphics.Add(graphic);

                MyMap.Cursor = System.Windows.Input.Cursors.Wait;

                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("Input_Features", mapPoint));
                parameters.Add(new GPString("Height", HeightTextBox.Text));
                parameters.Add(new GPLinearUnit("Distance", esriUnits.esriMiles, Convert.ToDouble(MilesTextBox.Text)));


                _geoprocessorTask.OutputSpatialReference = new SpatialReference(102100);
                _geoprocessorTask.SubmitJobAsync(parameters);
            }
        }
        private void MyMap_MouseClick(object sender, ESRI.ArcGIS.Client.Map.MouseEventArgs e)
        {
            IsBusy = true;
            // Cancel any outstanding Tasks
            _gpTask.CancelAsync();

            // Get the GraphicsLayer
            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;

            graphicsLayer.ClearGraphics();
            e.MapPoint.SpatialReference = MyMap.SpatialReference;

            // Add a graphic at the click point
            Graphic graphic = new ESRI.ArcGIS.Client.Graphic()
            {
                Geometry = e.MapPoint,
                Symbol   = LayoutRoot.Resources["DefaultClickSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol
            };

            graphic.SetZIndex(1);
            graphicsLayer.Graphics.Add(graphic);

            // Create the graphic to submit.
            Graphic g = new Graphic()
            {
                Geometry = _mercator.ToGeographic(e.MapPoint)
            };

            // Create a new list of GP Parameters
            List <GPParameter> gpParams = new List <GPParameter>();

            // We want to specify input attributes - create a new FeatureSet.
            FeatureSet featureSet = new FeatureSet();

            // Create the Fields and add one called "VALUE".
            featureSet.Fields = new List <Field> {
                new Field()
                {
                    FieldName = "VALUE", Type = Field.FieldType.String, Alias = "VALUE"
                }
            };

            //var fs = new FeatureSet(new List<Graphic> { g });
            // Add the graphic to the FeatureSet
            featureSet.Features.Add(g);

            // Set the graphic's attribute
            featureSet.Features[0].Attributes["VALUE"] = valueText.Text;

            // Add the GP Paramr
            gpParams.Add(new GPFeatureRecordSetLayer("InputFeatures", featureSet));
            gpParams.Add(new GPLinearUnit("Distance", esriUnits.esriKilometers, 500));

            // Register an inline handler for ExecuteCompleted event
            _gpTask.ExecuteCompleted += (s, e1) =>
            {
                // Clear the graphics layer (will remove the input Pushpin)
                graphicsLayer.Graphics.Clear();

                // Get the results
                GPExecuteResults        results = e1.Results;
                GPFeatureRecordSetLayer rs      = results.OutParameters[0] as GPFeatureRecordSetLayer;

                // Get the result feature
                Graphic graphicBuff = rs.FeatureSet.Features[0];

                // Set the symbol
                graphicBuff.Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol;

                // Add to the layer
                graphicsLayer.Graphics.Add(graphicBuff);

                // Stop the progress bar
                IsBusy = false;
            };

            // Register an inline handler for the failed event (just in case)
            _gpTask.Failed += (s2, e2) =>
            {
                MessageBox.Show(e2.Error.Message);
                IsBusy = false;
            };

            // Execute the Buffer asynchronously
            _gpTask.ExecuteAsync(gpParams);
        }
Beispiel #5
0
        void MyMap_MouseClick(object sender, Map.MouseEventArgs e)
        {
            /*
             * Add a graphic at the user input location
             */
            MyMap.MouseClick -= MyMap_MouseClick;

            if (inputGraphicsLayer == null)
            {
                inputGraphicsLayer = new GraphicsLayer();
                MyMap.Layers.Add(inputGraphicsLayer);
            }

            // Add a Graphic at the click point
            Graphic graphic = new Graphic()
            {
                Symbol   = MainGrid.Resources["IncidentMarkerSymbol"] as Symbol,
                Geometry = e.MapPoint
            };

            inputGraphicsLayer.Graphics.Add(graphic);

            /*
             * Reproject the mouseclick into the GP coordinate system
             */
            // Declare the ProjectCompleted Handler
            EventHandler <GraphicsEventArgs> ProjectCompletedHandler = null;

            // Handle the event
            ProjectCompletedHandler = (sender2, graphicsEventArgs) =>
            {
                // Unregister the handler
                geometryTask.ProjectCompleted -= ProjectCompletedHandler;

                // Cancel any existing Jobs
                geoprocessorTask.CancelAsync();

                // Handle the JobCompleted
                geoprocessorTask.JobCompleted += (sender3, jobInfoEventArgs) =>
                {
                    // Check whether it succeeded
                    if (jobInfoEventArgs.JobInfo.JobStatus != esriJobStatus.esriJobSucceeded)
                    {
                        //Do Something
                    }
                    ;

                    /*
                     * Create two new Geoprocessor Tasks to fetch the result data (thereby allowing them to run concurrently)
                     * Each will use the same event handler and we'll choose based on the Parameter Name.
                     * Alternatively could use the overload which takes an object (userToken).
                     */
                    Geoprocessor gpTaskSysvalves_Layer =
                        new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url);

                    gpTaskSysvalves_Layer.GetResultDataCompleted
                        += geoprocessorTask_GetResultDataCompleted;

                    gpTaskSysvalves_Layer.GetResultDataAsync(
                        jobInfoEventArgs.JobInfo.JobId, "Sysvalves_Layer");

                    Geoprocessor gpTaskDistribMains_Layer =
                        new Geoprocessor(traceNetworkLocalGpService.Tasks[0].Url);

                    gpTaskDistribMains_Layer.GetResultDataCompleted
                        += geoprocessorTask_GetResultDataCompleted;

                    gpTaskDistribMains_Layer.GetResultDataAsync(
                        jobInfoEventArgs.JobInfo.JobId, "DistribMains_Layer");
                };

                // Create the GP Parameter List
                List <GPParameter> parameters = new List <GPParameter>();
                parameters.Add(new GPFeatureRecordSetLayer("Flags", graphicsEventArgs.Results[0].Geometry));
                geoprocessorTask.SubmitJobAsync(parameters);
            };
            // Register the handler for the ProjectCompleted event.
            geometryTask.ProjectCompleted += ProjectCompletedHandler;

            // Project the input point into the coordinate system of the data
            geometryTask.ProjectAsync(new List <Graphic>()
            {
                new Graphic()
                {
                    Geometry = e.MapPoint
                }
            },
                                      waterNetworkLocalMapService.SpatialReference);
        }