private ArcmapPick LazyLoadPickTool() { if (_pick == null) { _pick = new ArcmapPick(_pickLayers, ArcmapUtils.GetFocusMap(), 10); } return(_pick); }
/// <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. } }
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); }
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); } } }
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); }
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()); } }
/// <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); }
/// <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()); }
/// <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); }