コード例 #1
0
ファイル: MapPointLayer.cs プロジェクト: CGX-GROUP/DotSpatial
        // This draws the individual point features
        private void DrawFeatures(MapArgs e, IEnumerable <IFeature> features, bool selected)
        {
            IDictionary <IFeature, IDrawnState> states = DrawingFilter.DrawnStates;

            if (states == null)
            {
                return;
            }
            if (selected && !states.Any(_ => _.Value.IsSelected))
            {
                return;
            }

            Graphics g             = e.Device ?? Graphics.FromImage(BackBuffer);
            Matrix   origTransform = g.Transform;

            foreach (IFeature feature in features)
            {
                if (!states.ContainsKey(feature))
                {
                    continue;
                }
                IDrawnState ds = states[feature];
                if (ds == null || !ds.IsVisible || ds.SchemeCategory == null)
                {
                    continue;
                }

                if (selected && !ds.IsSelected)
                {
                    continue;
                }

                IPointCategory pc = ds.SchemeCategory as IPointCategory;
                if (pc == null)
                {
                    continue;
                }

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

                foreach (Coordinate c in feature.Geometry.Coordinates)
                {
                    DrawPoint(c.X, c.Y, e, ps, g, origTransform);
                }
            }

            if (e.Device == null)
            {
                g.Dispose();
            }
            else
            {
                g.Transform = origTransform;
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a new scheme, assuming that the new scheme is the correct type.
        /// </summary>
        /// <param name="category">The category to add.</param>
        public override void AddCategory(ICategory category)
        {
            IPointCategory pc = category as IPointCategory;

            if (pc != null)
            {
                _categories.Add(pc);
            }
        }
コード例 #3
0
        /// <summary>
        /// Inserts the category at the specified index.
        /// </summary>
        /// <param name="index">The integer index where the category should be inserted.</param>
        /// <param name="category">The category to insert.</param>
        public override void InsertCategory(int index, ICategory category)
        {
            IPointCategory pc = category as IPointCategory;

            if (pc != null)
            {
                _categories.Insert(index, pc);
            }
        }
コード例 #4
0
        /// <summary>
        /// Removes the specified category.
        /// </summary>
        /// <param name="category">The category to insert.</param>
        public override void RemoveCategory(ICategory category)
        {
            IPointCategory pc = category as IPointCategory;

            if (pc != null)
            {
                _categories.Remove(pc);
            }
        }
コード例 #5
0
        public void ConvertLayerProperties_MapPointDataWithThemeAndMetaDataNameNotInFeatures_OnlyAddsDefaultCategory()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);
            var          theme             = new MapTheme <PointCategoryTheme>("Other Meta", new[]
            {
                new PointCategoryTheme(ValueCriterionTestFactory.CreateValueCriterion(),
                                       new PointStyle
                {
                    Color           = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    Size            = random.Next(1, 48),
                    Symbol          = random.NextEnum <PointSymbol>(),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });

            var pointStyle = new PointStyle
            {
                Color           = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                Size            = random.Next(1, 48),
                Symbol          = random.NextEnum <PointSymbol>(),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var mapPointData = new MapPointData("test", pointStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapPointLayer = new MapPointLayer();

            var converter = new MapPointDataConverter();

            // Call
            converter.ConvertLayerProperties(mapPointData, mapPointLayer);

            // Assert
            PointSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(pointStyle);

            IPointScheme appliedScheme = mapPointLayer.Symbology;

            Assert.AreEqual(1, appliedScheme.Categories.Count);

            IPointCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);
        }
コード例 #6
0
ファイル: Legend.cs プロジェクト: qingqibing/aa
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDoubleClick(MouseEventArgs e)
        {
            _wasDoubleClick = true;
            Point loc = new Point(e.X + ControlRectangle.X, e.Location.Y + ControlRectangle.Top);

            foreach (LegendBox lb in _legendBoxes)
            {
                if (!lb.Bounds.Contains(loc) || lb.CheckBox.Contains(loc))
                {
                    continue;
                }
                ILineCategory lc = lb.Item as ILineCategory;
                if (lc != null)
                {
                    DetailedLineSymbolDialog lsDialog = new DetailedLineSymbolDialog(lc.Symbolizer);
                    lsDialog.ShowDialog();
                    ILineSymbolizer sel = lc.Symbolizer.Copy();
                    sel.SetFillColor(Color.Cyan);
                    lc.SelectionSymbolizer = sel;
                }
                IPointCategory pc = lb.Item as IPointCategory;
                if (pc != null)
                {
                    DetailedPointSymbolDialog dlg = new DetailedPointSymbolDialog(pc.Symbolizer);
                    dlg.ShowDialog();
                    IPointSymbolizer ps = pc.Symbolizer.Copy();
                    ps.SetFillColor(Color.Cyan);
                    pc.SelectionSymbolizer = ps;
                }
                IPolygonCategory polyCat = lb.Item as IPolygonCategory;
                if (polyCat != null)
                {
                    DetailedPolygonSymbolDialog dlg = new DetailedPolygonSymbolDialog(polyCat.Symbolizer);
                    dlg.ShowDialog();
                    IPolygonSymbolizer ps = polyCat.Symbolizer.Copy();
                    ps.SetFillColor(Color.Cyan);
                    ps.OutlineSymbolizer.SetFillColor(Color.DarkCyan);
                    polyCat.SelectionSymbolizer = ps;
                }
                IFeatureLayer fl = lb.Item as IFeatureLayer;
                if (fl != null)
                {
                    LayerDialog layDialog = new LayerDialog(fl, new FeatureCategoryControl());
                    layDialog.ShowDialog();
                }
                IRasterLayer rl = lb.Item as IRasterLayer;
                if (rl != null)
                {
                    LayerDialog dlg = new LayerDialog(rl, new RasterCategoryControl());
                    dlg.ShowDialog();
                }
                IColorCategory cb = lb.Item as IColorCategory;
                if (cb != null)
                {
                    _tabColorDialog = new TabColorDialog();
                    _tabColorDialog.ChangesApplied += TabColorDialogChangesApplied;
                    _tabColorDialog.StartColor      = cb.LowColor;
                    _tabColorDialog.EndColor        = cb.HighColor;
                    _editCategory = cb;
                    _tabColorDialog.ShowDialog(this);
                }
            }
            base.OnMouseDoubleClick(e);
        }
コード例 #7
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;
            }
        }
コード例 #8
0
        /// <inheritdoc />
        protected override void OnMouseDown(GeoMouseArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
            {
                _mousePosition = e.Location;
                if (_dragging)
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        _dragging = false;
                        Map.Invalidate();
                        Map.IsBusy = false;
                    }
                }
                else
                {
                    if (_selectedFeature != null)
                    {
                        Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);

                        Envelope env = Map.PixelToProj(mouseRect).ToEnvelope();

                        if (CheckForVertexDrag(e))
                        {
                            return;
                        }

                        // No vertex selection has occured.
                        if (!_selectedFeature.Geometry.Intersects(env.ToPolygon()))
                        {
                            // We are clicking down outside of the given polygon, so clear our selected feature
                            DeselectFeature();
                            return;
                        }
                    }

                    if (_activeFeature != null)
                    {
                        // Don't start dragging a vertices right away for polygons and lines.
                        // First you select the polygon, which displays the vertices, then they can be moved.
                        if (_featureSet.FeatureType == FeatureType.Polygon)
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            IPolygonCategory sc = _selectedCategory as IPolygonCategory;
                            if (sc == null)
                            {
                                _selectedCategory = new PolygonCategory(Color.FromArgb(55, 0, 255, 255), Color.Blue, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }

                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else if (_featureSet.FeatureType == FeatureType.Line)
                        {
                            _selectedFeature = _activeFeature;
                            _activeFeature   = null;
                            ILineCategory sc = _selectedCategory as ILineCategory;
                            if (sc == null)
                            {
                                _selectedCategory = new LineCategory(Color.Cyan, 1)
                                {
                                    LegendItemVisible = false
                                };
                            }
                            _layer.SetCategory(_selectedFeature, _selectedCategory);
                        }
                        else
                        {
                            _dragging  = true;
                            Map.IsBusy = true;
                            _dragCoord = _activeFeature.Geometry.Coordinates[0];
                            MapPointLayer mpl = _layer as MapPointLayer;
                            if (mpl != null)
                            {
                                mpl.SetVisible(_activeFeature, false);
                            }
                            IPointCategory sc = _selectedCategory as IPointCategory;
                            if (sc == null)
                            {
                                IPointSymbolizer ps =
                                    _layer.GetCategory(_activeFeature).Symbolizer.Copy() as IPointSymbolizer;
                                if (ps != null)
                                {
                                    ps.SetFillColor(Color.Cyan);
                                    _selectedCategory = new PointCategory(ps);
                                }
                            }
                        }
                    }
                    Map.MapFrame.Initialize();
                    Map.Invalidate();
                }
            }
            base.OnMouseDown(e);
        }
コード例 #9
0
ファイル: MapPointLayer.cs プロジェクト: CGX-GROUP/DotSpatial
        // 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;
            }
        }
コード例 #10
0
        /// <summary>
        /// Re-orders the specified member by attempting to exchange it with the next higher
        /// index category. If there is no higher index, this does nothing.
        /// </summary>
        /// <param name="category">The category to increase the index of.</param>
        /// <returns>True, if index was increased.</returns>
        public override bool IncreaseCategoryIndex(ICategory category)
        {
            IPointCategory pc = category as IPointCategory;

            return(pc != null && Categories.IncreaseIndex(pc));
        }
コード例 #11
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;
            }
        }
コード例 #12
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;
            }
        }
コード例 #13
0
        public void ConvertLayerProperties_MapPointDataWithThemeAndMetaDataNameInFeatures_ConvertDataToMapPointLayer()
        {
            // Setup
            const string metadataAttribute = "Meta";
            var          random            = new Random(21);

            var unequalCriterion = new ValueCriterion(ValueCriterionOperator.UnequalValue,
                                                      "unequal value");
            var equalCriterion = new ValueCriterion(ValueCriterionOperator.EqualValue,
                                                    "equal value");
            var theme = new MapTheme <PointCategoryTheme>(metadataAttribute, new[]
            {
                new PointCategoryTheme(equalCriterion, new PointStyle
                {
                    Color           = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    Size            = random.Next(1, 48),
                    Symbol          = random.NextEnum <PointSymbol>(),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                }),
                new PointCategoryTheme(unequalCriterion, new PointStyle
                {
                    Color           = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    Size            = random.Next(1, 48),
                    Symbol          = random.NextEnum <PointSymbol>(),
                    StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                    StrokeThickness = random.Next(1, 48)
                })
            });

            var pointStyle = new PointStyle
            {
                Color           = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                Size            = random.Next(1, 48),
                Symbol          = random.NextEnum <PointSymbol>(),
                StrokeColor     = Color.FromKnownColor(random.NextEnum <KnownColor>()),
                StrokeThickness = random.Next(1, 48)
            };
            var mapPointData = new MapPointData("test", pointStyle, theme)
            {
                Features = new[]
                {
                    CreateMapFeatureWithMetaData(metadataAttribute)
                }
            };

            var mapPointLayer = new MapPointLayer();

            var converter = new MapPointDataConverter();

            // Call
            converter.ConvertLayerProperties(mapPointData, mapPointLayer);

            // Assert
            PointSymbolizer expectedSymbolizer = CreateExpectedSymbolizer(pointStyle);

            IPointScheme appliedScheme = mapPointLayer.Symbology;

            Assert.AreEqual(3, appliedScheme.Categories.Count);

            IPointCategory baseCategory = appliedScheme.Categories[0];

            AssertAreEqual(expectedSymbolizer, baseCategory.Symbolizer);
            Assert.IsNull(baseCategory.FilterExpression);

            IPointCategory equalSchemeCategory = appliedScheme.Categories[1];
            string         expectedFilter      = $"[1] = '{equalCriterion.Value}'";

            Assert.AreEqual(expectedFilter, equalSchemeCategory.FilterExpression);
            PointStyle expectedCategoryStyle = theme.CategoryThemes.ElementAt(0).Style;

            expectedSymbolizer = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, equalSchemeCategory.Symbolizer);

            IPointCategory unEqualSchemeCategory = appliedScheme.Categories[2];

            expectedFilter = $"NOT [1] = '{unequalCriterion.Value}'";
            Assert.AreEqual(expectedFilter, unEqualSchemeCategory.FilterExpression);
            expectedCategoryStyle = theme.CategoryThemes.ElementAt(1).Style;
            expectedSymbolizer    = CreateExpectedSymbolizer(expectedCategoryStyle);
            AssertAreEqual(expectedSymbolizer, unEqualSchemeCategory.Symbolizer);
        }