// 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; } }
// 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; } }
// 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; } }