/// <summary>
        /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if
        /// CanExecute returned true.
        /// </summary>
        public async void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature)
        {
            //This feature action relies on a profile graph widget to create a graph based on the profile line
            //Check if the view has a ProfileGraphWidget widget to display the output graph
            ProfileGraphFromMap profileWidget = OperationsDashboard.Instance.Widgets.FirstOrDefault(w => w.GetType() == typeof(ProfileGraphFromMap)) as ProfileGraphFromMap;

            if (profileWidget == null)
            {
                MessageBox.Show("Add the Profile Graph Widget to the view to execute this feature action", "Profile Graph Widget Required");
                return;
            }

            //Send the feature to the Elevation Analysis service to get the profile line
            ProfileService service = new ProfileService();

            Profile = await service.GetProfileLine(feature.Geometry);

            if (Profile == null)
            {
                MessageBox.Show("Failed to get elevation profile");
                return;
            }

            //Send the result (Profile) to the profile graph widget and ask it to generate the graph
            profileWidget.MapWidget = MapWidget.FindMapWidget(dataSource);
            profileWidget.Profile   = Profile;
            profileWidget.UpdateControls();
        }
Beispiel #2
0
        async void Map_ExtentChanged(object sender, ExtentEventArgs e)
        {
            try
            {
                if (callQuery)
                {
                    //Select features using polygon
                    IEnumerable <ESRI.ArcGIS.OperationsDashboard.DataSource> dataSources = OperationsDashboard.Instance.DataSources;
                    foreach (ESRI.ArcGIS.OperationsDashboard.DataSource d in dataSources)
                    {
                        //if (d.IsSelectable)
                        // {
                        System.Diagnostics.Debug.WriteLine(d.Name);
                        ESRI.ArcGIS.OperationsDashboard.Query query = new ESRI.ArcGIS.OperationsDashboard.Query();

                        query.SpatialFilter  = outdoorPoly;
                        query.ReturnGeometry = true;
                        query.Fields         = new string[] { d.ObjectIdFieldName };

                        ESRI.ArcGIS.OperationsDashboard.QueryResult result = await d.ExecuteQueryAsync(query);

                        //System.Diagnostics.Debug.WriteLine("Features : " + result.Features.Count);
                        if (result.Features.Count > 0)
                        {
                            // Get the array of IDs from the query results.
                            var resultOids = from feature in result.Features select System.Convert.ToInt32(feature.Attributes[d.ObjectIdFieldName]);

                            // Find the map layer in the map widget that contains the data source.
                            MapWidget mapW = MapWidget.FindMapWidget(d);
                            if (mapW != null)
                            {
                                // Get the feature layer in the map for the data source.
                                client.FeatureLayer featureL = mapW.FindFeatureLayer(d);

                                // NOTE: Can check here if the feature layer is selectable, using code shown above.
                                // For each result feature, find the corresponding graphic in the map by OID and select it.
                                foreach (client.Graphic feature in featureL.Graphics)
                                {
                                    int featureOid;
                                    int.TryParse(feature.Attributes[d.ObjectIdFieldName].ToString(), out featureOid);
                                    if (resultOids.Contains(featureOid))
                                    {
                                        feature.Select();
                                    }
                                }
                            }
                        }
                    }
                }
                callQuery = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error in MapExent Changed: " + ex.Message);
            }
        }
    /// <summary>
    /// This function creates the buffer area from user's selected feature
    /// </summary>
    /// <param name="BufferDS">BufferDS is the data source containing the BufferFeature</param>
    /// <param name="BufferFeature">BufferFeature is the feature used to generate the buffer area</param>
    public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource BufferDS, client.Graphic BufferFeature)
    {
      //Clear any running task
      _geometryTask.CancelAsync();

      //Get the map widget and the map that contains the feature used to generate the buffer
      MapWidget mw = MapWidget.FindMapWidget(BufferDS);
      client.Map mwMap = mw.Map;

      //Define the params to pass to the buffer operation
      client.Tasks.BufferParameters bufferParameters = CreateBufferParameters(BufferFeature, mwMap);

      //Execute the GP tool
      _geometryTask.BufferAsync(bufferParameters);
    }
        /// <summary>
        /// This function determines if the feature action will be enabled or disabled
        /// </summary>
        public bool CanExecute(DataSource BufferDS, client.Graphic BufferFeature)
        {
            if (BufferDistance == 0)
            {
                return(false);
            }

            MapWidget bufferDSMapWidget; //map widget containing the buffer dataSource
            MapWidget targetDSMapWidget; ////map widget containing the target dataSource

            //The feature used to generate the buffer area must not be null
            if (BufferFeature == null)
            {
                return(false);
            }

            //The data source to queried (TargetDataSource) and the data source that contains the BufferFeature (BufferDS) must not be null
            if (TargetDataSource == null || BufferDS == null)
            {
                return(false);
            }

            //Get the mapWidget consuming the target datasource
            if ((targetDSMapWidget = MapWidget.FindMapWidget(TargetDataSource)) == null)
            {
                return(false);
            }

            //Check if the map widget associated with the buffer dataSource is valid
            if ((bufferDSMapWidget = MapWidget.FindMapWidget(BufferDS)) == null)
            {
                return(false);
            }

            //Only if targetDSMapWidget and bufferDSMapWidget referes to the same object can we execute the search
            if (bufferDSMapWidget.Id != targetDSMapWidget.Id)
            {
                return(false);
            }

            //Assigning the selected values to the global variables for later use
            bufferDataSource = BufferDS;
            mapWidget        = bufferDSMapWidget;

            return(true);
        }
    public async Task QueryForFeatures(client.Geometry.Geometry bufferPolygon)
    {
      //Set up the query and query result
      Query query = new Query("", bufferPolygon, true);
      DataSource ds = OperationsDashboard.Instance.DataSources.Where(d => d.Id == TargetDataSourceId).FirstOrDefault();
      if (ds != null)
      {
          //Run the query and check the result
          QueryResult result = await ds.ExecuteQueryAsync(query);
          if ((result == null) || (result.Canceled) || (result.Features == null) || (result.Features.Count < 1))
              return;

          // Get the array of OIDs from the query results.
          var resultOids = from resultFeature in result.Features select System.Convert.ToInt32(resultFeature.Attributes[ds.ObjectIdFieldName]);

          // Find the map layer in the map widget that contains the target data source.
          MapWidget mapW = MapWidget.FindMapWidget(ds);
          if (mapW != null)
          {
              // Get the feature layer in the map for the data source.
              client.FeatureLayer featureLayer = mapW.FindFeatureLayer(ds);

              // For each graphic feature in featureLayer, use its OID to find the graphic feature from the result set.
              // Note that though the featureLayer's graphic feature and the result set's feature graphic feature share the same properties,
              // they are indeed different objects
              foreach (client.Graphic feature in featureLayer.Graphics)
              {
                  int featureOid;
                  int.TryParse(feature.Attributes[ds.ObjectIdFieldName].ToString(), out featureOid);

                  //If feature has been selected in previous session, unselect it
                  if (feature.Selected)
                      feature.UnSelect();

                  //If the feature is in the query result set, select it
                  if ((resultOids.Contains(featureOid)))
                      feature.Select();
              }
          }

      }
   
    }
Beispiel #6
0
 /// <summary>
 /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if
 /// CanExecute returned true.
 /// </summary>
 public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature)
 {
     try
     {
         // For example, in the MapWidget that ultimately provides the data source, show the popup window for the feature.
         MapWidget mw = MapWidget.FindMapWidget(dataSource);
         foreach (var widget in OperationsDashboard.Instance.Widgets)
         {
             if (widget is RangeFanWid)
             {
                 RangeFanWid pWidget = (RangeFanWid)widget;
                 pWidget.addToList(feature);
                 return;
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.Message);
     }
 }
        /// <summary>
        /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute
        /// the feature action is displayed to the user.
        /// </summary>
        /// <param name="dataSource">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param>
        /// <param name="feature">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param>
        /// <returns>True if the feature action should be enabled, otherwise false.</returns>
        public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature)
        {
            //CanExecute = false if the feature's data source is a stand alone data source (i.e. map widget is null)
            MapWidget mw = MapWidget.FindMapWidget(dataSource);

            if (mw == null)
            {
                return(false);
            }

            //CanExecute = false if the input feature's geometry is null
            if (feature.Geometry == null)
            {
                return(false);
            }

            //CanExecute = false if the input feature is not a polyline
            if (feature.Geometry.GetType() != typeof(client.Geometry.Polyline))
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// This function determines if the feature action will be enabled or disabled
 /// In order for the FeatureAction to execute:
 /// - The map widget that contains the dataSource from which the buffer area is generated must not be null
 /// - The Target DataSource that will be queried must not be null
 /// - The radius (Distance) of the buffer area must be >0 
 /// </summary>
 /// <param name="BufferDS">BufferDS is the data source containing the BufferFeature</param>
 /// <param name="BufferFeature">BufferFeature is the feature used to generate the buffer area</param>
 public bool CanExecute(ESRI.ArcGIS.OperationsDashboard.DataSource BufferDS, client.Graphic BufferFeature)
 {
     return (MapWidget.FindMapWidget(BufferDS) != null && TargetDataSourceId != null && BufferDistance > 0);
 }
Beispiel #9
0
        /*private void set_equipment(object sender, RoutedEventArgs e)
         * {
         *  if ((Boolean)((CheckBox)sender).IsChecked)
         *  {
         *      DataSourceSelectorEquipment.IsEnabled = true;
         *      //EquipmentUIDComboBox.IsEnabled = true;
         *      //EquipmentHFComboBox.IsEnabled = true;
         *      //EquipmentLabelComboBox.IsEnabled = true;
         *  }
         *  else
         *  {
         *      if (DataSources.Count > 1)
         *      {
         *          DataSources.Remove(DataSources[1]);
         *      }
         *      DataSourceSelectorEquipment.IsEnabled = false;
         *      //EquipmentUIDComboBox.IsEnabled = false;
         *      //EquipmentHFComboBox.IsEnabled = false;
         *      //EquipmentLabelComboBox.IsEnabled = false;
         *  }
         * }*/

        private async void AddDatasourceToCache(OOBDataSource ods)
        {
            try
            {
                String Uid       = ods.UIDField;
                String HF        = ods.HFField;
                String DF        = ods.DescField;
                String Labels    = "";
                String DescFlds  = "";
                String CacheName = ods.Key;
                Dictionary <String, String> fields = new Dictionary <String, String>();
                fields["UID"] = Uid;
                fields["HF"]  = HF;

                Int32 numBaseFlds = 2;
                if (DF != null)
                {
                    fields["DESCFIELD"] = DF;
                    numBaseFlds         = 3;
                }

                Int32    arraySize = ods.LabelFields.Count + ods.DescriptionFields.Count + numBaseFlds;
                string[] qfields   = new string[arraySize];
                qfields[0] = Uid;
                qfields[1] = HF;
                if (DF != null)
                {
                    qfields[2] = DF;
                }
                Int32   c     = numBaseFlds;
                Boolean first = true;
                foreach (String f in ods.LabelFields)
                {
                    if (!first)
                    {
                        Labels += ",";
                    }
                    else
                    {
                        first = false;
                    }
                    Labels    += f;
                    qfields[c] = f;
                    ++c;
                }
                first = true;
                foreach (String f in ods.DescriptionFields)
                {
                    if (!first)
                    {
                        DescFlds += ",";
                    }
                    else
                    {
                        first = false;
                    }
                    DescFlds  += f;
                    qfields[c] = f;
                    ++c;
                }
                fields["LABELS"]   = Labels;
                fields["DESCFLDS"] = DescFlds;
                Query q = new Query();



                q.Fields = qfields;
                cache.AddFeatuereContainer(CacheName);

                DataSource ds = ods.DataSource;
                q.ReturnGeometry = true;
                QueryResult res = await ds.ExecuteQueryAsync(q);

                var resultOids = from feature in res.Features select System.Convert.ToInt32(feature.Attributes[ds.ObjectIdFieldName]);

                MapWidget           mw = MapWidget.FindMapWidget(ds);
                client.FeatureLayer fl = mw.FindFeatureLayer(ds);
                //fl.Update();
                client.UniqueValueRenderer r = fl.Renderer as client.UniqueValueRenderer;
                foreach (client.Graphic g in fl.Graphics)
                {
                    cache.AddFeature(CacheName, g, ods.BaseDescription, ods.BaseLabel, fields, r);
                }
                ods.IsCacheCreated = true;

                //cache.AddFeature
            }
            catch (Exception e)
            {
                System.Windows.MessageBox.Show(e.Message + "/n" + e.Source
                                               + "/n" + e.StackTrace);
            }
        }
        /// <summary>
        /// Execute is called when the user chooses the feature action from the feature actions context menu. Only called if
        /// CanExecute returned true.
        /// </summary>
        public void Execute(ESRI.ArcGIS.OperationsDashboard.DataSource dataSource, client.Graphic feature)
        {
            int wkid = MapWidget.FindMapWidget(dataSource).Map.SpatialReference.WKID;

            GenerateReportAsync(feature, wkid);
        }
        /// <summary>
        /// Determines if the feature action can be executed based on the specified data source and feature, before the option to execute
        /// the feature action is displayed to the user.
        /// </summary>
        /// <param name="searchAreaDS">The data source which will be subsequently passed to the Execute method if CanExecute returns true.</param>
        /// <param name="searchArea">The data which will be subsequently passed to the Execute method if CanExecute returns true.</param>
        /// <returns>True if the feature action should be enabled, otherwise false.</returns>
        public bool CanExecute(DataSource searchAreaDS, client.Graphic searchArea)
        {
            //Map widget that contains the searchArea data Source
            MapWidget areaMW;
            //Map widget that contains the rescueTeam data Source
            MapWidget teamMW;

            try
            {
                #region Check if the polygon data source is valid
                //Check if the searchAreaDS has a display name field
                if (searchAreaDS.DisplayFieldName == null)
                {
                    return(false);
                }

                //Check if the map widget associated with the search area dataSource is valid
                if ((areaMW = MapWidget.FindMapWidget(searchAreaDS)) == null)
                {
                    return(false);
                }

                //Check if the search area layer is polygon
                if (areaMW.FindFeatureLayer(searchAreaDS).LayerInfo.GeometryType != client.Tasks.GeometryType.Polygon)
                {
                    return(false);
                }
                #endregion

                #region Find the rescue team data source and check if it is consumed by the same mapWidget as the polygon data source
                //Find all the data sources that can possibly be a taem data sources
                //(i.e. are associated with point layers and hase the field "SearchAreaName")
                var teamDataSrcs = OperationsDashboard.Instance.DataSources.Where(ds => IsValidTeamDataSource(ds));
                if (teamDataSrcs == null || teamDataSrcs.Count() == 0)
                {
                    return(false);
                }

                //For each of the data source retrieved, get its associated mapWidget
                //Check if the polygon feature source is also consumed by the same map widget (i.e. teamMW)
                foreach (DataSource teamDataSrc in teamDataSrcs)
                {
                    if ((teamMW = MapWidget.FindMapWidget(teamDataSrc)) == null)
                    {
                        return(false);
                    }

                    if (teamMW.Id == areaMW.Id)
                    {
                        MapWidget        = areaMW;
                        TeamDataSrc      = teamDataSrc;
                        TeamFeatureLayer = MapWidget.FindFeatureLayer(TeamDataSrc);
                        return(true);
                    }
                }
                #endregion

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }