Select to view content in your preferred language

Text Annotation displaying problem

1538
5
11-21-2018 04:25 AM
tanerkoka
Frequent Contributor

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

0 Kudos
5 Replies
tanerkoka
Frequent Contributor

Hi,

İs there any progress in the question above ?

Thanks for helping

0 Kudos
by Anonymous User
Not applicable

Hi,

In future try to put your code inside the syntax highlighter (expand the toolbar, choose more then 'syntax highlighter) to make the code easier to read.

One thing to try is to invalidate the row in the callback both before and after the changes. Place an additional "context.Invalidate(annoFeature);" before the textgraphic and symbol changes in the callback.

At 2.3 creating an editing annotation becomes easier as its more integrated into the edit operation and inspector so you wont need the callback or a chained operation.

0 Kudos
tanerkoka
Frequent Contributor

Hi,

I've added the line in the code above with the bold font, but nothing has changed. Do I have to add or remove anything in the code ? Can you help me ?Here is code below:

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;
context.Invalidate(annoFeature);

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();
}

Thanks for Helping

0 Kudos
tanerkoka
Frequent Contributor

Hi,

Is there any improvement in the above question?  Is it a bug? Because our customers waiting for this.

Thanks

0 Kudos
CharlesMacleod
Esri Regular Contributor

I cannot reproduce your issue in either 2.2 or our next release (not yet available) 2.3. The placement of your context.Invalidate statements are correct.

Please work with ESRI tech support to resolve your issue. They will most likely need a copy of your data as well. 

0 Kudos