How to ensure that the OnToolMouseDown event is not triggered during OnToolDoubleClick?

357
0
07-18-2022 11:24 PM
DavidMrázek
Occasional Contributor II

Hi,
does anyone know how to ensure that the OnToolMouseDown event is not triggered during OnToolDoubleClick.

My code looks like this:

private string strana;
        private long oid;
        private Geometry shape;
        public PresunAnotaciPodelRamu()
        {
            IsSketchTool = true;
            SketchType = SketchGeometryType.Point;
            SketchOutputMode = SketchOutputMode.Map;
        }
        protected override void OnToolDoubleClick(MapViewMouseButtonEventArgs e)
        {
            FrameworkApplication.SetCurrentToolAsync(null);
            base.OnToolDoubleClick(e);
        }

        private AnnotationLayer AlBodyAnno(string bodyAnno)
        {

            MapView mapView = MapView.Active;
            AnnotationLayer alBodyAnno = mapView.Map.FindLayers(bodyAnno).FirstOrDefault() as AnnotationLayer;
            if (alBodyAnno == null)
            {
                MessageBox.Show(@"Neexistuje.");
                return null;
            }
            return alBodyAnno;
        }

        private Inspector Insp()
        {
            var insp = new Inspector();
            return insp;
        }
        private EditOperation Editace()
        {
            var editace = new EditOperation
            {
                Name = "Posun anotace",
                SelectNewFeatures = false
            };
            return editace;
        }

        private QueryFilter Filter(long oid)
        {
            var filter = new QueryFilter
            {
                WhereClause = " OBJECTID = " + oid
            };
            return filter;
        }

        private Form Formular()
        {
            Form form1 = new Form();
            form1.Text = "Upozornění";
            form1.StartPosition = FormStartPosition.CenterScreen;
            var label = new Label() { Text = "Nebyla zvolena anotace!",AutoSize = true, Location = new Point(15, 15) };
            form1.Controls.Add(label);
            form1.Size = new Size(300, 85);
            return form1;
        }

        private Selection AnotaceZvolena(AnnotationLayer alBodyAnno, QueryFilter filter)
        {
            var anotaceZvolena = alBodyAnno.Select(filter);
            return anotaceZvolena;
        }
        protected async override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
        {
            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)
                    {
                        var form1 = Formular();
                        form1.ShowDialog();
                        //The form always starts when no annotation is selected. But I would like it to start only with one press.
                        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;
                });
            }
        }

The form always starts when no annotation is selected. But I would like it to start only with one press.

I don't know whether to set some condition or there is some other way.

Thanks in advance for the answers

David

0 Kudos
0 Replies