/// <summary> /// Function to render the actual map decoration /// </summary> /// <param name="g"></param> /// <param name="map"></param> protected override void OnRender(Graphics g, IMapViewPort map) { var image = NorthArrowImage ?? DefaultNorthArrowBitmap; var mapSize = map.Size; //Get rotation var ptTop = map.ImageToWorld(new PointF(mapSize.Width / 2f, 0f), true); var ptBottom = map.ImageToWorld(new PointF(mapSize.Width / 2f, mapSize.Height * 0.5f), true); var dx = ptTop.X - ptBottom.X; var dy = ptBottom.Y - ptTop.Y; var length = Math.Sqrt(dx * dx + dy * dy); var cos = dx / length; var rot = -90 + (dy > 0 ? -1 : 1) * Math.Acos(cos) / GeoSpatialMath.DegToRad; var halfSize = new Size((int)(0.5f * Size.Width), (int)(0.5f * Size.Height)); var oldTransform = g.Transform; var clip = g.ClipBounds; var newTransform = new Matrix(1f, 0f, 0f, 1f, clip.Left + halfSize.Width, clip.Top + halfSize.Height); newTransform.Rotate((float)rot); // Setup image attributes var ia = new ImageAttributes(); var cmap = new [] { new ColorMap { OldColor = Color.Transparent, NewColor = OpacityColor(BackgroundColor) }, new ColorMap { OldColor = Color.Black, NewColor = OpacityColor(ForeColor) } }; ia.SetRemapTable(cmap); g.Transform = newTransform; var rect = new Rectangle(-halfSize.Width, -halfSize.Height, Size.Width, Size.Height); g.DrawImage(image, rect, 0, 0, image.Size.Width, image.Size.Height, GraphicsUnit.Pixel, ia); g.Transform = oldTransform; }
/// <summary> /// Function to render the actual map decoration /// </summary> /// <param name="g"></param> /// <param name="map"></param> protected override void OnRender(Graphics g, IMapViewPort map) { var rectF = g.ClipBounds; if (MapUnit == (int)Unit.Degree) { var p1 = map.ImageToWorld(new PointF(0, map.Size.Height * 0.5f)); var p2 = map.ImageToWorld(new PointF(map.Size.Width, map.Size.Height * 0.5f)); SetScaleD((int)g.DpiX, p1.X, p2.X, p1.Y, map.Size.Width); } else { SetScale((int)g.DpiX, map.Envelope.Width, map.Size.Width); } var rect = new Rectangle(Point.Truncate(rectF.Location), Size.Truncate(rectF.Size)); RenderScaleBar(g, rect); }