Example #1
0
        protected async void CreateParcelSeeds()
        {
            string errorMessage = await QueuedTask.Run(async() =>
            {
                // check for selected layer
                if (MapView.Active.GetSelectedLayers().Count == 0)
                {
                    return("Please select a target parcel polygon layer in the table of contents");
                }
                //get the feature layer that's selected in the table of contents
                var destPolygonL        = MapView.Active.GetSelectedLayers().FirstOrDefault() as FeatureLayer;
                var myParcelFabricLayer = MapView.Active.Map.GetLayersAsFlattenedList().OfType <ParcelLayer>().FirstOrDefault();
                if (myParcelFabricLayer == null)
                {
                    return("Parcel layer not found in map.");
                }

                //is it a fabric parcel type layer?
                string ParcelTypeName = "";
                IEnumerable <string> parcelTypeNames = await myParcelFabricLayer.GetParcelTypeNames();
                foreach (string parcelTypeNm in parcelTypeNames)
                {
                    var polygonLyrParcelTypeEnum = await myParcelFabricLayer.GetParcelPolygonLayerByTypeName(parcelTypeNm);
                    foreach (FeatureLayer lyr in polygonLyrParcelTypeEnum)
                    {
                        if (lyr == destPolygonL)
                        {
                            ParcelTypeName = parcelTypeNm;
                            break;
                        }
                    }
                }
                if (String.IsNullOrEmpty(ParcelTypeName))
                {
                    return("Please select a target parcel polygon layer in the table of contents.");
                }
                var destLineL = await myParcelFabricLayer.GetParcelLineLayerByTypeName(ParcelTypeName);
                if (destLineL == null)
                {
                    return("");
                }
                #region Create parcel seeds
                try
                {
                    var theActiveRecord = myParcelFabricLayer.GetActiveRecord();
                    if (theActiveRecord == null)
                    {
                        return("There is no Active Record. Please set the active record and try again.");
                    }

                    var guid     = theActiveRecord.Guid;
                    var editOper = new EditOperation()
                    {
                        Name            = "Create Parcel Seeds",
                        ProgressMessage = "Create Parcel Seeds...",
                        ShowModalMessageAfterFailure = true,
                        SelectNewFeatures            = true,
                        SelectModifiedFeatures       = false
                    };
                    editOper.CreateParcelSeedsByRecord(myParcelFabricLayer, guid, MapView.Active.Extent);
                    if (!editOper.Execute())
                    {
                        return(editOper.ErrorMessage);
                    }
                }
                catch (Exception ex)
                {
                    return(ex.Message);
                }
                return("");

                #endregion
            });

            if (!string.IsNullOrEmpty(errorMessage))
            {
                MessageBox.Show(errorMessage, "Create Parcel Seeds.");
            }
        }