protected override Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
        {
            //Check we only have one feature to extend to
            if (MapView.Active.Map.SelectionCount != 1)
            {
                MessageBox.Show("Please select one polyline or polygon feature to extend to", "Extend");
                return Task.FromResult(true);
            }

            //Run on MCT
            return QueuedTask.Run(() =>
            {
                //get selected feature geometry
                var selectedFeatures = MapView.Active.Map.GetSelection();
                var insp = new Inspector();
                insp.Load(selectedFeatures.Keys.First(), selectedFeatures.Values.First());
                var selGeom = insp.Shape;
                if (!(selGeom.GeometryType == GeometryType.Polygon
                    || selGeom.GeometryType == GeometryType.Polyline))
                {
                    MessageBox.Show("Please choose as the selected feature either a polyline or polygon feature to extend to");
                    return false;
                }

                //find feature at the click
                var clickFeatures = MapView.Active.GetFeatures(geometry);
                insp.Load(clickFeatures.First().Key, clickFeatures.First().Value);
                var clickGeom = insp.Shape as Polyline;
                if (clickGeom == null)
                {
                    MessageBox.Show("Please select a polyline feature to extend");
                    return false;
                }

                //extend the line to the poly?
                ArcGIS.Core.Geometry.Polyline extPolyline;
                extPolyline = GeometryEngine.Extend(clickGeom, (selGeom.GeometryType == GeometryType.Polygon ? GeometryEngine.Boundary(selGeom) as Polyline : selGeom as Polyline), ExtendFlags.Default);
                if (extPolyline == null)
                {
                    MessageBox.Show(string.Format("Unable to extend the clicked {0} to the selected {1}",
                        clickGeom.GeometryType, selGeom.GeometryType));
                    return false;
                }

                //set the new geometry back on the feature
                insp.Shape = extPolyline;

                //create and execute the edit operation
                var op = new EditOperation();
                op.Name = "Extend";
                op.SelectModifiedFeatures = false;
                op.SelectNewFeatures = false;
                op.Modify(insp);
                return op.Execute();
            });
        }
    protected override Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
    {
      //Simple check for selected layer
      if (MappingModule.ActiveTOC.SelectedLayers.Count == 0)
      {
        System.Windows.MessageBox.Show("Select a layer in the toc");
        return Task.FromResult(true);
      }

      //jump to CIM thread
      return QueuedTask.Run(async () =>
      {
        //Get the selected layer in toc
        var featLayer = MappingModule.ActiveTOC.SelectedLayers[0] as FeatureLayer;

        //find feature oids under the sketch for the selected layer
        var features = await MapView.Active.HitTestAsync(geometry, CancelableProgressor.None);
        var featOids = features.Where(x => x.Item1 == featLayer).Select(x => x.Item2).First();

        //update the attributes of those features
        var fi = new FeatureInspector(true);
        await fi.FillAsync(featLayer, featOids);
        await fi.Attributes.Where(a => a.FieldName == "PARCEL_ID").First().SetValueAsync(42);

        //create and execute the edit operation
        var op = new EditOperation();
        op.Name = "The ultimate answer";
        op.SelectModifiedFeatures = true;
        op.SelectNewFeatures = false;
        op.Modify(fi);
        return await op.ExecuteAsync();
      });
    }
    protected override Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
    {
      //Simple check for selected layer
      if (MapView.Active.GetSelectedLayers().Count == 0)
      {
        MessageBox.Show("Please select a layer in the toc","Update attributes with sketch");
        return Task.FromResult(true);
      }

      //Run on MCT
      return QueuedTask.Run(() =>
      {
        //Get the selected layer in toc
        var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;

        //find feature oids under the sketch for the selected layer
        var features = MapView.Active.GetFeatures(geometry);
        var featOids = features[featLayer];

        //update the attributes of those features
        var insp = new Inspector();
        insp.Load(featLayer, featOids);
        insp["PARCEL_ID"] = 42;

        //create and execute the edit operation
        var op = new EditOperation();
        op.Name = "Update parcel";
        op.SelectModifiedFeatures = true;
        op.SelectNewFeatures = false;
        op.Modify(insp);
        return op.Execute();
      });
    }
    /// <summary>
    /// Called when a sketch is completed.
    /// </summary>
    protected override async Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
    {
      var popupContent = await QueuedTask.Run(() =>
      {
        var mapView = MapView.Active;
        if (mapView == null)
          return null;

        //Get the features that intersect the sketch geometry.
        var result = mapView.GetFeatures(geometry);

        //For each feature in the result create a new instance of our custom popup content class.
        List<PopupContent> popups = new List<PopupContent>();
        foreach (var kvp in result)
        {
          kvp.Value.ForEach(id => popups.Add(new DynamicPopupContent(kvp.Key, id)));
        }

        //Flash the features that intersected the sketch geometry.
        mapView.FlashFeature(result);

        //return the collection of popup content object.
        return popups;
      });

      //Create the list of custom popup commands to show at the bottom of the pop-up window.
      var commands = CreateCommands();

      //Show the custom pop-up with the custom commands and the default pop-up commands. 
      MapView.Active.ShowCustomPopup(popupContent, CreateCommands(), true);
      return true;
    }
        /// <summary>
        /// Called when the sketch is finished.
        /// </summary>
        protected override async Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
        {
            return await QueuedTask.Run(() =>
            {
                //Return all the features that intersect the sketch geometry
                var result = MapView.Active.GetFeatures(geometry);

                MapView.Active.SelectFeatures(geometry, SelectionCombinationMethod.New);

                return true;
            });
        }
        private static Task DoSomeWork(ArcGIS.Desktop.Framework.Threading.Tasks.ProgressDialog progDialog)
        {
            return QueuedTask.Run(async () =>
            {
                for (uint iSeconds = 0; iSeconds < 10; iSeconds++)
                {
                    await Task.Delay(1000);
                }
                progDialog.Hide();
            });

        }
    /// <summary>
    /// Called when the sketch is finished.
    /// </summary>
    protected override async Task<bool> OnSketchCompleteAsync(ArcGIS.Core.Geometry.Geometry geometry)
    {
      //Get the instance of the ViewModel from the dock pane
      var featureSelVM = Module1.FeatureSelectionVM;
      if (featureSelVM == null || featureSelVM.SelectedLayer == null)
        return true;

      return await QueuedTask.Run(() =>
      {
        //Return all the features that intersect the sketch geometry
        var result = MapView.Active.GetFeatures(geometry);
        var layerSelection = result.FirstOrDefault(kvp => kvp.Key == featureSelVM.SelectedLayer);

        //Clear the selection if no features where returned
        if (!result.ContainsKey(featureSelVM.SelectedLayer))
        {
          featureSelVM.SelectedLayer.Select(null, SelectionCombinationMethod.Subtract);
          return true;
        }

        //Construct a query filter using the OIDs of the features that intersected the sketch geometry
        var oidList = result[featureSelVM.SelectedLayer];
        var oid = featureSelVM.SelectedLayer.GetTable().GetDefinition().GetObjectIDField();
        var qf = new ArcGIS.Core.Data.QueryFilter() { WhereClause = string.Format("({0} in ({1}))", oid, string.Join(",", oidList)) };

        //Add to the clause using the where clause specified in the dock pane.
        if (featureSelVM.WhereClause != "" && featureSelVM.WhereClause != null)
          qf.WhereClause += string.Format(" AND ({0})", featureSelVM.WhereClause);

        //Return if the expression is not valid.
        if (!featureSelVM.ValidateExpresion(false))
          return true;

        //Change the method depending on the hot keys that are pressed.
        var method = SelectionCombinationMethod.New;
        if (_ctrlPressed && _shiftPressed)
          method = SelectionCombinationMethod.And;
        else if (_ctrlPressed)
          method = SelectionCombinationMethod.Subtract;
        else if (_shiftPressed)
          method = SelectionCombinationMethod.Add;

        try
        {
          //Create the new selection
          featureSelVM.SelectedLayer.Select(qf, method);
        }
        catch (Exception){} //May occur if expression validates but is still invalid expression.
        return true;
      });
    }
        /// <summary>
        /// This is a basic FinishSketch method which illustrates the process of using the sketch geometry for a cut. 
        ///   1. Create edit operation
        ///   2. Use the sketch geometry to perform a spatial query
        ///   3. Use the found features and use them to set up a cut operation
        ///   3. Execute the edit operation
        ///  
        /// </summary>
        /// <returns>Task of bool</returns>
        protected override async Task<bool> FinishSketch(ArcGIS.Core.Geometry.Geometry geometry, 
                                                         Dictionary<string, object> attributes) {
            if (CurrentTemplate == null)
                return false;
            // intialize a list of ObjectIDs that need to be cut
            List<int> cutOIDs = new List<int>();

            Table fc = await this.CurrentTemplate.Layer.getFeatureClass();
            // on a separate thread
            await QueuingTaskFactory.StartNew(() => {
                // find the features crossed by the sketch geometry
                RowCursor rc = fc.Search(geometry, SpatialRelationship.Crosses);

                // add the feature IDs into our prepared list
                while (rc.MoveNext()) {
                    cutOIDs.Add(rc.Current.ObjectID);
                }
            });
            if (!cutOIDs.Any())
                return true;//nothing to cut

            // create an edit operation for the cut
            var op = await EditingModule.CreateEditOperationAsync();
            op.Name = string.Format("Cut {0}", this.CurrentTemplate.Layer.Name);
            op.ProgressMessage = "Working...";
            op.CancelMessage = "Operation canceled";
            op.ErrorMessage = "Error cutting features";
            op.SelectModifiedFeatures = false;
            op.SelectNewFeatures = false;

            // for each of the found features set up a cut method inside our edit operation
            // for multiple ObjectIDs the cuts with will be stacked into one operation
            foreach (var oid in cutOIDs) {
                op.Cut(this.CurrentTemplate.Layer, oid, geometry);
            }

            //execute the operation
            return await op.ExecuteAsync();
        }
 private static EditOperation CreateOperationAndBuildInitialEnvelope(ref EnvelopeBuilder envBuilder, ref ArcGIS.Core.Geometry.Envelope env)
 {
     var createOperation = new EditOperation();
     createOperation.Name = "Highlight Design Features";
     createOperation.SelectNewFeatures = false;
     if (envBuilder == null)
     {
         envBuilder = new EnvelopeBuilder();
         envBuilder.XMin = 0;
         envBuilder.XMax = 0;
         envBuilder.YMin = 0;
         envBuilder.YMax = 0;
         env = envBuilder.ToGeometry().Extent;
     }
     return createOperation;
 }
 private void OnActiveToolChanged(ArcGIS.Desktop.Framework.Events.ToolEventArgs args)
 {
     if (args.CurrentID == "ProSymbolEditor_DrawFeatureSketchTool")
     {
         //Toggle all down
         AddToMapToolEnabled = true;
         SelectToolEnabled = false;
     }
     else if (args.CurrentID == "ProSymbolEditor_SelectionMapTool")
     {
         SelectToolEnabled = true;
         AddToMapToolEnabled = false;
     }
     else
     {
         //Disable all toggles
         AddToMapToolEnabled = false;
         SelectToolEnabled = false;
     }
 }
        /// <summary>
        /// Add a point to the specified mapview
        /// </summary>
        /// <param name="point">The location of the graphic</param>
        /// <param name="mapView">The mapview to whose overlay the graphic will be added</param>
        /// <returns></returns>
        public static async void AddToMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
        {
            ArcGIS.Core.CIM.CIMPointSymbol symbol = null;

            await QueuedTask.Run(() =>
               {
                   // Construct point symbol
                   symbol = SymbolFactory.ConstructPointSymbol(ColorFactory.Red, 10.0, SimpleMarkerStyle.Star);
               });

            //Get symbol reference from the symbol 
            CIMSymbolReference symbolReference = symbol.MakeSymbolReference();

            await QueuedTask.Run(() =>
                {
                    _overlayObject = mapView.AddOverlay(point, symbolReference);
                });

        }
        private async void OnMapSelectionChanged(ArcGIS.Desktop.Mapping.Events.MapSelectionChangedEventArgs args)
        {
            //Get the selected features from the map and filter out the standalone table selection.
            var selectedFeatures = args.Selection
              .Where(kvp => kvp.Key is BasicFeatureLayer)
              .ToDictionary(kvp => (BasicFeatureLayer)kvp.Key, kvp => kvp.Value);


            //TODO:  Further filter features so it only contains ones that are in layers that are in the military schema
            SelectedFeaturesCollection.Clear();
            foreach (KeyValuePair<BasicFeatureLayer, List<long>> kvp in selectedFeatures)
            {
                await QueuedTask.Run(() =>
                {
                    ArcGIS.Core.Data.Field symbolSetField = kvp.Key.GetTable().GetDefinition().GetFields().FirstOrDefault(x => x.Name == "symbolset");
                    CodedValueDomain symbolSetDomain = symbolSetField.GetDomain() as CodedValueDomain;
                    SortedList<object, string> symbolSetDomainSortedList = symbolSetDomain.GetCodedValuePairs();
                    ArcGIS.Core.Data.Field symbolEntityField = kvp.Key.GetTable().GetDefinition().GetFields().FirstOrDefault(x => x.Name == "symbolentity");
                    CodedValueDomain symbolEntityDomain = symbolEntityField.GetDomain() as CodedValueDomain;
                    SortedList<object, string> symbolEntityDomainSortedList = symbolEntityDomain.GetCodedValuePairs();

                    foreach (long id in kvp.Value)
                    {
                        //Query for field values

                        string oidFieldName = kvp.Key.GetTable().GetDefinition().GetObjectIDField();
                        QueryFilter queryFilter = new QueryFilter();
                        queryFilter.WhereClause = string.Format("{0} = {1}", oidFieldName, id);
                        RowCursor cursor = kvp.Key.Search(queryFilter);
                        Row row = null;

                        if (cursor.MoveNext())
                        {
                            row = cursor.Current;
                        }

                        if (row != null)
                        {
                            GeometryType geometryType = ArcGIS.Core.Geometry.GeometryType.Point;

                            if (kvp.Key.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolygon)
                            {
                                geometryType = ArcGIS.Core.Geometry.GeometryType.Polygon;
                            }
                            else if (kvp.Key.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPoint)
                            {
                                geometryType = ArcGIS.Core.Geometry.GeometryType.Point;
                            }
                            else if (kvp.Key.ShapeType == ArcGIS.Core.CIM.esriGeometryType.esriGeometryPolyline)
                            {
                                geometryType = ArcGIS.Core.Geometry.GeometryType.Polyline;
                            }

                            SelectedFeature newSelectedFeature = new SelectedFeature(kvp.Key, id);
                            
                            foreach(KeyValuePair<object, string> symbolSetKeyValuePair in symbolSetDomainSortedList)
                            {
                                if (symbolSetKeyValuePair.Key.ToString() == row["symbolset"].ToString())
                                {
                                    newSelectedFeature.SymbolSetName = symbolSetKeyValuePair.Value;
                                    break;
                                }
                            }

                            foreach (KeyValuePair<object, string> symbolEntityKeyValuePair in symbolEntityDomainSortedList)
                            {
                                if (symbolEntityKeyValuePair.Key.ToString() == row["symbolentity"].ToString())
                                {
                                    newSelectedFeature.EntityName = symbolEntityKeyValuePair.Value;
                                    break;
                                }
                            }

                            SelectedFeaturesCollection.Add(newSelectedFeature);
                        }

                    }
                });
            }

            SelectedSelectedFeature = SelectedFeaturesCollection.FirstOrDefault();
        }
        /// <summary>
        /// All-in-one. Update the graphic on the overlay if it was previously added
        /// otherwise, make it and add it
        /// </summary>
        /// <param name="newLocation">The new location to be added to the map</param>
        /// <param name="mapView"></param>
        /// <returns></returns>
        public static void UpdateMapOverlay(ArcGIS.Core.Geometry.MapPoint point, MapView mapView)
        {
            
            if (_overlayObject != null)
            {
                _overlayObject.Dispose();
                _overlayObject = null;

               AddToMapOverlay(point, mapView);
            }
            else
            {
                //first time
                AddToMapOverlay(point, mapView);
            }
        }
 private string GetName(ArcGIS.Core.Data.Field field)
 {
     return string.IsNullOrEmpty(field.AliasName) ? field.Name : field.AliasName;
 }
예제 #15
0
        /// <summary>
        /// All-in-one. Update the graphic on the overlay if it was previously added
        /// otherwise, make it and add it
        /// </summary>
        /// <param name="newLocation">The new location to be added to the map</param>
        /// <param name="mapView"></param>
        /// <returns></returns>
        public static void UpdateMapOverlay(ArcGIS.Core.CIM.PointN point, MapView mapView) {
            if (!mapView.Is2D)
                return;//only currently works for 2D

            //CIMPointGraphicHelper graphicHlpr = null;
            if (_lookup.ContainsKey(mapView.Map.RepositoryID)) {
                ////graphicHlpr = _lookup[mapView.Map.ID];
                ////graphicHlpr.UpdateLocation(point);
                ////int id = graphicHlpr.graphicID;
                ////mapView.UpdateOverlayGraphic(ref id, graphicHlpr.XML);
                ////graphicHlpr.graphicID = id;
                RemoveFromMapOverlay(mapView);
                AddToMapOverlay(point, mapView);
            }
            else {
                //first time
                AddToMapOverlay(point, mapView);
            }
        }
 /// <summary>
 /// Get the time time to begin inserting new keyframes and shift any existing keyframes if necessary.
 /// </summary>
 /// <param name="animation">The animation to be modified.</param>
 private double GetInsertTime(ArcGIS.Desktop.Mapping.Animation animation)
 {
   var duration = Animation.Settings.Duration;
   double currentTimeSeconds = 0;
   if (animation.Duration > TimeSpan.Zero)
   {
     if (Animation.Settings.IsAfterTime)
     {
       currentTimeSeconds = (animation.Duration + TimeSpan.FromSeconds(Animation.Settings.AfterTime)).TotalSeconds;
     }
     else
     {
       currentTimeSeconds = Animation.Settings.AtTime;
       ShiftKeyframes(currentTimeSeconds, duration);
     }
   }
   return currentTimeSeconds;
 }
예제 #17
0
        ///// <summary>
        ///// Make a CIMPointGraphic that can be added to the map overlay
        ///// </summary>
        ///// <param name="point">The location of the graphic</param>
        ///// <returns></returns>
        //internal static CIMPointGraphicHelper MakeCIMPointGraphic(PointN point)
        //{
        //    return new CIMPointGraphicHelper(point);
        //}
        /// <summary>
        /// Add a point to the specified mapview
        /// </summary>
        /// <param name="mapView">The mapview to whose overlay the graphic will be added</param>
        /// <returns>The graphic id assigned to the graphic in the overlay</returns>
        public static void AddToMapOverlay(ArcGIS.Core.CIM.PointN point, MapView mapView) {
            if (!mapView.Is2D)
                return;//only currently works for 2D

            CIMPointGraphicHelper graphicHlpr = new CIMPointGraphicHelper(point);
            graphicHlpr.graphicID = mapView.AddOverlayGraphic(graphicHlpr.XML);
            _lookup[mapView.Map.RepositoryID] = graphicHlpr;

        }