AnsweredAssumed Answered

Text Annotation displaying problem

Question asked by tkoka3 on Nov 21, 2018
Latest reply on Dec 3, 2018 by cmacleod-esristaff

Hi,

We are develope commands for arcgis pro sdk 2.2 version.We have developed the "Intermediate distance writing " tool.Tool lines are feature class, distance string is the annotation .But annotation (distance string) when I create new one store annotation correctly in  table but  not shown stable in map. When create a new sometimes when I use zoom in/out (change scale), some annotations or all annotations don not display.When I create a new one sometimes all the annotations appear.  Here is the Pictures and Codes below. How can I solve this problem ? Could this problem be a bug?

Pictures:

annotation1

annotation2

 

Codes:

 

#region VARIABLES
private BaseBL baseBL = new BaseBL();
private AnnotationBL annotationBL = new AnnotationBL();
private Layer planlamaAlaniLayer;
private FeatureLayer araMesafeLineLayer;
private AnnotationLayer araMesafeLayer;
private Polyline polyline;
private Polyline annotationPolyline;
private MapPoint centerPoint;
private PolylineBuilder polylineBuilder;
private List<Segment> segmentList;
private double distance;
private double mesafe;
private double size;
private int clickCount;
private string planlamaAlaniID;
private string methodBilgi;
private RowCursor cursor;
private AnnotationFeature annoFeature;
#endregion VARIABLES

 

 

#region CONSTRUCTOR
public AraMesafeYazMapTool()
{
IsSketchTool = true;
SketchType = SketchGeometryType.Line;
SketchOutputMode = SketchOutputMode.Map;
UseSnapping = true;
}
#endregion CONSTRUCTOR

 

 

protected override Task<bool> OnSketchCompleteAsync(Geometry geometry)
{

 

if (clickCount != 2)
return Task.FromResult(false);

return QueuedTask.Run(() =>
{
try
{
if (!KatmanKontrol())
return false;

 

 

#region CREATING LINE FEATURES 

 

geometry = GeometryEngine.Instance.Project(geometry, this.araMesafeLayer.GetSpatialReference());
polyline = geometry as Polyline;
if (polyline != null)
{
this.planlamaAlaniID = Library.GetPlanlamaAlaniID(this.planlamaAlaniLayer, polyline);
if (this.planlamaAlaniID == null)
return false;

this.mesafe = polyline.Length;

this.centerPoint = GeometryEngine.Instance.Centroid(polyline);
this.annotationPolyline = GeometryEngine.Instance.Rotate(polyline, GeometryEngine.Instance.Centroid(polyline), Math.PI / 2) as Polyline;

polylineBuilder = new PolylineBuilder(polyline);
distance = polyline.Length / 2;
if (distance <= 5)
distance = distance - polyline.Length / 8;
else
distance = distance - 2;
polylineBuilder.SplitAtDistance(distance, false);

distance = polyline.Length / 2;
if (distance <= 5)
distance = distance + polyline.Length / 8;
else
distance = distance + 2;
polylineBuilder.SplitAtDistance(distance, false);
segmentList = GeometryUtil.GetSegment(polylineBuilder.ToGeometry());

if (segmentList.Count != 3)
return false;

segmentList.RemoveAt(1);

polyline = GeometryEngine.Instance.Union(PolylineBuilder.CreatePolyline(segmentList.FirstOrDefault()), PolylineBuilder.CreatePolyline(segmentList.LastOrDefault())) as Polyline;
if (!baseBL.InsertBaseFeature(MapView.Active, baseBL.CreateBaseFeatureEntity(polyline, null, this.araMesafeLineLayer, this.planlamaAlaniID, ref this.methodBilgi), ref this.methodBilgi, "Ara mesafe yaz - Çizgi ekleme"))
{
Library.MesajHata(methodBilgi);
return false;
}

if (mesafe >= 20)
size = 0.1;
else
size = mesafe * 0.1 / 20;

 

#endregion CREATING LINE FEATURES 

 

 #region CREATING  DİSTANCE ANNOTATİON

 

var fc = this.araMesafeLayer.GetFeatureClass() as AnnotationFeatureClass;
if (fc == null)
return false;


EditOperation editOperation = new EditOperation();
editOperation.Name = "Mesafe Sembölü";
editOperation.SelectNewFeatures = false;

 


var cimDefinition = fc.GetDefinition() as AnnotationFeatureClassDefinition;
var labels = cimDefinition.GetLabelClassCollection();
var symbols = cimDefinition.GetSymbolCollection();

if ((labels.Count == 0) || (symbols.Count == 0))

return false;

var label = labels[0];
if (labels.Count > 1)
{
foreach (var LabelClass in labels)
{
if (LabelClass.Name == CurrentTemplate.Name)
{
label = LabelClass;
break;
}
}
}

var symbolName = label.TextSymbol.SymbolName;
int symbolID = -1;
if (!int.TryParse(symbolName, out symbolID))
{
foreach (var symbol in symbols)
{
if (symbol.Name == symbolName)
{
symbolID = symbol.ID;
break;
}
}
}

if (symbolID == -1)
return false;

Dictionary<string, object> values = new Dictionary<string, object>();
values.Add("SymbolID", symbolID);
values.Add("AnnotationClassID", label.ID);

int idxField = cimDefinition.FindField("TextString");

values.Add("TextString", this.mesafe.ToString("0.##"));


values["SHAPE"] = this.annotationPolyline as Geometry;

long newFeatureID = -1;
editOperation.Create(this.araMesafeLayer as Layer, values, oid => newFeatureID = oid);
bool opResult = editOperation.Execute();
if (opResult)
{
var chainedOp = editOperation.CreateChainedOperation();
chainedOp.Callback(context =>
{
QueryFilter qf = new QueryFilter();
qf.WhereClause = BaseFeatureEntity.objectIdFieldName + "=" + newFeatureID.ToString();
cursor = fc.Search(qf, false);
cursor.MoveNext();

if (cursor.Current != null)
{
annoFeature = cursor.Current as AnnotationFeature;

if (annoFeature != null)
{

var textGraphic = annoFeature.GetGraphic() as CIMTextGraphic;
if (textGraphic != null)
{
var symbol = textGraphic.Symbol.Symbol;
symbol.SetColor(ColorFactory.Instance.BlackRGB);
var cimTextSymbol = symbol as CIMTextSymbol;
cimTextSymbol.HorizontalAlignment = ArcGIS.Core.CIM.HorizontalAlignment.Center;
cimTextSymbol.VerticalAlignment = ArcGIS.Core.CIM.VerticalAlignment.Center;
cimTextSymbol.SetSize(this.size);

textGraphic.Text = this.mesafe.ToString("0.##");

annoFeature.SetGraphic(textGraphic);
annoFeature.Store();
context.Invalidate(annoFeature);
}
}
}
}, fc);

chainedOp.Execute();
}

 

#endregion CREATING  DİSTANCE ANNOTATİON

 

}
}
catch (Exception ex)
{
Library.MesajHata(ex.ToString());
}
finally
{
if (cursor != null)
cursor.Dispose();

if (annoFeature != null)
annoFeature.Dispose();

 

clickCount = 0;
}
return true;
});
}

 

Sample codes we take for reference, Narelle Chedzey suggested codes:

How can I create Text Anntation with given FontSize and Alignment ?  

 

Thanks For Helping

Outcomes