Beispiel #1
0
        private string GetDisplayField(FeatureClass featureClass)
        {
            string displayField = "";

            Map map = MapView.Active.Map;

            if (map == null)
            {
                return(displayField);
            }

            //Get flattened layers from Map. If the feature class exists in the map, get that feature Layer and its display field. If not, return null.
            var layer = map.GetLayersAsFlattenedList().OfType <FeatureLayer>().FirstOrDefault(lyr => lyr.GetFeatureClass().GetName() == featureClass.GetName());

            if (layer == null)
            {
                return("");
            }
            CIMFeatureLayer currentCIMFeatureLayer = layer.GetDefinition() as CIMFeatureLayer;
            CIMFeatureTable cimFeatureTable        = currentCIMFeatureLayer.FeatureTable;

            displayField = cimFeatureTable.DisplayField;

            return(displayField);
        }
        // Set range for feature layer
        // Map Exploration Team Routine
        private Task SetRangeProperties(FeatureLayer ftrLyr, string fieldName, bool hasCustomRange = false, double customMin = 0, double customMax = 1, bool inSingleValueMode = false, int rangeStepCount = 0)
        {
            return(QueuedTask.Run(() =>
            {
                //Get min/max values for the field
                double minValue = 0;
                double maxValue = 0;

                //Calculate min/max if custom range is not defined
                if (!hasCustomRange)
                {
                    int ftrCount = 0;
                    RowCursor rows = ftrLyr.Search(null);
                    while (rows.MoveNext())
                    {
                        ftrCount++;
                    }
                    double[] fieldVals = new double[ftrCount];
                    rows = ftrLyr.Search(null);
                    //Looping through to count
                    int i = 0;
                    while (rows.MoveNext())
                    {
                        using (var currentRow = rows.Current)
                        {
                            object origVal = currentRow.GetOriginalValue(rows.FindField(fieldName));
                            if (!(origVal is DBNull))
                            {
                                fieldVals[i] = System.Convert.ToDouble(origVal);
                            }
                            i++;
                        }
                    }
                    if (fieldVals.Count() > 0)
                    {
                        minValue = fieldVals.Min();
                        maxValue = fieldVals.Max();
                    }
                }
                else
                {
                    minValue = customMin;
                    maxValue = customMax;
                }

                CIMBasicFeatureLayer baseLyr = (CIMBasicFeatureLayer)ftrLyr.GetDefinition();
                CIMFeatureTable ftrTable = baseLyr.FeatureTable;

                //CIMRange theRange = new CIMRange();
                CIMRangeDefinition[] rangeDefn = new CIMRangeDefinition[1];
                rangeDefn[0] = new CIMRangeDefinition();
                rangeDefn[0].FieldName = fieldName;
                rangeDefn[0].Name = fieldName;
                rangeDefn[0].CustomFullExtent = new CIMRange();
                rangeDefn[0].CustomFullExtent.Min = minValue;
                rangeDefn[0].CustomFullExtent.Max = maxValue;

                //Set current range with either step count == 1 OR for some cases with step count == 0
                rangeDefn[0].CurrentRange = new CIMRange();
                rangeDefn[0].CurrentRange.Min = minValue;
                //rangeDefn[0].CurrentRange.Max = (rangeStepCount == 1) ? minValue + 1 : minValue;

                //set range step to 0 if in single value mode and to rangeStepCount otherwise
                rangeDefn[0].CurrentRange.Max = (inSingleValueMode) ? minValue : minValue + rangeStepCount;
                //rangeDefn[0].CurrentRange.Max = maxValue;

                ftrTable.RangeDefinitions = rangeDefn;
                ftrTable.ActiveRangeName = fieldName;
                baseLyr.FeatureTable = ftrTable;
                ftrLyr.SetDefinition(baseLyr);
            }));
        }