Exemplo n.º 1
0
        /// <summary>
        /// Gets the indices of the features that get drawn.
        /// </summary>
        /// <param name="indices">Indices of all the features that could be drawn.</param>
        /// <param name="states">FastDrawnStates of the features.</param>
        /// <param name="category">Category the features must have to get drawn.</param>
        /// <param name="selected">Indicates whether only the selected features get drawn.</param>
        /// <returns>List of the indices of the features that get drawn.</returns>
        private static List <int> GetFeatures(IList <int> indices, FastDrawnState[] states, ILineCategory category, bool selected)
        {
            List <int> drawnFeatures = new List <int>();

            foreach (int index in indices)
            {
                if (index >= states.Length)
                {
                    break;
                }
                FastDrawnState state = states[index];

                if (selected)
                {
                    if (state.Category == category && state.Visible && state.Selected)
                    {
                        drawnFeatures.Add(index);
                    }
                }
                else
                {
                    if (state.Category == category && state.Visible)
                    {
                        drawnFeatures.Add(index);
                    }
                }
            }

            return(drawnFeatures);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Equality based on the Boolean and category settings
        /// </summary>
        /// <param name="obj">The fast drawn state to compare with</param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            FastDrawnState item = obj as FastDrawnState;

            if (item == null)
            {
                return(false);
            }
            return(item.Selected == Selected && item.Category == Category && Visible == item.Visible);
        }
Exemplo n.º 3
0
        // CGX, n'est plus static
        /// <summary>
        /// Gets the indices of the features that get drawn.
        /// </summary>
        /// <param name="indices">Indices of all the features that could be drawn.</param>
        /// <param name="states">FastDrawnStates of the features.</param>
        /// <param name="category">Category the features must have to get drawn.</param>
        /// <param name="selected">Indicates whether only the selected features get drawn.</param>
        /// <returns>List of the indices of the features that get drawn.</returns>
        private List <int> GetFeatures(IList <int> indices, FastDrawnState[] states, ILineCategory category, bool selected)
        {
            List <int> drawnFeatures = new List <int>();

            foreach (int index in indices)
            {
                if (index >= states.Length)
                {
                    break;
                }
                FastDrawnState state = states[index];

                if (selected)
                {
                    if (state.Category == category && state.Visible && state.Selected)
                    {
                        // CGX
                        if (Visibility != null && Visibility.Length > 0 && index < Visibility.Length)
                        {
                            bool visi = Visibility[index].Visible;
                            if (!visi)
                            {
                                continue;
                            }
                        } // CGX END

                        drawnFeatures.Add(index);
                    }
                }
                else
                {
                    if (state.Category == category && state.Visible)
                    {
                        drawnFeatures.Add(index);
                    }
                }
            }

            return(drawnFeatures);
        }
Exemplo n.º 4
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;

            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    = pc?.Symbolizer;
                if (ps == null)
                {
                    return;
                }
                double[] vertices = DataSet.Vertex;

                foreach (int index in indices)
                {
                    if (DrawnStates != null && DrawnStates.Length > index && !DrawnStates[index].Visible)
                    {
                        continue;
                    }
                    if (featureType == FeatureType.Point)
                    {
                        DrawPoint(vertices[index * 2], vertices[(index * 2) + 1], e, ps, g, origTransform);
                    }
                    else
                    {
                        // multi-point
                        ShapeRange range = DataSet.ShapeIndices[index];
                        for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                        {
                            DrawPoint(vertices[i * 2], vertices[(i * 2) + 1], e, ps, g, origTransform);
                        }
                    }
                }
            }
            else
            {
                FastDrawnState[] states   = DrawnStates;
                double[]         vertices = DataSet.Vertex;

                foreach (int index in indices)
                {
                    if (index >= states.Length)
                    {
                        break;
                    }
                    FastDrawnState state = states[index];
                    if (!state.Visible || state.Category == null)
                    {
                        continue;
                    }
                    IPointCategory pc = state.Category as IPointCategory;
                    if (pc == null)
                    {
                        continue;
                    }

                    IPointSymbolizer ps = state.Selected ? pc.SelectionSymbolizer : pc.Symbolizer;
                    if (ps == null)
                    {
                        continue;
                    }

                    if (featureType == FeatureType.Point)
                    {
                        DrawPoint(vertices[index * 2], vertices[(index * 2) + 1], e, ps, g, origTransform);
                    }
                    else
                    {
                        ShapeRange range = DataSet.ShapeIndices[index];
                        for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                        {
                            DrawPoint(vertices[i * 2], vertices[(i * 2) + 1], e, ps, g, origTransform);
                        }
                    }
                }
            }

            if (e.Device == null)
            {
                g.Dispose();
            }
            else
            {
                g.Transform = origTransform;
            }
        }
Exemplo n.º 5
0
        private void BuildPaths(MapArgs e, IEnumerable <int> indices, out Dictionary <FastDrawnState, GraphicsPath> paths, bool selected)
        {
            paths = new Dictionary <FastDrawnState, GraphicsPath>();

            var indiceList = indices as IList <int> ?? indices.ToList();

            FastDrawnState[] states = DrawnStatesNeeded ? DrawnStates : new FastDrawnState[0];
            if (DrawnStatesNeeded && indiceList.Max() >= states.Length)
            {
                AssignFastDrawnStates();
                states = DrawnStates;
            }

            if (selected && (!DrawnStatesNeeded || !DrawnStates.Any(_ => _.Selected)))
            {
                return;
            }

            if (ProgressReportingEnabled)
            {
                ProgressMeter = new ProgressMeter(ProgressHandler, "Building Paths", indiceList.Count);
            }

            FastDrawnState     state       = new FastDrawnState(selected, Symbology.Categories[0]);
            Extent             drawExtents = e.GeographicExtents;
            Rectangle          clipRect    = e.ProjToPixel(e.GeographicExtents);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            List <ShapeRange> shapes = DataSet.ShapeIndices;

            double[] vertices = DataSet.Vertex;

            foreach (int shp in indiceList)
            {
                if (ProgressReportingEnabled)
                {
                    ProgressMeter.Next();
                }
                if (shp >= shapes.Count)
                {
                    return;
                }
                ShapeRange shape = shapes[shp];
                if (!shape.Extent.Intersects(e.GeographicExtents))
                {
                    continue;
                }

                if (DrawnStatesNeeded)
                {
                    if (!states[shp].Visible || (selected && !states[shp].Selected))
                    {
                        continue;
                    }

                    state = new FastDrawnState(selected, states[shp].Category);
                }

                if (!paths.ContainsKey(state))
                {
                    paths.Add(state, new GraphicsPath(FillMode.Winding));
                }

                BuildPolygon(vertices, shapes[shp], paths[state], e, drawExtents.Contains(shape.Extent) ? null : shClip);
            }

            if (ProgressReportingEnabled)
            {
                ProgressMeter.Reset();
            }
        }
Exemplo n.º 6
0
        private void BuildPaths(MapArgs e, IEnumerable <int> indices, out List <GraphicsPath> paths)
        {
            DateTime startTime = DateTime.Now;

            paths = new List <GraphicsPath>();
            Rectangle          clipRect    = ComputeClippingRectangle(e);
            Extent             drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            List <GraphicsPath> graphPaths = new List <GraphicsPath>();
            Dictionary <FastDrawnState, GraphicsPath> borders = new Dictionary <FastDrawnState, GraphicsPath>();

            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (IPolygonCategory category in Symbology.Categories)
                {
                    FastDrawnState state = new FastDrawnState(selectState == 1, category);

                    GraphicsPath border = new GraphicsPath();
                    borders.Add(state, border);
                    graphPaths.Add(border);
                }
            }

            paths.AddRange(graphPaths);

            List <ShapeRange> shapes = DataSet.ShapeIndices;

            double[] vertices = DataSet.Vertex;

            if (ProgressReportingEnabled)
            {
                ProgressMeter = new ProgressMeter(ProgressHandler, "Building Paths", indices.Count());
            }

            if (!DrawnStatesNeeded)
            {
                FastDrawnState state = new FastDrawnState(false, Symbology.Categories[0]);

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled)
                    {
                        ProgressMeter.Next();
                    }
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents))
                    {
                        return;
                    }
                    if (shp >= shapes.Count)
                    {
                        return;
                    }
                    if (!borders.ContainsKey(state))
                    {
                        return;
                    }

                    BuildPolygon(vertices, shapes[shp], borders[state], e, drawExtents.Contains(shape.Extent) ? null : shClip);
                }
            }
            else
            {
                FastDrawnState[] states = DrawnStates;
                foreach (GraphicsPath borderPath in borders.Values)
                {
                    if (borderPath != null)
                    {
                        borderPath.FillMode = FillMode.Winding;
                    }
                }

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled)
                    {
                        ProgressMeter.Next();
                    }
                    if (shp >= shapes.Count)
                    {
                        return;
                    }
                    if (shp >= states.Length)
                    {
                        AssignFastDrawnStates();
                        states = DrawnStates;
                    }
                    if (states[shp].Visible == false)
                    {
                        continue;
                    }
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents))
                    {
                        return;
                    }
                    if (drawExtents.Contains(shape.Extent))
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state))
                        {
                            return;
                        }
                        BuildPolygon(vertices, shapes[shp], borders[state], e, null);
                    }
                    else
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state))
                        {
                            return;
                        }
                        BuildPolygon(vertices, shapes[shp], borders[state], e, shClip);
                    }
                }
            }
            if (ProgressReportingEnabled)
            {
                ProgressMeter.Reset();
            }

            TimeSpan interval = DateTime.Now - startTime;

            totalTime += interval.TotalMilliseconds;

            //Console.WriteLine("Total milliseconds: " + totalTime.ToString());
        }
Exemplo n.º 7
0
        // This draws the individual point features
        private void DrawFeatures(MapArgs e, IEnumerable <int> indices, bool selected)
        {
            if (selected && (!DrawnStatesNeeded || !DrawnStates.Any(_ => _.Selected)))
            {
                return;                                                                        // there are no selected features
            }
            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;

            // CGX
            if (dx < 2000000000 && dx > -2000000000 && dy < 2000000000 && dy > -2000000000)
            {
                if (!DrawnStatesNeeded)
                {
                    if (Symbology == null || Symbology.Categories.Count == 0)
                    {
                        return;
                    }
                    FastDrawnState   state = new FastDrawnState(false, Symbology.Categories[0]);
                    IPointSymbolizer ps    = (state.Category as IPointCategory)?.Symbolizer;
                    if (ps == null)
                    {
                        return;
                    }
                    double[] vertices = DataSet.Vertex;

                    foreach (int index in indices)
                    {
                        // CGX
                        if (Visibility != null)
                        {
                            bool visi = Visibility[index].Visible;
                            if (!visi)
                            {
                                continue;
                            }
                        }
                        if (featureType == FeatureType.Point)
                        {
                            DrawPoint(vertices[index * 2], vertices[(index * 2) + 1], e, ps, g, origTransform);
                        }
                        else
                        {
                            // multi-point
                            ShapeRange range = DataSet.ShapeIndices[index];
                            for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                            {
                                DrawPoint(vertices[i * 2], vertices[(i * 2) + 1], e, ps, g, origTransform);
                            }
                        }
                    }
                }
                else
                {
                    FastDrawnState[] states = DrawnStates;

                    var indexList = indices as IList <int> ?? indices.ToList();
                    if (indexList.Max() >= states.Length)
                    {
                        AssignFastDrawnStates();
                        states = DrawnStates;
                    }

                    double[] vertices = DataSet.Vertex;

                    foreach (int index in indexList)
                    {
                        if (index >= states.Length)
                        {
                            break;
                        }
                        FastDrawnState state = states[index];
                        if (!state.Visible || state.Category == null)
                        {
                            continue;
                        }
                        if (selected && !state.Selected)
                        {
                            continue;
                        }

                        IPointCategory pc = state.Category as IPointCategory;
                        if (pc == null)
                        {
                            continue;
                        }

                        IPointSymbolizer ps = selected ? pc.SelectionSymbolizer : pc.Symbolizer;
                        if (ps == null)
                        {
                            continue;
                        }

                        if (featureType == FeatureType.Point)
                        {
                            DrawPoint(vertices[index * 2], vertices[(index * 2) + 1], e, ps, g, origTransform);
                        }
                        else
                        {
                            ShapeRange range = DataSet.ShapeIndices[index];
                            for (int i = range.StartIndex; i <= range.EndIndex(); i++)
                            {
                                DrawPoint(vertices[i * 2], vertices[(i * 2) + 1], e, ps, g, origTransform);
                            }
                        }
                    }
                }
            }



            if (e.Device == null)
            {
                g.Dispose();
            }
            else
            {
                g.Transform = origTransform;
            }
        }
Exemplo n.º 8
0
        private void DrawFeatures(MapArgs e, IEnumerable <int> indices)
        {
            Graphics g = e.Device ?? Graphics.FromImage(BackBuffer);

            if (DrawnStatesNeeded)
            {
                FastDrawnState[] states = DrawnStates;
                int max = indices.Max();
                if (max >= states.Length)
                {
                    AssignFastDrawnStates();
                    states = DrawnStates;
                }
                for (int selectState = 0; selectState < 2; selectState++)
                {
                    foreach (ILineCategory category in Symbology.Categories)
                    {
                        // Define the symbology based on the category and selection state
                        ILineSymbolizer ls = category.Symbolizer;
                        if (selectState == SELECTED)
                        {
                            ls = category.SelectionSymbolizer;
                        }
                        g.SmoothingMode = ls.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;

                        // Compute a clipping rectangle that accounts for symbology
                        Rectangle clipRect = ComputeClippingRectangle(e, ls);

                        // Determine the subset of the specified features that are visible and match the category
                        ILineCategory lineCategory = category;
                        int           i            = selectState;

                        List <int> drawnFeatures = new List <int>();

                        foreach (int index in indices)
                        {
                            if (index >= states.Length)
                            {
                                break;
                            }
                            FastDrawnState state = states[index];
                            if (state.Category == lineCategory && state.Selected == (i == 1) && state.Visible)
                            {
                                drawnFeatures.Add(index);
                            }
                        }

                        GraphicsPath graphPath = new GraphicsPath();
                        foreach (int shp in drawnFeatures)
                        {
                            ShapeRange shape = DataSet.ShapeIndices[shp];
                            BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect);
                        }
                        double scale = 1;
                        if (ls.ScaleMode == ScaleMode.Geographic)
                        {
                            scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                        }

                        foreach (IStroke stroke in ls.Strokes)
                        {
                            stroke.DrawPath(g, graphPath, scale);
                        }

                        graphPath.Dispose();
                    }
                }
            }
            else
            {
                // Selection state is disabled
                // Category is only the very first category
                ILineCategory   category = Symbology.Categories[0];
                ILineSymbolizer ls       = category.Symbolizer;

                g.SmoothingMode = ls.Smoothing ? SmoothingMode.AntiAlias : SmoothingMode.None;

                Rectangle clipRect = ComputeClippingRectangle(e, ls);
                // Determine the subset of the specified features that are visible and match the category
                GraphicsPath graphPath = new GraphicsPath();
                foreach (int shp in indices)
                {
                    ShapeRange shape = DataSet.ShapeIndices[shp];
                    BuildLineString(graphPath, DataSet.Vertex, shape, e, clipRect);
                }
                double scale = 1;
                if (ls.ScaleMode == ScaleMode.Geographic)
                {
                    scale = e.ImageRectangle.Width / e.GeographicExtents.Width;
                }

                foreach (IStroke stroke in ls.Strokes)
                {
                    stroke.DrawPath(g, graphPath, scale);
                }

                graphPath.Dispose();
            }

            if (e.Device == null)
            {
                g.Dispose();
            }
        }
Exemplo n.º 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;
            }
        }