예제 #1
0
        /// <summary>
        /// Draws the point symbol in the view
        /// </summary>
        /// <param name="g"></param>
        /// <param name="clip"></param>
        protected virtual void OnDraw(Graphics g, Rectangle clip)
        {
            if (_borderStyle == BorderStyle.Fixed3D)
            {
                g.DrawLine(Pens.White, 0, Height - 1, Width - 1, Height - 1);
                g.DrawLine(Pens.White, Width - 1, 0, Width - 1, Height - 1);
                g.DrawLine(Pens.Gray, 0, 0, 0, Height - 1);
                g.DrawLine(Pens.Gray, 0, 0, Width - 1, 0);
            }
            if (_borderStyle == BorderStyle.FixedSingle)
            {
                g.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
            }

            if (_symbolizer == null)
            {
                return;
            }
            Size2D size = _symbolizer.GetSize();
            int    w    = (int)size.Width;
            int    h    = (int)size.Height;

            if (w < 1 || h < 1)
            {
                return;
            }
            Rectangle symbolBounds = new Rectangle(Width / 2 - w / 2, Height / 2 - h / 2, w, h);

            if (!symbolBounds.IntersectsWith(clip))
            {
                return;
            }
            _symbolizer.Draw(g, symbolBounds);
        }
예제 #2
0
        /// <summary>
        /// Draws a point at the given location.
        /// </summary>
        /// <param name="ptX">X-Coordinate of the point, that should be drawn.</param>
        /// <param name="ptY">Y-Coordinate of the point, that should be drawn.</param>
        /// <param name="e">MapArgs for calculating the scaleSize.</param>
        /// <param name="ps">PointSymbolizer with which the point gets drawn.</param>
        /// <param name="g">Graphics-Object that should be used by the PointSymbolizer.</param>
        /// <param name="origTransform">The original transformation that is used to position the point.</param>
        private void DrawPoint(double ptX, double ptY, MapArgs e, IPointSymbolizer ps, Graphics g, Matrix origTransform)
        {
            var    x         = Convert.ToInt32((ptX - e.MinX) * e.Dx);
            var    y         = Convert.ToInt32((e.MaxY - ptY) * e.Dy);
            double scaleSize = ps.GetScale(e);
            Matrix shift     = origTransform.Clone();

            shift.Translate(x, y);
            g.Transform = shift;
            ps.Draw(g, scaleSize);
        }
예제 #3
0
        /// <summary>
        /// Draws a point at the given location.
        /// </summary>
        /// <param name="ptX">X-Coordinate of the point, that should be drawn.</param>
        /// <param name="ptY">Y-Coordinate of the point, that should be drawn.</param>
        /// <param name="e">MapArgs for calculating the scaleSize.</param>
        /// <param name="ps">PointSymbolizer with which the point gets drawn.</param>
        /// <param name="g">Graphics-Object that should be used by the PointSymbolizer.</param>
        /// <param name="origTransform">The original transformation that is used to position the point.</param>
        private void DrawPoint(double ptX, double ptY, MapArgs e, IPointSymbolizer ps, Graphics g, Matrix origTransform)
        {
            var pt = new Point
            {
                X = Convert.ToInt32((ptX - e.MinX) * e.Dx),
                Y = Convert.ToInt32((e.MaxY - ptY) * e.Dy)
            };
            double scaleSize = ps.ScaleMode == ScaleMode.Geographic ? e.ImageRectangle.Width / e.GeographicExtents.Width : 1;
            Matrix shift     = origTransform.Clone();

            shift.Translate(pt.X, pt.Y);
            g.Transform = shift;
            ps.Draw(g, scaleSize);
        }
예제 #4
0
        /// <summary>
        /// Draws a point at the given location.
        /// </summary>
        /// <param name="ptX">X-Coordinate of the point, that should be drawn.</param>
        /// <param name="ptY">Y-Coordinate of the point, that should be drawn.</param>
        /// <param name="e">MapArgs for calculating the scaleSize.</param>
        /// <param name="ps">PointSymbolizer with which the point gets drawn.</param>
        /// <param name="g">Graphics-Object that should be used by the PointSymbolizer.</param>
        /// <param name="origTransform">The original transformation that is used to position the point.</param>
        /// <param name="clockwiseAngle">clockwiseAngle.</param>
        private void DrawPoint(double ptX, double ptY, MapArgs e, IPointSymbolizer ps, Graphics g, Matrix origTransform, float clockwiseAngle)
        {
            var pt = new PointF
            {
                X = Convert.ToSingle((ptX - e.MinX) * e.Dx),
                Y = Convert.ToSingle((e.MaxY - ptY) * e.Dy)
            };
            double scaleSize = ps.GetScale(e);
            Matrix shift     = origTransform.Clone();

            shift.Translate(pt.X, pt.Y);
            shift.Rotate(clockwiseAngle);
            g.Transform = shift;
            ps.Draw(g, scaleSize);
        }
예제 #5
0
        private void UpdatePreview(Graphics g)
        {
            if (_symbolizer == null)
            {
                return;
            }
            g.Clear(Color.White);
            Matrix shift = g.Transform;

            shift.Translate((float)lblPreview.Width / 2, (float)lblPreview.Height / 2);
            g.Transform = shift;
            double scale      = 1;
            Size2D symbolSize = _symbolizer.GetSize();

            if (_symbolizer.ScaleMode == ScaleMode.Geographic || symbolSize.Height > (lblPreview.Height - 6))
            {
                scale = (lblPreview.Height - 6) / symbolSize.Height;
            }

            _symbolizer.Draw(g, scale);
        }
예제 #6
0
        /// <summary>
        /// Draws a point at the given location.
        /// </summary>
        /// <param name="ptX">X-Coordinate of the point, that should be drawn.</param>
        /// <param name="ptY">Y-Coordinate of the point, that should be drawn.</param>
        /// <param name="e">MapArgs for calculating the scaleSize.</param>
        /// <param name="ps">PointSymbolizer with which the point gets drawn.</param>
        /// <param name="g">Graphics-Object that should be used by the PointSymbolizer.</param>
        /// <param name="origTransform">The original transformation that is used to position the point.</param>
        private void DrawPoint(double ptX, double ptY, MapArgs e, IPointSymbolizer ps, Graphics g, Matrix origTransform)
        {
            var pt = new Point
            {
                X = Convert.ToInt32((ptX - e.MinX) * e.Dx),
                Y = Convert.ToInt32((e.MaxY - ptY) * e.Dy)
            };
            double scaleSize = ps.GetScale(e);

            // CGX
            if (MapFrame != null && (MapFrame as IMapFrame).ReferenceScale > 1.0 && (MapFrame as IMapFrame).CurrentScale > 0.0)
            {
                double dReferenceScale = (MapFrame as IMapFrame).ReferenceScale;
                double dCurrentScale   = (MapFrame as IMapFrame).CurrentScale;
                scaleSize = dReferenceScale / dCurrentScale;
            } // Fin CGX

            Matrix shift = origTransform.Clone();

            shift.Translate(pt.X, pt.Y);
            g.Transform = shift;
            ps.Draw(g, scaleSize);
        }
예제 #7
0
        private static Bitmap GetSymbolizerBitmap(IPointSymbolizer symbolizer, IProj e)
        {
            if (symbolizer == null) return null;

            var scaleSize = symbolizer.GetScale(e);
            var size = symbolizer.GetSize();
            if (size.Width * scaleSize < 1 || size.Height * scaleSize < 1) return null;

            var bitmap = new Bitmap((int)(size.Width * scaleSize) + 1, (int)(size.Height * scaleSize) + 1);
            var bg = Graphics.FromImage(bitmap);
            bg.SmoothingMode = symbolizer.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
            var trans = bg.Transform;

            // keenedge:
            // added ' * scaleSize ' to fix a problme when ploted using ScaleMode=Geographic.   however, it still
            // appeared to be shifted up and left by 1 pixel so I also added the one pixel shift to the NW.
            trans.Translate(((float)(size.Width * scaleSize) / 2 - 1), (float)(size.Height * scaleSize) / 2 - 1);
            bg.Transform = trans;
            symbolizer.Draw(bg, 1);

            return bitmap;
        }
예제 #8
0
        // This draws the individual point features
        private void DrawFeatures(MapArgs e, IEnumerable <IFeature> features)
        {
            Graphics g             = e.Device ?? Graphics.FromImage(_backBuffer);
            Matrix   origTransform = g.Transform;
            double   minX          = e.MinX;
            double   maxY          = e.MaxY;
            double   dx            = e.Dx;
            double   dy            = e.Dy;
            IDictionary <IFeature, IDrawnState> states = DrawingFilter.DrawnStates;

            if (states == null)
            {
                return;
            }
            foreach (IPointCategory category in Symbology.Categories)
            {
                foreach (IFeature feature in features)
                {
                    if (states.ContainsKey(feature) == false)
                    {
                        continue;
                    }
                    IDrawnState ds = states[feature];
                    if (ds == null)
                    {
                        continue;
                    }
                    if (!ds.IsVisible)
                    {
                        continue;
                    }
                    if (ds.SchemeCategory == null)
                    {
                        continue;
                    }
                    IPointCategory pc = ds.SchemeCategory as IPointCategory;
                    if (pc == null)
                    {
                        continue;
                    }
                    if (pc != category)
                    {
                        continue;
                    }
                    IPointSymbolizer ps = pc.Symbolizer;
                    if (ds.IsSelected)
                    {
                        ps = pc.SelectionSymbolizer;
                    }
                    if (ps == null)
                    {
                        continue;
                    }
                    g.SmoothingMode = ps.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
                    foreach (Coordinate c in feature.Coordinates)
                    {
                        Point pt = new Point
                        {
                            X = Convert.ToInt32((c.X - minX) * dx),
                            Y = Convert.ToInt32((maxY - c.Y) * dy)
                        };
                        double scaleSize = 1;
                        if (ps.ScaleMode == ScaleMode.Geographic)
                        {
                            scaleSize = e.ImageRectangle.Width / e.GeographicExtents.Width;
                        }
                        Matrix shift = origTransform.Clone();
                        shift.Translate(pt.X, pt.Y);
                        g.Transform = shift;
                        ps.Draw(g, scaleSize);
                    }
                }
            }

            if (e.Device == null)
            {
                g.Dispose();
            }
            else
            {
                g.Transform = origTransform;
            }
        }
예제 #9
0
        // This draws the individual point features
        private void DrawFeatures(MapArgs e, IEnumerable <int> indices)
        {
            Graphics    g             = e.Device ?? Graphics.FromImage(_backBuffer);
            Matrix      origTransform = g.Transform;
            FeatureType featureType   = DataSet.FeatureType;

            double minX = e.MinX;
            double maxY = e.MaxY;
            double dx   = e.Dx;
            double dy   = e.Dy;

            if (!DrawnStatesNeeded)
            {
                if (Symbology == null || Symbology.Categories.Count == 0)
                {
                    return;
                }
                FastDrawnState   state = new FastDrawnState(false, Symbology.Categories[0]);
                IPointCategory   pc    = state.Category as IPointCategory;
                IPointSymbolizer ps    = null;
                if (pc != null && pc.Symbolizer != null)
                {
                    ps = pc.Symbolizer;
                }
                if (ps == null)
                {
                    return;
                }
                g.SmoothingMode = ps.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
                double[] vertices = DataSet.Vertex;
                foreach (int index in indices)
                {
                    if (DrawnStates != null && DrawnStates.Length > index)
                    {
                        if (!DrawnStates[index].Visible)
                        {
                            continue;
                        }
                    }
                    if (featureType == FeatureType.Point)
                    {
                        Point pt = new Point();
                        pt.X = Convert.ToInt32((vertices[index * 2] - minX) * dx);
                        pt.Y = Convert.ToInt32((maxY - vertices[index * 2 + 1]) * dy);
                        double scaleSize = 1;
                        if (ps.ScaleMode == ScaleMode.Geographic)
                        {
                            scaleSize = e.ImageRectangle.Width / e.GeographicExtents.Width;
                        }
                        Matrix shift = origTransform.Clone();
                        shift.Translate(pt.X, pt.Y);
                        g.Transform = shift;
                        ps.Draw(g, scaleSize);
                    }
                    else
                    {
                        // multi-point
                        ShapeRange range = DataSet.ShapeIndices[index];
                        for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                        {
                            Point pt = new Point();
                            pt.X = Convert.ToInt32((vertices[i * 2] - minX) * dx);
                            pt.Y = Convert.ToInt32((maxY - vertices[i * 2 + 1]) * dy);
                            double scaleSize = 1;
                            if (ps.ScaleMode == ScaleMode.Geographic)
                            {
                                scaleSize = e.ImageRectangle.Width / e.GeographicExtents.Width;
                            }
                            Matrix shift = origTransform.Clone();
                            shift.Translate(pt.X, pt.Y);
                            g.Transform = shift;
                            ps.Draw(g, scaleSize);
                        }
                    }
                }
            }
            else
            {
                FastDrawnState[] states   = DrawnStates;
                double[]         vertices = DataSet.Vertex;
                foreach (IPointCategory category in Symbology.Categories)
                {
                    if (category.Symbolizer == null)
                    {
                        continue;
                    }

                    double scaleSize = 1;
                    if (category.Symbolizer.ScaleMode == ScaleMode.Geographic)
                    {
                        scaleSize = e.ImageRectangle.Width / e.GeographicExtents.Width;
                    }
                    Size2D size = category.Symbolizer.GetSize();
                    if (size.Width * scaleSize < 1 || size.Height * scaleSize < 1)
                    {
                        continue;
                    }

                    Bitmap   normalSymbol = new Bitmap((int)(size.Width * scaleSize) + 1, (int)(size.Height * scaleSize) + 1);
                    Graphics bg           = Graphics.FromImage(normalSymbol);
                    bg.SmoothingMode = category.Symbolizer.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
                    Matrix trans = bg.Transform;

                    // keenedge:
                    // added ' * scaleSize ' to fix a problme when ploted using ScaleMode=Geographic.   however, it still
                    // appeared to be shifted up and left by 1 pixel so I also added the one pixel shift to the NW.
                    // trans.Translate((float)size.Width / 2, (float)size.Height / 2);
                    trans.Translate(((float)(size.Width * scaleSize) / 2 - 1), (float)(size.Height * scaleSize) / 2 - 1);
                    bg.Transform = trans;
                    category.Symbolizer.Draw(bg, 1);

                    Size2D selSize = category.SelectionSymbolizer.GetSize();
                    if (selSize.Width * scaleSize < 1 || selSize.Height * scaleSize < 1)
                    {
                        continue;
                    }

                    Bitmap   selectedSymbol = new Bitmap((int)(selSize.Width * scaleSize + 1), (int)(selSize.Height * scaleSize + 1));
                    Graphics sg             = Graphics.FromImage(selectedSymbol);
                    sg.SmoothingMode = category.SelectionSymbolizer.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;
                    Matrix trans2 = sg.Transform;
                    trans2.Translate((float)selSize.Width / 2, (float)selSize.Height / 2);
                    sg.Transform = trans2;
                    category.SelectionSymbolizer.Draw(sg, 1);

                    foreach (int index in indices)
                    {
                        FastDrawnState state = states[index];
                        if (!state.Visible)
                        {
                            continue;
                        }
                        if (state.Category == null)
                        {
                            continue;
                        }
                        IPointCategory pc = state.Category as IPointCategory;
                        if (pc == null)
                        {
                            continue;
                        }
                        if (pc != category)
                        {
                            continue;
                        }
                        Bitmap bmp = normalSymbol;
                        if (state.Selected)
                        {
                            bmp = selectedSymbol;
                        }
                        if (featureType == FeatureType.Point)
                        {
                            Point pt = new Point();
                            pt.X = Convert.ToInt32((vertices[index * 2] - minX) * dx);
                            pt.Y = Convert.ToInt32((maxY - vertices[index * 2 + 1]) * dy);

                            Matrix shift = origTransform.Clone();
                            shift.Translate(pt.X, pt.Y);
                            g.Transform = shift;

                            g.DrawImageUnscaled(bmp, -bmp.Width / 2, -bmp.Height / 2);
                        }
                        else
                        {
                            ShapeRange range = DataSet.ShapeIndices[index];
                            for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                            {
                                Point pt = new Point();
                                pt.X = Convert.ToInt32((vertices[i * 2] - minX) * dx);
                                pt.Y = Convert.ToInt32((maxY - vertices[i * 2 + 1]) * dy);

                                Matrix shift = origTransform.Clone();
                                shift.Translate(pt.X, pt.Y);
                                g.Transform = shift;
                                g.DrawImageUnscaled(bmp, -bmp.Width / 2, -bmp.Height / 2);
                            }
                        }
                    }
                }
            }

            if (e.Device == null)
            {
                g.Dispose();
            }
            else
            {
                g.Transform = origTransform;
            }
        }
예제 #10
0
 /// <summary>
 /// Draws a point at the given location.
 /// </summary>
 /// <param name="ptX">X-Coordinate of the point, that should be drawn.</param>
 /// <param name="ptY">Y-Coordinate of the point, that should be drawn.</param>
 /// <param name="e">MapArgs for calculating the scaleSize.</param>
 /// <param name="ps">PointSymbolizer with which the point gets drawn.</param>
 /// <param name="g">Graphics-Object that should be used by the PointSymbolizer.</param>
 /// <param name="origTransform">The original transformation that is used to position the point.</param>
 private void DrawPoint(double ptX, double ptY, MapArgs e, IPointSymbolizer ps, Graphics g, Matrix origTransform)
 {
     var pt = new Point
     {
         X = Convert.ToInt32((ptX - e.MinX) * e.Dx),
         Y = Convert.ToInt32((e.MaxY - ptY) * e.Dy)
     };
     double scaleSize = ps.ScaleMode == ScaleMode.Geographic ? e.ImageRectangle.Width / e.GeographicExtents.Width : 1;
     Matrix shift = origTransform.Clone();
     shift.Translate(pt.X, pt.Y);
     g.Transform = shift;
     ps.Draw(g, scaleSize);
 }
예제 #11
0
        /// <summary>
        /// Given the points on this line decoration, this will cycle through and handle
        /// the drawing as dictated by this decoration.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="path"></param>
        /// <param name="scaleWidth">The double scale width for controling markers</param>
        public void Draw(Graphics g, GraphicsPath path, double scaleWidth)
        {
            if (NumSymbols == 0)
            {
                return;
            }
            GraphicsPathIterator myIterator = new GraphicsPathIterator(path);

            myIterator.Rewind();
            int      start, end;
            bool     isClosed;
            Size2D   symbolSize = _symbol.GetSize();
            Bitmap   symbol     = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height);
            Graphics sg         = Graphics.FromImage(symbol);

            _symbol.Draw(sg, new Rectangle(0, 0, (int)symbolSize.Width, (int)symbolSize.Height));
            sg.Dispose();

            Matrix oldMat = g.Transform;

            PointF[] points;
            if (path.PointCount == 0)
            {
                return;
            }
            try
            {
                points = path.PathPoints;
            }
            catch
            {
                return;
            }


            while (myIterator.NextSubpath(out start, out end, out isClosed) > 0)
            {
                if (NumSymbols == 1)              //single decoration spot
                {
                    if (_percentualPosition == 0) // at start of the line
                    {
                        DrawImage(g, points[start], points[start + 1], points[start], (FlipFirst ^ FlipAll), symbol, oldMat);
                    }
                    else if (_percentualPosition == 100) // at end of the line
                    {
                        DrawImage(g, points[end - 1], points[end], points[end], (FlipFirst ^ FlipAll), symbol, oldMat);
                    }
                    else  //somewhere in between start and end
                    {
                        double totalLength         = GetLength(points, start, end);
                        double span                = totalLength * (double)_percentualPosition / 100;
                        List <DecorationSpot> spot = GetPosition(points, span, start, end);
                        if (spot.Count > 1)
                        {
                            DrawImage(g, spot[1].Before, spot[1].After, spot[1].Position, (FlipFirst ^ FlipAll), symbol, oldMat);
                        }
                    }
                }
                else // more than one decoration spot
                {
                    double totalLength          = GetLength(points, start, end);
                    double span                 = Math.Round(totalLength / (NumSymbols - 1), 4);
                    List <DecorationSpot> spots = GetPosition(points, span, start, end);
                    spots.Add(new DecorationSpot(points[end - 1], points[end], points[end])); //add the missing end point
                    for (int i = 0; i < spots.Count; i++)
                    {
                        DrawImage(g, spots[i].Before, spots[i].After, spots[i].Position, i == 0 ? (FlipFirst ^ FlipAll) : FlipAll, symbol, oldMat);
                    }
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Given the points on this line decoration, this will cycle through and handle
        /// the drawing as dictated by this decoration.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="path"></param>
        /// <param name="scaleWidth">The double scale width for controling markers</param>
        public void Draw(Graphics g, GraphicsPath path, double scaleWidth)
        {
            if (NumSymbols == 0)
            {
                return;
            }
            GraphicsPathIterator myIterator = new GraphicsPathIterator(path);

            myIterator.Rewind();
            int      start, end;
            bool     isClosed;
            Size2D   symbolSize = _symbol.GetSize();
            Bitmap   symbol     = new Bitmap((int)symbolSize.Width, (int)symbolSize.Height);
            Graphics sg         = Graphics.FromImage(symbol);

            _symbol.Draw(sg, new Rectangle(0, 0, (int)symbolSize.Width, (int)symbolSize.Height));
            sg.Dispose();

            Matrix oldMat = g.Transform;

            PointF[] points;
            if (path.PointCount == 0)
            {
                return;
            }
            try
            {
                points = path.PathPoints;
            }
            catch
            {
                return;
            }
            PointF offset;

            int count = 0;

            while (myIterator.NextSubpath(out start, out end, out isClosed) > 0)
            {
                count = count + 1;
                // First marker
                PointF startPoint = points[start];
                PointF stopPoint  = points[start + 1];
                float  angle      = 0F;
                if (_rotateWithLine)
                {
                    angle = GetAngle(startPoint, stopPoint);
                }
                if (FlipFirst && !FlipAll)
                {
                    FlipAngle(ref angle);
                }
                offset     = GetOffset(startPoint, stopPoint);
                startPoint = new PointF(startPoint.X + offset.X, startPoint.Y + offset.Y);
                Matrix rotated = g.Transform;
                rotated.RotateAt(angle, startPoint);
                g.Transform = rotated;
                DrawImage(g, startPoint, symbol);
                g.Transform = oldMat;

                // Second marker
                if (NumSymbols > 1)
                {
                    angle = 0F;
                    if (_rotateWithLine)
                    {
                        angle = GetAngle(points[end - 1], points[end]);
                    }
                    if (FlipAll)
                    {
                        FlipAngle(ref angle);
                    }
                    offset = GetOffset(points[end - 1], points[end]);
                    PointF endPoint = new PointF(points[end].X + offset.X, points[end].Y + offset.Y);
                    rotated = g.Transform;
                    rotated.RotateAt(angle, endPoint);
                    g.Transform = rotated;
                    DrawImage(g, endPoint, symbol);
                    g.Transform = oldMat;
                }
                if (NumSymbols > 2)
                {
                    double totalLength = GetLength(points, start, end);
                    double span        = totalLength / (NumSymbols - 1);
                    for (int i = 1; i < NumSymbols - 1; i++)
                    {
                        DecorationSpot spot = GetPosition(points, span * i, start, end);
                        angle = 0F;
                        if (_rotateWithLine)
                        {
                            angle = GetAngle(spot.Before, spot.After);
                        }
                        offset = GetOffset(spot.Before, spot.After);
                        PointF location = new PointF(spot.Position.X + offset.X, spot.Position.Y + offset.Y);
                        if (FlipAll)
                        {
                            FlipAngle(ref angle);
                        }
                        rotated = g.Transform;
                        rotated.RotateAt(angle, location);
                        g.Transform = rotated;
                        DrawImage(g, location, symbol);
                        g.Transform = oldMat;
                    }
                }
            }
        }