コード例 #1
0
 private ArcmapPick LazyLoadPickTool()
 {
     if (_pick == null)
     {
         _pick = new ArcmapPick(_pickLayers, ArcmapUtils.GetFocusMap(), 10);
     }
     return(_pick);
 }
コード例 #2
0
 /// <summary>
 /// This event is called, when the ArcMap tool is activated.
 /// </summary>
 protected override void OnActivate()
 {
     try
     {
         _pickLayers = ArcmapLayerUtils.EnumerateLayers(ArcmapUtils.GetFocusMap(), false).ToList();
     }
     catch (Exception)
     {
         // Don't let the exeption escape to arcgis.
     }
 }
コード例 #3
0
        private List <WorkspaceInfoViewModel> LoadWorkspaceInfosFromArcMap()
        {
            var result = new List <WorkspaceInfoViewModel>();

            var workspaces = ArcmapUtils.EnumerateAllWorkspaces(Ioc.GetOrCreate <IApplication>());

            foreach (IWorkspace workspace in workspaces)
            {
                WorkspaceInfoViewModel info = new WorkspaceInfoViewModel();
                info.Path = workspace.PathName;
                info.Name = Path.GetFileNameWithoutExtension(info.Path);

                ISQLSyntax sqlSyntax = workspace as ISQLSyntax;
                if (sqlSyntax != null)
                {
                    info.StringComparisonCaseSensitive   = sqlSyntax.GetStringComparisonCase();
                    info.IdentifierCaseSensitive         = sqlSyntax.GetIdentifierCase();
                    info.QuotedIdentifierCaseSensitive   = sqlSyntax.GetDelimitedIdentifierCase();
                    info.InvalidCharactersForIdentifiers = sqlSyntax.GetInvalidCharacters();

                    foreach (var enumName in Enum.GetValues(typeof(esriSQLFunctionName)))
                    {
                        string enumValue = sqlSyntax.GetFunctionName((esriSQLFunctionName)enumName);
                        if (string.IsNullOrEmpty(enumValue))
                        {
                            enumValue = NotAvailable;
                        }
                        info.SqlFunctions.AddOrReplace(enumName.ToString(), enumValue);
                    }
                    info.SqlFunctions.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.InvariantCultureIgnoreCase));

                    foreach (var enumName in Enum.GetValues(typeof(esriSQLSpecialCharacters)))
                    {
                        string enumValue = sqlSyntax.GetSpecialCharacter((esriSQLSpecialCharacters)enumName);
                        if (string.IsNullOrEmpty(enumValue))
                        {
                            enumValue = string.Empty;
                        }
                        info.SpecialCharacters.AddOrReplace(enumName.ToString(), enumValue);
                    }
                    info.SpecialCharacters.Sort((x, y) => string.Compare(x.Key, y.Key, StringComparison.InvariantCultureIgnoreCase));

                    foreach (string keyword in sqlSyntax.GetKeywords().Enumerate())
                    {
                        info.ReservedWords.Add(keyword);
                    }
                    info.ReservedWords.Sort(StringComparer.InvariantCultureIgnoreCase);
                }

                result.Add(info);
            }
            return(result);
        }
コード例 #4
0
        public void CreatePropertyChildNodes(TreeviewBranchViewModel parentNode, object comObj, Type typ)
        {
            IEnumDatasetName enumDatasetName = comObj as IEnumDatasetName;

            foreach (IDatasetName value in ArcmapUtils.EnumerateDatasetNames(enumDatasetName, false))
            {
                if ((value != null) && (value.GetType().IsCOMObject))
                {
                    ComObjectViewModel child = new ComObjectViewModel(parentNode, value, typeof(IDatasetName), ".Next()");
                    parentNode.Children.Add(child);
                }
            }
        }
コード例 #5
0
ファイル: LayerSpyViewModel.cs プロジェクト: litcas/ArcmapSpy
        private List <LayerInfoViewModel> LoadLayerInfosFromArcMap()
        {
            List <LayerInfoViewModel> result = new List <LayerInfoViewModel>();

            var layers = ArcmapLayerUtils.EnumerateLayers(ArcmapUtils.GetFocusMap(), false);

            foreach (IFeatureLayer layer in layers)
            {
                LayerInfoViewModel layerInfo = LoadLayerInfoFromArcMap(layer);
                result.Add(layerInfo);
            }
            return(result);
        }
コード例 #6
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());
            }
        }
コード例 #7
0
        /// <summary>
        /// Expands the table of contents in ArcMap to the matching layer and selects it.
        /// </summary>
        private void SelectFeature()
        {
            IFeatureSelection featureSelection;
            IMap map = ArcmapUtils.GetFocusMap();

            foreach (IFeatureLayer featureLayer in ArcmapLayerUtils.EnumerateLayers(map, false))
            {
                featureSelection = featureLayer as IFeatureSelection;
                featureSelection?.Clear();
            }

            featureSelection = _layer as IFeatureSelection;
            featureSelection?.Add(_feature);

            ArcmapUtils.InvalidateMap(map);
        }
コード例 #8
0
 /// <summary>
 /// This event is called, when the user released the mouse button in ArcMap.
 /// </summary>
 /// <param name="arg">Event arguments</param>
 protected override void OnMouseUp(MouseEventArgs arg)
 {
     try
     {
         ArcmapPick          pick            = LazyLoadPickTool();
         ArcmapPickCandidate pickedCandidate = pick.OnMouseUp(arg.X, arg.Y);
         if (pickedCandidate != null)
         {
             ArcmapUtils.FlashFeature(pickedCandidate.Feature, ArcmapUtils.FocusMapToScreenDisplay(pick.FocusMap));
             GeometrySpyViewModel viewModel = new GeometrySpyViewModel(pickedCandidate.Feature);
             GeometrySpyView      form      = new GeometrySpyView();
             form.SetDataContext(viewModel);
             WindowsUtils.MakeModelessDialogParentOf(form, new IntPtr(ArcMap.Application.hWnd));
             form.Show();
         }
     }
     catch (Exception)
     {
         // Don't let the exeption escape to arcgis.
         ResetPickTool();
     }
     ArcmapUtils.InvalidateMap(ArcmapUtils.GetFocusMap());
 }
コード例 #9
0
 /// <summary>
 /// Expands the table of contents in ArcMap to the matching layer and selects it.
 /// </summary>
 private void JumpToLayer()
 {
     ArcmapLayerUtils.ExpandParentLayers(Layer, ArcmapUtils.GetFocusMap());
     ArcmapLayerUtils.SelectLayer(Layer, ArcMap.Application);
 }