Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FeatureSpyViewModel"/>.
        /// <param name="feature">The feature to represent.</param>
        /// <param name="layer">The layer from which the feature originated.</param>
        /// </summary>
        public FeatureSpyViewModel(IFeature feature, ILayer layer)
        {
            _feature             = feature;
            _layer               = layer;
            ColumnValues         = new List <ColumnInfoViewModel>();
            JumpToLayerCommand   = new RelayCommand(JumpToLayer);
            SelectFeatureCommand = new RelayCommand(SelectFeature);

            // Analyse the feature
            if (feature != null)
            {
                WorkspaceName = ArcobjWorkspaceUtils.GetWorkspaceName(_feature);
                TableName     = ArcobjWorkspaceUtils.GetTableName(_feature.Table);
                ObjectId      = _feature.OID;
                object globalId = ArcobjWorkspaceUtils.GetIdFromRow(_feature, true);
                if (globalId is string)
                {
                    GlobalId = globalId.ToString();
                }
                else
                {
                    GlobalId = string.Empty;
                }
                FillColumnValues(ColumnValues, _feature);
            }
            if (_layer != null)
            {
                LayerName = _layer.Name;
            }
        }
Example #2
0
        private static LayerInfoViewModel LoadLayerInfoFromArcMap(IFeatureLayer layer)
        {
            // tablename
            IDataset dataset   = (IDataset)layer.FeatureClass;
            string   tableName = ArcobjWorkspaceUtils.GetTableName(dataset);

            IFeatureLayerDefinition layerDefinition = layer as IFeatureLayerDefinition;
            string filter = layerDefinition?.DefinitionExpression;

            int?[] rowCounts =
            {
                ArcmapLayerUtils.GetFilteredLayerRowCount(layer),
                ArcmapLayerUtils.GetLayerRowCount(layer)
            };

            return(new LayerInfoViewModel
            {
                Title = layer.Name,
                Layer = layer,
                TableName = tableName,
                Filter = filter,
                RowCount = string.Join(" / ", rowCounts.Where(item => item != null)),
            });
        }
Example #3
0
        private void CreateLabels()
        {
            if (Layer is IGeoFeatureLayer geoFeatureLayer)
            {
                const double TextSizePt        = 9.0;
                const double GoodLookingScale  = 500.0;
                double       referenceScale    = ArcmapUtils.GetReferenceScale(GoodLookingScale);
                string       tableName         = ArcobjWorkspaceUtils.UnqualifyTableName(ArcobjWorkspaceUtils.GetTableName(geoFeatureLayer.FeatureClass as IDataset));
                string       oidFieldName      = geoFeatureLayer.FeatureClass.OIDFieldName;
                string       globalIdFieldName = ArcobjWorkspaceUtils.GetGlobalIdFieldName(geoFeatureLayer.FeatureClass as ITable);
                string       expression        = FormatLabelExpression(tableName, oidFieldName, globalIdFieldName);

                ITextSymbol textSymbol = new TextSymbolClass();
                textSymbol.Color = ArcmapLayerUtils.DetectLayerMainColor(geoFeatureLayer);
                textSymbol.Size  = TextSizePt / referenceScale * GoodLookingScale;

                // Remove existing annotations
                geoFeatureLayer.DisplayAnnotation = false;
                geoFeatureLayer.AnnotationProperties.Clear();

                IAnnotateLayerProperties annotateLayerProperties = new LabelEngineLayerPropertiesClass();
                annotateLayerProperties.UseOutput              = true;
                annotateLayerProperties.LabelWhichFeatures     = esriLabelWhichFeatures.esriVisibleFeatures;
                annotateLayerProperties.CreateUnplacedElements = true;

                ILabelEngineLayerProperties2 labelEngineProperties = (ILabelEngineLayerProperties2)annotateLayerProperties;
                labelEngineProperties.ExpressionParser = new AnnotationVBScriptEngineClass();
                labelEngineProperties.Expression       = expression;
                labelEngineProperties.Symbol           = textSymbol;

                IBasicOverposterLayerProperties overposterProperties = labelEngineProperties.BasicOverposterLayerProperties;
                overposterProperties.GenerateUnplacedLabels = true;
                overposterProperties.NumLabelsOption        = esriBasicNumLabelsOption.esriOneLabelPerShape;
                overposterProperties.PointPlacementOnTop    = true;
                overposterProperties.PointPlacementMethod   = esriOverposterPointPlacementMethod.esriSpecifiedAngles;
                overposterProperties.PointPlacementAngles   = new[] { 30.0 };
                overposterProperties.LineLabelPosition      = CreateLineLabelPosition();

                if (labelEngineProperties.OverposterLayerProperties is IOverposterLayerProperties2 overposterProperties2)
                {
                    overposterProperties2.TagUnplaced = false; // The "place overlapping labels" option
                }
                // Show new annotation in map
                geoFeatureLayer.AnnotationProperties.Add(annotateLayerProperties);
                geoFeatureLayer.DisplayAnnotation = true;
                ArcmapUtils.InvalidateMap(ArcmapUtils.GetFocusMap());
            }
        }