Welcome Guest, you are in: Login

FDOT Wiki

RSS RSS

GisFramework



Search the wiki
»

DrawCommand

public class DrawCommand : ScriptableCommand<DrawCommandParameters>
    {

        /// <summary>
        /// A string identifier for this command.
        /// </summary>
        public override string CommandVerb
        {
            get { return "draw"; }
        }

        /// <summary>
        /// Executes the command with the specified <see cref="DrawCommandParameters"/>.
        /// </summary>
        /// <param name="parameters"></param>
        public override sealed void Execute(DrawCommandParameters parameters)
        {
            var executionContext = new ActionExecutionContext();
            Coroutine.BeginExecute(GetWorkflow(parameters).GetEnumerator(), executionContext, Complete);
        }

        private void Complete(object sender, ResultCompletionEventArgs e)
        {
            if (e.Error != null)
                Failure(e.Error);
            else
                Success(null);
        }

        protected IEnumerable<IResult> GetWorkflow(DrawCommandParameters parameters)
        {
            if (!IsInitialized) throw new Exception("Command not initiaized.");

            if (parameters.DoClearFirst)
            {
                ClearGraphics();
            }

            if (parameters.DrawingObjects != null && parameters.DrawingObjects.Length > 0)
            {
                var symbol = SymbolManager.GetMarkerSymbol(parameters.SymbolType, parameters.SymbolFillColor, parameters.SymbolStrokeColor);
                yield return new DrawGeometry(parameters.GeometryObjects, GraphicsManager, parameters.HueShift, symbol);

                if (parameters.DoPan || parameters.DoZoom)
                {
                    yield return new ZoomToGeometry(GeometryHelper.GetViewableArea(parameters.Envelope, parameters.DoPan, parameters.DoZoom), parameters.Buffer);
                }
            }
        }
    }

DrawCommandParameters

    public class DrawCommandParameters
    {
        public DataContracts.Geometry[] DrawingObjects { get; set; }
        public bool DoClearFirst { get; set; }
        public bool DoShowLabels { get; set; }
        public bool DoPan { get; set; }
        public bool DoZoom { get; set; }
        public double HueShift { get; set; }
        public string SymbolType { get; set; }
        public string SymbolFillColor { get; set; }
        public string SymbolStrokeColor { get; set; }
        public double Buffer { get; set; }

        private DataContracts.Geometry[] _geometryObjects = null;
        internal DataContracts.Geometry[] GeometryObjects
        {
            get
            {
                if (_geometryObjects == null)
                {
                    foreach (DataContracts.Geometry g in DrawingObjects)
                    {
                        if (g.Radius != null && g.X != null && g.Y != null)
                        {
                            double[][] ring = CreateRing(new Point(g.X.Value, g.Y.Value), g.Radius.Value);
                            g.Rings = new double[][][] { ring };
                            g.X = null;
                            g.Y = null;
                        }
                        _geometryObjects = (DataContracts.Geometry[])DrawingObjects;
                    }
                }
                return _geometryObjects;
            }
        }

        private Envelope _envelope = null;
        internal Envelope Envelope
        {
            get
            {
                if (_envelope == null)
                { _envelope = GeometryHelper.GetEnvelope(GeometryObjects); }
                return _envelope;
            }
        }

        #region create a ring from an origin and radius
        private double[][] CreateRing(Point origin, double radius)
        {
            List<double[]> points = new List<double[]>();

            for (double i = 0d; i < 360d; i++)
            {
                double angle = i * (Math.PI / 180d);

                points.Add(new double[] 
                    {
                        origin.X + radius * Math.Cos(angle), 
                        origin.Y + radius * Math.Sin(angle) 
                    });
            }
            return points.ToArray();
        }
        #endregion
    }

See Also

Any Questions or Comments? Email
Some of the icons created by FamFamFam.