Click here to Skip to main content
15,887,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I would like to see the exact displacement of the text when moving the annotation in ArcGIS Pro. That's why I thought of stopping and restarting an Event or individual operation every millisecond, where it would always check the position of the mouse cursor.The point is that I keep the left mouse button pressed to move the text, and when I release the button, the text moves to the last position of the cursor.

What I have tried:

C#
protected async override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
        {var form1 = Formular();
            if (e.ChangedButton == MouseButton.Left)
            {await QueuedTask.Run(() =>
                    {
                        MapView mapView = MapView.Active;
                        mapView.Map.SetSelection(null);
                        const string bodyAnno = "BodyAnno";
                        var alBodyAnno = AlBodyAnno(bodyAnno);
                        var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
                        var features = mapView.GetFeatures(mapPoint);
                        if (features.ContainsKey(alBodyAnno))
                        {
                            var thisTag = features.FirstOrDefault(t => t.Key == alBodyAnno);
                            var oidSeznam = thisTag.Value;
                            foreach (var longOid in oidSeznam)
                            {
                                oid = longOid;
                            }

                            var filter = Filter(oid);
                            var anotaceHledana = alBodyAnno.Search(filter);
                            while (anotaceHledana.MoveNext())
                            {
                                var aktual = anotaceHledana.Current;
                                strana = aktual["STRANA"].ToString();
                            }

                            AnotaceZvolena(alBodyAnno, filter);
                        }

                        var insp = Insp();
                        insp.Load(alBodyAnno, oid);
                        AnnotationProperties annoProperties = insp.GetAnnotationProperties();
                        shape = annoProperties.Shape;
                        if (shape == null)
                        {
                           
                            form1.ShowDialog();
                            //MessageBox.Show("Nebyla zvolena anotace!");
                            return;
                        }
                    });
                }
 }
}

 protected async override void OnToolMouseUp(MapViewMouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
            {
                await QueuedTask.Run(() =>
                {
                    var insp = Insp();
                    const string bodyAnno = "BodyAnno";
                    var alBodyAnno = AlBodyAnno(bodyAnno);
                    insp.Load(alBodyAnno, oid);
                    AnnotationProperties annoProperties = insp.GetAnnotationProperties();
                    var editace = Editace();
                    if (shape == null)
                    {
                        return;
                    }
                    var envelope = shape.Extent;
                    var mapPointCentroid = GeometryEngine.Instance.Centroid(envelope);
                    double souradniceStrduX = mapPointCentroid.X;
                    double souradniceStreduY = mapPointCentroid.Y;
                    if (strana == "horni" || strana == "dolni")
                    {
                        if (shape.GeometryType != GeometryType.GeometryBag)
                        {
                            var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
                            var souradniceX = mapPoint.X;
                            var x = souradniceX - souradniceStrduX;
                            var posun = GeometryEngine.Instance.Move(shape, x, 0);
                            annoProperties.Shape = posun;
                        }
                    }
                    else
                    {
                        if (shape.GeometryType != GeometryType.GeometryBag)
                        {
                            var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
                            var souradniceY = mapPoint.Y;
                            var y = souradniceY - souradniceStreduY;
                            var posun = GeometryEngine.Instance.Move(shape, 0, y);
                            annoProperties.Shape = posun;
                        }
                    }
                    insp.SetAnnotationProperties(annoProperties);
                    editace.Modify(insp);
                    editace.Execute();
                    oid = 0;
                });
            }
        }

This is how the complete code looks like to move to the final position without seeing the moved text.

And somewhere, I would like to set the OnToolMouseDown Event so that it always checks the position, for example, every millisecond and writes it down so that it can be seen how it moves.

Is there any such option to check cursor position every millisecond?

Thanks for the advice and tips.

David
Posted
Updated 21-Jul-22 20:59pm
Comments
Richard MacCutchan 20-Jul-22 3:12am    
The point about an event driven system is that you can rely on the events providing all the information necessary to run your application. If you try to work outside the system you will most likely have a poorly working system. And trying to capture something on a millisecond timer is not reliable in a non-real-time operating system.
dejf111 20-Jul-22 3:25am    
And is there any other way to set up tracking of moving text?
Richard MacCutchan 20-Jul-22 3:47am    
dejf111 20-Jul-22 7:57am    
Thank you for the advice.
Maciej Los 20-Jul-22 6:59am    
If i'm not wrong, you should use OnToolMouseMove(MapViewMouseEventArgs e) event with _trackingMouseMove = TrackingState.TrackingMove

1 solution

If i'm not wrong, you should use OnToolMouseMove(MapViewMouseEventArgs e) event with _trackingMouseMove = TrackingState.TrackingMove

More: MouseMove Event - ArcGIS Resources[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900