Example #1
0
        public void drawMap(Graphics g, int width, int height, Point center)
        {
            try
            {
                int nScale = mapview.Getlevel(tlVectorControl1.ScaleRatio);
                if (nScale == -1)
                {
                    return;
                }
                LongLat longlat = LongLat.Empty;
                //计算中心点经纬度

                longlat = mapview.OffSet(mapview.ZeroLongLat, mapview.Getlevel(1), center.X, center.Y);
                ImageAttributes imageA = new ImageAttributes();
                longlat = mapview.OffSetZero(-(int)(center.X * tlVectorControl1.ScaleRatio), -(int)(center.Y * tlVectorControl1.ScaleRatio));

                int chose = Convert.ToInt32(ConfigurationSettings.AppSettings.Get("chose"));
                if (chose == 1)
                {
                    g.Clear(Color.White);//ColorTranslator.FromHtml("#EBEAE8")

                    Color color = ColorTranslator.FromHtml("#EBEAE8");
                    imageA.SetColorKey(color, color);
                }
                else if (chose == 2)
                {
                    Color color  = ColorTranslator.FromHtml("#F4F4FB");
                    Color color2 = ColorTranslator.FromHtml("#EFF0F1");//EFF0F1
                    //imageAttributes2.SetColorKey(color, color);
                    //imageAttributes2.SetColorKey(color2, color2);
                    imageA.SetColorKey(color2, color);
                }
                //imageA.
                //g.InterpolationMode = InterpolationMode.HighQualityBicubic;


                mapview.Paint(g, width, height, nScale, longlat.Longitude, longlat.Latitude, imageA);
                //绘制比例尺
                Point p1 = new Point(20, height - 30);
                Point p2 = new Point(20, height - 20);
                Point p3 = new Point(80, height - 20);
                Point p4 = new Point(80, height - 30);

                //g.DrawLines(new Pen(Color.Black, 2), new Point[4] { p1, p2, p3, p4 });
                //string str1 = string.Format("{0}公里", MapViewObj.GetMiles(nScale));
                //g.DrawString(str1, new Font("宋体", 10), Brushes.Black, 30, height - 40);
            }
            catch (Exception e1)
            {
            }
        }
Example #2
0
        private void documentControl1_AfterPaintPage(object sender, ItopVector.Core.PaintMapEventArgs e)
        {
            (mapview as MapViewBase).ShowMapInfo = true;
            int   nScale = 0;
            float nn     = 1;

            nScale = mapview.Getlevel(documentControl1.ScaleRatio);
            //if(isIn)
            //nScale = mapview.Getlevel(documentControl1.ScaleRatio, out nn);
            //else
            //nScale = mapview.Getlevel2(documentControl1.ScaleRatio, out nn);
            if (nScale == -1)
            {
                return;
            }


            LongLat longlat = LongLat.Empty;

            //计算中心点经纬度

            longlat = mapview.OffSet(mapview.ZeroLongLat, nScale, (int)(e.CenterPoint.X / nn), (int)(e.CenterPoint.Y / nn));

            //创建地图

            System.Drawing.Image image = backbmp;
            //if (image != null && isdown) { } else
            if (nn >= 1)
            {
                //for (double i=-0.1;i<=0.1;i=i+0.01)
                //{
                //    for (double j = -0.1; j <= 0.1; j = j + 0.01)
                //    {
                //        image = mapview.CreateMap(e.Bounds.Width, e.Bounds.Height, nScale, longlat.Longitude + i, longlat.Latitude+j);
                //    }
                //}
                //image = mapview.CreateMap(1000, 1000, nScale, longlat.Longitude, longlat.Latitude);
                image = mapview.CreateMap(e.Bounds.Width, e.Bounds.Height, nScale, longlat.Longitude, longlat.Latitude);
            }
            else
            {
                image = mapview.CreateMap((int)(e.Bounds.Width / nn), (int)(e.Bounds.Height / nn), nScale, longlat.Longitude, longlat.Latitude);
            }
            //backbmp = image;
            ImageAttributes imageAttributes = new ImageAttributes();
            ColorMatrix     matrix1         = new ColorMatrix();

            matrix1.Matrix00 = 1f;
            matrix1.Matrix11 = 1f;
            matrix1.Matrix22 = 1f;
            matrix1.Matrix33 = 0.9f;            //地图透明度
            matrix1.Matrix44 = 1f;
            //设置地图透明度
            imageAttributes.SetColorMatrix(matrix1, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            //int offx = 0;
            //int offy = 0;
            //if (isdown) {
            //    offx = Control.MousePosition.X - beginPoint.X;
            //    offy = Control.MousePosition.Y - beginPoint.Y;
            //}
            //e.G.TranslateTransform(offx, offy, MatrixOrder.Append);
            //绘制地图

            if (nn > 1)
            {
                int w1 = (int)(e.Bounds.Width * ((nn - 1) / 2));
                int h1 = (int)(e.Bounds.Height * ((nn - 1) / 2));

                Rectangle rt1 = e.Bounds;
                rt1.Inflate(w1, h1);
                e.G.CompositingQuality = CompositingQuality.HighQuality;
                e.G.DrawImage((Bitmap)image, rt1, 0f, 0f, (float)image.Width, (float)image.Height, GraphicsUnit.Pixel, imageAttributes);
            }
            else
            {
                e.G.DrawImage((Bitmap)image, e.Bounds, 0f, 0f, (float)image.Width, (float)image.Height, GraphicsUnit.Pixel, imageAttributes);
            }
            SolidBrush brush = new SolidBrush(Color.FromArgb(220, 75, 75, 75));

            //e.G.FillRectangle( brush,e.G.VisibleClipBounds);
            //绘制中心点
            e.G.DrawEllipse(Pens.Red, e.Bounds.Width / 2 - 2, e.Bounds.Height / 2 - 2, 4, 4);
            e.G.DrawEllipse(Pens.Red, e.Bounds.Width / 2 - 1, e.Bounds.Height / 2 - 1, 2, 2);
            ///107,159
            {    //绘制比例尺
                Point p1 = new Point(20, e.Bounds.Height - 30);
                Point p2 = new Point(20, e.Bounds.Height - 20);
                Point p3 = new Point(80, e.Bounds.Height - 20);
                Point p4 = new Point(80, e.Bounds.Height - 30);

                e.G.DrawLines(new Pen(Color.Black, 2), new Point[4] {
                    p1, p2, p3, p4
                });
                string str1 = string.Format("{0}公里", mapview.GetMiles(nScale));
                e.G.DrawString(str1, new Font("宋体", 10), Brushes.Black, 30, e.Bounds.Height - 40);
            }
//			string s = string.Format("{0}行{1}列", nRows, nCols);
            string s = string.Format("经{0}:纬{1}", longlat.Longitude, longlat.Latitude);

//			//显示中心点经纬度
            e.G.DrawString(s, new Font("宋体", 10), Brushes.Red, 20, 40);

//			IntPtr hDC = e.G.GetHdc();
//
//
//			LOGBRUSH brush;
//			brush.lbColor = 255;
//			brush.lbHatch = 10;
//			brush.lbStyle = 1;//BS_NULL
//			IntPtr hBursh = CreateBrushIndirect(ref brush);
//			IntPtr hPen = CreatePen(2, 1, 255);
//			IntPtr nOldPen = SelectObject(hDC, hPen);
//			IntPtr nOldBrush = SelectObject(hDC, hBursh);
//			SetROP2(hDC,10);
//			Rectangle((int)hDC, 100, 100, 50, 50);
////			SetROP2(hDC,10);
//			Rectangle((int)hDC, 150, 150, 50, 50);
//
//			SelectObject(hDC, nOldPen);
//			SelectObject(hDC, nOldBrush);
//			e.G.ReleaseHdc(hDC);
        }