コード例 #1
0
ファイル: IS3View2D.cs プロジェクト: flyong/iS3-Transplant
        //public async void drawToolsClickEventListener(object sender,
        //    UserControl.DrawToolClickEventArgs args)
        //{
        //    if (args.stopDraw)
        //    {
        //        if (_mapView.Editor.Cancel.CanExecute(null))
        //            _mapView.Editor.Cancel.Execute(null);
        //    }
        //    else
        //    {
        //        await drawGraphics(args.drawShapeType);
        //    }
        //}

        public async Task drawGraphics(DrawShapeType drawShapeType)
        {
            if (Globals.isThreadUnsafe())
            {
                await Globals.application.Dispatcher.Invoke(new Func <Task>(async() =>
                {
                    await drawGraphics(drawShapeType);
                }));

                return;
            }

            // Add a drawing graphics layer
            if (_drawingLayer == null)
            {
                _drawingLayer             = new IS3GraphicsLayer();
                _drawingLayer.ID          = "0";
                _drawingLayer.DisplayName = "0";
                _map.Layers.Add(_drawingLayer);
            }

            if (_mapView.Editor.IsActive)
            {
                return;
            }

            try
            {
                Geometry geom = await _mapView.Editor.RequestShapeAsync((DrawShape)drawShapeType);

                if (_srEMap != null)
                {
                    geom = GeometryEngine.Project(geom, _srEMap);
                }
                IGeometry iGeom = IS3GeometryEngine.fromGeometry(geom);
                IGraphic  g     = Runtime.graphicEngine.newGraphic(iGeom);
                GraphicsUtil.AssignDefaultDrawingSymbol(g);

                _drawingLayer.graphics.Add(g);

                // trigger a drawing graphics changed event
                if (drawingGraphicsChangedTrigger != null)
                {
                    DrawingGraphicsChangedEventArgs args =
                        new DrawingGraphicsChangedEventArgs();
                    List <IGraphic> addedItems = new List <IGraphic>();
                    addedItems.Add(g);
                    args.addedItems = addedItems;
                    drawingGraphicsChangedTrigger(this, args);
                }
            }
            catch (TaskCanceledException)
            {
                // Ignore TaskCanceledException - usually happens if the editor gets cancelled or restarted
            }
        }