コード例 #1
4
        void getImage()
        {
            MapType type = MapType.GoogleSatellite;
            PureProjection prj = null;
            int maxZoom;

            GMaps.Instance.AdjustProjection(type, ref prj, out maxZoom);
              //int zoom = 14; // 12
            if (!area.IsEmpty)
            {
                try
                {
                    List<GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);
                    //string bigImage = zoom + "-" + type + "-vilnius.png";

                    //Console.WriteLine("Preparing: " + bigImage);
                    //Console.WriteLine("Zoom: " + zoom);
                    //Console.WriteLine("Type: " + type.ToString());
                    //Console.WriteLine("Area: " + area);

                    var types = GMaps.Instance.GetAllLayersOfType(type);

                    // current area
                    GPoint topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                    GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                    GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

                    DateTime startimage = DateTime.Now;

                    int padding = 0;
                    {
                        using (Bitmap bmpDestination = new Bitmap(pxDelta.X + padding * 2, pxDelta.Y + padding * 2))
                        {
                            using (Graphics gfx = Graphics.FromImage(bmpDestination))
                            {
                                gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                                // get tiles & combine into one
                                foreach (var p in tileArea)
                                {
                                   Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count);

                                    foreach (MapType tp in types)
                                    {
                                        Exception ex;
                                        WindowsFormsImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as WindowsFormsImage;
                                        if (tile != null)
                                        {
                                            using (tile)
                                            {
                                                int x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                                int y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                                {
                                                    gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                                }
                                            }
                                        }
                                    }
                                    if ((DateTime.Now - startimage).TotalMilliseconds > 200)
                                        break;
                                }
                            }
                            _terrain = new Bitmap(bmpDestination, 512, 512);

                            GL.BindTexture(TextureTarget.Texture2D, texture);

                            BitmapData data = _terrain.LockBits(new System.Drawing.Rectangle(0, 0, _terrain.Width, _terrain.Height),
                    ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                            //Console.WriteLine("w {0} h {1}",data.Width, data.Height);

                            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                                OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

                            _terrain.UnlockBits(data);

                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

                        }
                    }
                    if ((DateTime.Now - startimage).TotalMilliseconds > 200)
                    {
                        zoom--;
                    }
                    else
                    {
                        //zoom++;
                    }
                }
                catch { }
            }
        }
コード例 #2
1
ファイル: GRect.cs プロジェクト: mikhp/greatmaps
 public GRect(GPoint location, GSize size)
 {
    this.x = location.X;
    this.y = location.Y;
    this.width = size.Width;
    this.height = size.Height;
 }
コード例 #3
1
ファイル: TilePrefetcher.cs プロジェクト: LeoTosti/x-drone
        bool CacheTiles(ref MapType[] types, int zoom, GPoint p)
        {
            foreach(MapType type in types)
             {
            Exception ex;
            PureImage img;

            // tile number inversion(BottomLeft -> TopLeft) for pergo maps
            if(type == MapType.PergoTurkeyMap)
            {
               img = GMaps.Instance.GetImageFrom(type, new GPoint(p.X, maxOfTiles.Height - p.Y), zoom, out ex);
            }
            else // ok
            {
               img = GMaps.Instance.GetImageFrom(type, p, zoom, out ex);
            }

            if(img != null)
            {
               img.Dispose();
               img = null;
            }
            else
            {
               return false;
            }
             }
             return true;
        }
コード例 #4
1
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (this.DesignMode)
                return;

            if (area.LocationMiddle.Lat == 0 && area.LocationMiddle.Lng == 0)
                return;
            
            try
            {
                base.OnPaint(e);

            }
            catch { return;  }

            double heightscale = (step / 90.0) * 3;

            float yawradians = (float)(Math.PI * (rpy.Z * 1) / 180.0f);

             //radians = 0;

            float mouseY = (float)(0.0025);

            cameraX = area.LocationMiddle.Lng;// -Math.Sin(yawradians) * mouseY;     // multiplying by mouseY makes the
            cameraY = area.LocationMiddle.Lat;// -Math.Cos(yawradians) * mouseY;    // camera get closer/farther away with mouseY
            cameraZ = (LocationCenter.Alt < srtm.getAltitude(center.Lat, center.Lng).alt) ? (srtm.getAltitude(center.Lat, center.Lng).alt + 1) * heightscale : LocationCenter.Alt * heightscale;// (srtm.getAltitude(lookZ, lookX, 20) + 100) * heighscale;

      lookX = area.LocationMiddle.Lng + Math.Sin(yawradians) * mouseY;
      lookY = area.LocationMiddle.Lat + Math.Cos(yawradians) * mouseY;
      lookZ = cameraZ;

     // cameraZ += 0.04;
            
            GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj = type.Projection;

          
            PointLatLngAlt leftf = center.newpos(rpy.Z ,500);
            PointLatLngAlt rightf = center.newpos(rpy.Z, 10);
            PointLatLngAlt left = center.newpos(rpy.Z - 90, 500);
            PointLatLngAlt right = center.newpos(rpy.Z + 90, 500);

            double maxlat = Math.Max(left.Lat,Math.Max(right.Lat,Math.Max(leftf.Lat,rightf.Lat)));
            double minlat = Math.Min(left.Lat, Math.Min(right.Lat, Math.Min(leftf.Lat, rightf.Lat)));

            double maxlng = Math.Max(left.Lng, Math.Max(right.Lng, Math.Max(leftf.Lng, rightf.Lng)));
            double minlng = Math.Min(left.Lng, Math.Min(right.Lng, Math.Min(leftf.Lng, rightf.Lng)));

            area = RectLatLng.FromLTRB(minlng, maxlat, maxlng, minlat);

            GPoint topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
            GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
            GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            zoom = 17;

            // zoom based on pixel density
            while (pxDelta.X > 2000)
            {
                zoom--;

                // current area
                topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            }

            // update once per seconds - we only read from disk, so need to let cahce settle
            if (lastrefresh.AddSeconds(.6) < DateTime.Now)
            {
                // get tiles - bg
                core.Provider = type;
                core.Position = LocationCenter;
                core.Zoom = zoom;
                core.OnMapSizeChanged(this.Width, this.Height);

                lastrefresh = DateTime.Now;
            }
            else
            {
                //return;
            }

            MakeCurrent();


            GL.MatrixMode(MatrixMode.Projection);

            OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(130 * deg2rad, 1f, 0.00001f, (float)step * 100);
            GL.LoadMatrix(ref projection);

            Matrix4 modelview = Matrix4.LookAt((float)cameraX, (float)cameraY, (float)cameraZ, (float)lookX, (float)lookY, (float)lookZ, 0, 0, 1);
            GL.MatrixMode(MatrixMode.Modelview);

            // roll
            modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationZ(rpy.X * deg2rad));
            // pitch
            modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationX((rpy.Y - 10) * -deg2rad));

            GL.LoadMatrix(ref modelview);

            GL.ClearColor(Color.LightBlue);

            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 1f, 1f, 1f, 1f });

            GL.Enable(EnableCap.Fog);
            // GL.Enable(EnableCap.Lighting);
            // GL.Enable(EnableCap.Light0);

            GL.Fog(FogParameter.FogColor, new float[] { 0.5f, 0.5f, 0.5f, 1f });
            //GL.Fog(FogParameter.FogDensity,0.1f);
            GL.Fog(FogParameter.FogMode, (int)FogMode.Linear);
            GL.Fog(FogParameter.FogStart, (float)step * 1);
            GL.Fog(FogParameter.FogEnd, (float)(step * 7));

            /*
            GL.Begin(BeginMode.LineStrip);

            GL.Color3(Color.White);
            GL.Vertex3(0, 0, 0);

            GL.Vertex3(area.Bottom, 0, area.Left);

            GL.Vertex3(lookX, lookY, lookZ);

            //GL.Vertex3(cameraX, cameraY, cameraZ);

            GL.End();
            */

            GL.Begin(PrimitiveType.LineStrip);
            GL.PointSize(200);
            GL.Color3(Color.Red);
            //GL.Vertex3(new Vector3((float)center.Lng,(float)center.Lat,(float)(center.Alt * heightscale)));
            //GL.Vertex3(new Vector3(0, 0, 0));
            //GL.Vertex3(new Vector3((float)cameraX, (float)cameraY, (float)cameraZ));
            //GL.Color3(Color.Green);
            //GL.Vertex3(new Vector3((float)lookX, (float)lookY, (float)lookZ));

            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, 0);
            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationRightBottom.Lat, 0);
            GL.Vertex3(area.LocationRightBottom.Lng, area.LocationRightBottom.Lat, 0);
            GL.Vertex3(area.LocationRightBottom.Lng, area.LocationTopLeft.Lat, 0);
            GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, 0);

            GL.End();

            GL.Begin(PrimitiveType.LineStrip);
            GL.PointSize(200);
            GL.Color3(Color.Red);
            GL.Vertex3(new Vector3((float)center.Lng, (float)center.Lat, 0));
            GL.Vertex3(new Vector3((float)leftf.Lng, (float)leftf.Lat, 0));

            GL.End();

            GL.Begin(PrimitiveType.Points);
            GL.PointSize(100);
            GL.Color3(Color.Blue);
            GL.Vertex3(new Vector3((float)center.Lng, (float)center.Lat, 0));
            GL.End();

            //textureid.Clear();

            // get type list at new zoom level
            List<GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

             // get tiles & combine into one
            foreach (var p in tileArea)
            {
                core.tileDrawingListLock.AcquireReaderLock();
                core.Matrix.EnterReadLock();
                try
                {
                    GMap.NET.Internals.Tile t = core.Matrix.GetTileWithNoLock(core.Zoom, p);

                    if (t.NotEmpty)
                    {
                        foreach (GMapImage img in t.Overlays)
                        {
                            if (!textureid.ContainsKey(p))
                            {
                                generateTexture(p, (Bitmap)img.Img);
                            }
                        }
                    }
                    else
                    {

                    }
                }
                finally
                {
                    core.Matrix.LeaveReadLock();
                    core.tileDrawingListLock.ReleaseReaderLock();
                }

                //GMapImage tile = ((PureImageCache)Maps.MyImageCache.Instance).GetImageFromCache(type.DbId, p, zoom) as GMapImage;

                //if (tile != null && !textureid.ContainsKey(p))
                {
                  //  generateTexture(p, (Bitmap)tile.Img);
                }

                if (textureid.ContainsKey(p))
                {
                    int texture = textureid[p];

                    GL.Enable(EnableCap.Texture2D);
                    GL.BindTexture(TextureTarget.Texture2D, texture);

                }
                else
                {
                    GL.Disable(EnableCap.Texture2D);
                }

                long x = p.X * prj.TileSize.Width - topLeftPx.X;
                long y = p.Y * prj.TileSize.Width - topLeftPx.Y;

                long xr = p.X * prj.TileSize.Width;
                long yr = p.Y * prj.TileSize.Width;

                long x2 = (p.X+1) * prj.TileSize.Width;
                long y2 = (p.Y+1) * prj.TileSize.Width;

                // generate terrain
                GL.Begin(PrimitiveType.TriangleStrip);

                var latlng = prj.FromPixelToLatLng(xr,yr,zoom);

                double heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.Color3(Color.White);
                //xr - topLeftPx.X, yr - topLeftPx.Y
                GL.TexCoord2(0,0);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next down
                latlng = prj.FromPixelToLatLng(xr, y2, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(0,.99);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next right
                latlng = prj.FromPixelToLatLng(x2, yr, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(.99,0);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);


                // next right down
                latlng = prj.FromPixelToLatLng(x2, y2, zoom);

                heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt;

                GL.TexCoord2(.99,.99);
                GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale);

                GL.End();

            }


            GL.Enable(EnableCap.Blend);
            GL.DepthMask(false);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.One);
            GL.DepthMask(true);
            GL.Disable(EnableCap.Blend);

            GL.Flush();

            try
            {

                this.SwapBuffers();


                Context.MakeCurrent(null);
            }
            catch { }

            return;
        }
コード例 #5
0
            public override void OnRender(Graphics g)
            {
                base.OnRender(g);

                if (wprad == 0 || Overlay.Control == null)
                    return;

                // if we have drawn it, then keep that color
                if (!initcolor.HasValue)
                    Color = Color.White;

                //wprad = 300;

                // undo autochange in mouse over
                //if (Pen.Color == Color.Blue)
                //  Pen.Color = Color.White;

                double width = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Width, 0)) * 1000.0);
                double height = (Overlay.Control.MapProvider.Projection.GetDistance(Overlay.Control.FromLocalToLatLng(0, 0), Overlay.Control.FromLocalToLatLng(Overlay.Control.Height, 0)) * 1000.0);
                double m2pixelwidth = Overlay.Control.Width / width;
                double m2pixelheight = Overlay.Control.Height / height;

                GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * wprad * 2)), LocalPosition.Y);// MainMap.FromLatLngToLocal(wpradposition);

                //if (m2pixelheight > 0.5)
                    g.DrawArc(Pen, new System.Drawing.Rectangle(LocalPosition.X - Offset.X - (int)(Math.Abs(loc.X - LocalPosition.X) / 2), LocalPosition.Y - Offset.Y - (int)Math.Abs(loc.X - LocalPosition.X) / 2, (int)Math.Abs(loc.X - LocalPosition.X), (int)Math.Abs(loc.X - LocalPosition.X)), 0, 360);

                    g.FillPie(new SolidBrush(Color.FromArgb(25,Color.Red)), LocalPosition.X - Offset.X - (int)(Math.Abs(loc.X - LocalPosition.X) / 2), LocalPosition.Y - Offset.Y - (int)Math.Abs(loc.X - LocalPosition.X) / 2,  Math.Abs(loc.X - LocalPosition.X), Math.Abs(loc.X - LocalPosition.X), 0, 360);

            }
コード例 #6
0
        bool PureImageCache.PutImageToCache(byte[] tile, int type, GPoint pos, int zoom)
        {
            bool ret = true;
            if (Created)
            {
                try
                {
                    string file = CacheLocation + Path.DirectorySeparatorChar + GMapProviders.TryGetProvider(type).Name + Path.DirectorySeparatorChar + zoom + Path.DirectorySeparatorChar + pos.Y + Path.DirectorySeparatorChar + pos.X + ".jpg";
                    string dir = Path.GetDirectoryName(file);
                    Directory.CreateDirectory(dir);
                    using (BinaryWriter sw = new BinaryWriter(File.OpenWrite(file)))
                    {
                        sw.Write(tile.ToArray());
                    }
                }
                catch (Exception ex)
                {
#if MONO
            Console.WriteLine("PutImageToCache: " + ex.ToString());
#endif
                    Debug.WriteLine("PutImageToCache: " + ex.ToString());
                    ret = false;
                }
            }
            return ret;
        }
コード例 #7
0
        string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            string ret;

            ret = string.Format(CultureInfo.InvariantCulture, CustomURL + "&x={0}&y={1}&z={2}&s=", pos.X, pos.Y, zoom);

            return ret;
        }
コード例 #8
0
ファイル: Custom.cs プロジェクト: ArduPilot/MissionPlanner
        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            //string url = MakeTileImageUrl(pos, zoom, LanguageStr);

            //return GetTileImageUsingHttp(url);

            return null;
        }
コード例 #9
0
ファイル: Mapbox.cs プロジェクト: xqiu35/Senior_Design
        string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            string ret;

            ret = string.Format(CultureInfo.InvariantCulture, CustomURL, pos.X, pos.Y, zoom, mapsource, mapkey);

            return ret;
        }
コード例 #10
0
 public void ConvertCoordGroundToPixel(double GroundX, double GroundY, ref int PixelX, ref int PixelY)
 {
     GMap.NET.PointLatLng Position = new GMap.NET.PointLatLng();
     Position.Lat = GroundY;
     Position.Lng = GroundX;
     GMap.NET.GPoint p = MyMainMap.FromLatLngToLocal(Position);
     PixelX = (int)p.X;
     PixelY = (int)p.Y;
 }
コード例 #11
0
        string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            string ret;

            this.RefererUrl = "http://www.norgeskart.no/";

            ret = string.Format(CultureInfo.InvariantCulture, CustomURL, zoom, pos.X, pos.Y);

            return ret;
        }
コード例 #12
0
 public override GMap.NET.PureImage GetTileImage(GMap.NET.GPoint pos, int zoom)
 {
     try
     {
         string url = MakeTileImageUrl(pos, zoom, LanguageStr);
         return(GetTileImageUsingHttp(url));
     }
     catch
     {
         return(null);
     }
 }
コード例 #13
0
        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            Console.Out.WriteLine("zoom = {0}, pos = {1}", zoom, pos);
            var imgStream = GetImgStreamForZoomPos(pos, zoom);
            if (imgStream == null) return null;

            var newStream = CopyStream(imgStream, true);
            var ret = TileImageProxy.FromStream(imgStream);
            ret.Data = newStream;
            ret.Data.Position = 0;
            newStream.Dispose();
            return ret;
        }
コード例 #14
0
        public WellDetailPopup(Form parent, BSE.Windows.Forms.Panel leftPanel, Well well, GPoint markerLocationOnParent, string dataConnString, Action<Well> updateMarkerPosition, Action<Well> deleteMarker)
        {
            this.FormClosing += Close_clicked;
            this.leftPanel = leftPanel;
            deleteMarkerAction = deleteMarker;
            updateMarkerPositionAction = updateMarkerPosition;
            connectionString = dataConnString;
            Owner = parent;
            StartPosition = FormStartPosition.Manual;
            Location = markerLocationOnParent;

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

            InitializeComponent();

            this.well = well;
            editLngBox.Text = well.Latitude;
            editLatBox.Text = well.Longitude;
            imageEditBackup = well.WellImage;
            wellImage.Image = well.WellImage;
            wellImage.SizeMode = PictureBoxSizeMode.Zoom;
        }
コード例 #15
0
ファイル: ImageHelper.cs プロジェクト: F1nZeR/CourseWork
 public static Stream TakePartFromOriginal(Bitmap img, GPoint pos)
 {
     const int size = 512;
     var brush = new SolidBrush(Color.White);
     var resizedImg = new Bitmap(ResizeTo(img, size, size));
     var bmp = new Bitmap(256, 256);
     var graph = Graphics.FromImage(bmp);
     graph.FillRectangle(brush, new RectangleF(0, 0, size, size));
     var offsetX = (int) pos.X*256;
     var offsetY = (int) pos.Y*256;
     for (int x = 0; x < 256; x++)
     {
         for (int y = 0; y < 256; y++)
         {
             var curX = x + offsetX;
             var curY = y + offsetY;
             bmp.SetPixel(x, y, resizedImg.GetPixel(curX, curY));
         }
     }
     var resultStream = new MemoryStream();
     bmp.Save(resultStream, img.RawFormat);
     return resultStream;
 }
コード例 #16
0
        public override PureImage GetTileImage(GPoint pos, int zoom)
        {
            var px1 = GDALProvider.Instance.Projection.FromTileXYToPixel(pos);
            var px2 = px1;

            px1.Offset(0, 0);
            PointLatLng p1 = GDALProvider.Instance.Projection.FromPixelToLatLng(px1, zoom);

            px2.Offset(GDALProvider.Instance.Projection.TileSize.Width, -GDALProvider.Instance.Projection.TileSize.Height);
            PointLatLng p2 = GDALProvider.Instance.Projection.FromPixelToLatLng(px2, zoom);

            var bmp = GDAL.GetBitmap(p1.Lng, p1.Lat, p2.Lng, p2.Lat, GDALProvider.Instance.Projection.TileSize.Width, GDALProvider.Instance.Projection.TileSize.Height);

            if (bmp == null)
            {
                return null;
            }

            var ms = new MemoryStream();

            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);

            return new GMapImage() { Img = bmp, Data = ms };
        }
コード例 #17
0
ファイル: common.cs プロジェクト: cooldragon1/mw-wingui
        public override void OnRender(Graphics g)
        {
            base.OnRender(g);

            if (wprad == 0 || MainMap == null)
                return;

            // undo autochange in mouse over
            if (Pen.Color == Color.Blue)
                Pen.Color = Color.White;

            double width = (MainMap.MapProvider.Projection.GetDistance(MainMap.FromLocalToLatLng(0, 0), MainMap.FromLocalToLatLng(MainMap.Width, 0)) * 1000.0);
            double height = (MainMap.MapProvider.Projection.GetDistance(MainMap.FromLocalToLatLng(0, 0), MainMap.FromLocalToLatLng(MainMap.Height, 0)) * 1000.0);
            double m2pixelwidth = MainMap.Width / width;
            double m2pixelheight = MainMap.Height / height;

            GPoint loc = new GPoint((int)(LocalPosition.X - (m2pixelwidth * wprad * 2)), LocalPosition.Y);// MainMap.FromLatLngToLocal(wpradposition);
            try
            {
                g.DrawArc(Pen, new System.Drawing.Rectangle((int)(LocalPosition.X - Offset.X - (Math.Abs(loc.X - LocalPosition.X) / 2)), (int)(LocalPosition.Y - Offset.Y - Math.Abs(loc.X - LocalPosition.X) / 2), (int)(Math.Abs(loc.X - LocalPosition.X)), (int)(Math.Abs(loc.X - LocalPosition.X))), 0, 360);
            }
            catch { }

        }
コード例 #18
0
        public String decode(Bitmap bitmap)
        {
            if (bitmap == null)
            {
                return null;
            }

            LuminanceSource source = new RGBLuminanceSource(bitmap, bitmap.Width, bitmap.Height);
            BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));

            try
            {
                Result result = this.reader.decode(binaryBitmap);

                if (result != null)
                {
                    String[] resultToken = result.Text.Split(';');

                    double lat = Convert.ToDouble(resultToken[0]);
                    double lng = Convert.ToDouble(resultToken[1]);

                    double distance = Convert.ToDouble(resultToken[2]);
                    GPoint pointA = new GPoint(Convert.ToInt32(result.ResultPoints[1].X), Convert.ToInt32(result.ResultPoints[1].Y));
                    GPoint pointB = new GPoint(Convert.ToInt32(result.ResultPoints[2].X), Convert.ToInt32(result.ResultPoints[2].Y));

                    MapOverlayForm.Instance.SetMapScale(pointA, pointB, distance);
                    MapOverlayForm.Instance.RotationAngle = Convert.ToSingle(this.computeRotation(result.ResultPoints));
                    MapOverlayForm.Instance.MoveMapToLocalPosition(this.computeCenter(result.ResultPoints), new GMap.NET.PointLatLng(lat, lng));
                }
                return result.Text;
            }
            catch (ReaderException)
            {
                return null;
            }
        }
コード例 #19
0
ファイル: WMSProvider.cs プロジェクト: duyisu/MissionPlanner
        string MakeTileImageUrl(GPoint pos, int zoom, string language)
        {
            var px1 = Projection.FromTileXYToPixel(pos);
            var px2 = px1;

            px1.Offset(0, Projection.TileSize.Height);
            PointLatLng p1 = Projection.FromPixelToLatLng(px1, zoom);

            px2.Offset(Projection.TileSize.Width, 0);
            PointLatLng p2 = Projection.FromPixelToLatLng(px2, zoom);

            string ret;

            string extra = "?";

            if (CustomWMSURL.Contains("?"))
                extra = "&";

            //if there is a layer, use it  
            if (szWmsLayer != "")
            {
                ret = string.Format(CultureInfo.InvariantCulture,
                    CustomWMSURL + extra + "VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&layers=" + szWmsLayer +
                    "&styles=&bbox={0},{1},{2},{3}&width={4}&height={5}&srs=EPSG:4326&format=image/png", p1.Lng, p1.Lat,
                    p2.Lng, p2.Lat, Projection.TileSize.Width, Projection.TileSize.Height);
            }
            else
            {
                ret = string.Format(CultureInfo.InvariantCulture,
                    CustomWMSURL + extra +
                    "VERSION=1.1.1&REQUEST=GetMap&SERVICE=WMS&styles=&bbox={0},{1},{2},{3}&width={4}&height={5}&srs=EPSG:4326&format=image/png",
                    p1.Lng, p1.Lat, p2.Lng, p2.Lat, Projection.TileSize.Width, Projection.TileSize.Height);
            }

            return ret;
        }
コード例 #20
0
        void generateTexture(GPoint point, Bitmap image)
        {
            int texture = 0;

            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvModeCombine.Replace);//Important, or wrong color on some computers

            GL.GenTextures(1, out texture);

            GL.BindTexture(TextureTarget.Texture2D, texture);

            BitmapData data = image.LockBits(new System.Drawing.Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);

            image.UnlockBits(data);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

            GL.Finish();

          

            image.Dispose();

            textureid[point] = texture;
        }
コード例 #21
0
ファイル: GPoint.cs プロジェクト: artifact113/matsps
 public void OffsetNegative(GPoint p)
 {
     Offset(-p.X, -p.Y);
 }
コード例 #22
0
ファイル: GPoint.cs プロジェクト: artifact113/matsps
 public static GPoint Add(GPoint pt, GSize sz)
 {
     return(new GPoint(pt.X + sz.Width, pt.Y + sz.Height));
 }
コード例 #23
0
 private string MakeTileImageUrl(GPoint pos, int zoom, string language)
 {
     string str = string.Format(UrlFormat, pos.X, pos.Y, zoom);
     Console.WriteLine("url:" + str);
     return str;
 }
コード例 #24
0
ファイル: MySQLPureImageCache.cs プロジェクト: Jeffiy/ypmap
        public bool PutImageToCache(MemoryStream tile, MapType type, GPoint pos, int zoom)
        {
            bool ret = true;
             {
            if(Initialize())
            {
               try
               {
                  lock(cmdInsert)
                  {
                     cnSet.Ping();

                     if(cnSet.State != ConnectionState.Open)
                     {
                        cnSet.Open();
                     }

                     cmdInsert.Parameters["@type"].Value = (int)type;
                     cmdInsert.Parameters["@zoom"].Value = zoom;
                     cmdInsert.Parameters["@x"].Value = pos.X;
                     cmdInsert.Parameters["@y"].Value = pos.Y;
                     cmdInsert.Parameters["@tile"].Value = tile.GetBuffer();
                     cmdInsert.ExecuteNonQuery();
                  }
               }
               catch(Exception ex)
               {
                  Debug.WriteLine(ex.ToString());
                  ret = false;
                  Dispose();
               }
            }
             }
             return ret;
        }
コード例 #25
0
ファイル: StaticImage.cs プロジェクト: Saroko-dnd/My_DZ
      void bg_DoWork(object sender, DoWorkEventArgs e)
      {
         MapInfo info = (MapInfo)e.Argument;
         if(!info.Area.IsEmpty)
         {
            //var types = GMaps.Instance.GetAllLayersOfType(info.Type);

            string bigImage = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + Path.DirectorySeparatorChar + "GMap at zoom " + info.Zoom + " - " + info.Type + "-" + DateTime.Now.Ticks + ".png";
            e.Result = bigImage;

            // current area
            GPoint topLeftPx = info.Type.Projection.FromLatLngToPixel(info.Area.LocationTopLeft, info.Zoom);
            GPoint rightButtomPx = info.Type.Projection.FromLatLngToPixel(info.Area.Bottom, info.Area.Right, info.Zoom);
            GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);
            GMap.NET.GSize maxOfTiles = info.Type.Projection.GetTileMatrixMaxXY(info.Zoom);

            int padding = info.MakeWorldFile ? 0 : 22;
            {
               using(Bitmap bmpDestination = new Bitmap((int)(pxDelta.X + padding * 2), (int)(pxDelta.Y + padding * 2)))
               {
                  using(Graphics gfx = Graphics.FromImage(bmpDestination))
                  {
                     gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
                     gfx.SmoothingMode = SmoothingMode.HighQuality;

                     int i = 0;

                     // get tiles & combine into one
                     lock(tileArea)
                     {
                        foreach(var p in tileArea)
                        {
                           if(bg.CancellationPending)
                           {
                              e.Cancel = true;
                              return;
                           }

                           int pc = (int)(((double)++i / tileArea.Count) * 100);
                           bg.ReportProgress(pc, p);

                           foreach(var tp in info.Type.Overlays)
                           {
                              Exception ex;
                              GMapImage tile;

                              // tile number inversion(BottomLeft -> TopLeft) for pergo maps
                              if(tp.InvertedAxisY)
                              {
                                 tile = GMaps.Instance.GetImageFrom(tp, new GPoint(p.X, maxOfTiles.Height - p.Y), info.Zoom, out ex) as GMapImage;
                              }
                              else // ok
                              {
                                 tile = GMaps.Instance.GetImageFrom(tp, p, info.Zoom, out ex) as GMapImage;
                              }

                              if(tile != null)
                              {
                                 using(tile)
                                 {
                                    long x = p.X * info.Type.Projection.TileSize.Width - topLeftPx.X + padding;
                                    long y = p.Y * info.Type.Projection.TileSize.Width - topLeftPx.Y + padding;
                                    {
                                       gfx.DrawImage(tile.Img, x, y, info.Type.Projection.TileSize.Width, info.Type.Projection.TileSize.Height);
                                    }
                                 }
                              }
                           }
                        }
                     }

                     // draw routes
                     {
                        foreach(GMapRoute r in Main.routes.Routes)
                        {
                           if(r.IsVisible)
                           {
                              using(GraphicsPath rp = new GraphicsPath())
                              {
                                 for(int j = 0; j < r.Points.Count; j++)
                                 {
                                    var pr = r.Points[j];
                                    GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom);

                                    px.Offset(padding, padding);
                                    px.Offset(-topLeftPx.X, -topLeftPx.Y);

                                    GPoint p2 = px;

                                    if(j == 0)
                                    {
                                       rp.AddLine(p2.X, p2.Y, p2.X, p2.Y);
                                    }
                                    else
                                    {
                                       System.Drawing.PointF p = rp.GetLastPoint();
                                       rp.AddLine(p.X, p.Y, p2.X, p2.Y);
                                    }
                                 }

                                 if(rp.PointCount > 0)
                                 {
                                    gfx.DrawPath(r.Stroke, rp);
                                 }
                              }
                           }
                        }
                     }

                     // draw polygons
                     {
                        foreach(GMapPolygon r in Main.polygons.Polygons)
                        {
                           if(r.IsVisible)
                           {
                              using(GraphicsPath rp = new GraphicsPath())
                              {
                                 for(int j = 0; j < r.Points.Count; j++)
                                 {
                                    var pr = r.Points[j];
                                    GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom);

                                    px.Offset(padding, padding);
                                    px.Offset(-topLeftPx.X, -topLeftPx.Y);

                                    GPoint p2 = px;

                                    if(j == 0)
                                    {
                                       rp.AddLine(p2.X, p2.Y, p2.X, p2.Y);
                                    }
                                    else
                                    {
                                       System.Drawing.PointF p = rp.GetLastPoint();
                                       rp.AddLine(p.X, p.Y, p2.X, p2.Y);
                                    }
                                 }

                                 if(rp.PointCount > 0)
                                 {
                                    rp.CloseFigure();

                                    gfx.FillPath(r.Fill, rp);

                                    gfx.DrawPath(r.Stroke, rp);
                                 }
                              }
                           }
                        }
                     }

                     // draw markers
                     {
                        foreach(GMapMarker r in Main.objects.Markers)
                        {
                           if(r.IsVisible)
                           {
                              var pr = r.Position;
                              GPoint px = info.Type.Projection.FromLatLngToPixel(pr.Lat, pr.Lng, info.Zoom);

                              px.Offset(padding, padding);
                              px.Offset(-topLeftPx.X, -topLeftPx.Y);
                              px.Offset(r.Offset.X, r.Offset.Y);

                              r.LocalPosition = new System.Drawing.Point((int)px.X, (int)px.Y);

                              r.OnRender(gfx);
                           }
                        }

                        // tooltips above
                        foreach(GMapMarker m in Main.objects.Markers)
                        {
                           if(m.IsVisible && m.ToolTip != null && m.IsVisible)
                           {
                              if(!string.IsNullOrEmpty(m.ToolTipText))
                              {
                                 m.ToolTip.OnRender(gfx);
                              }
                           }
                        }
                     }

                     // draw info
                     {
                        System.Drawing.Rectangle rect = new System.Drawing.Rectangle();
                        {
                           rect.Location = new System.Drawing.Point(padding, padding);
                           rect.Size = new System.Drawing.Size((int)pxDelta.X, (int)pxDelta.Y);
                        }

                        using(Font f = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold))
                        {
                           // draw bounds & coordinates
                           using(Pen p = new Pen(Brushes.DimGray, 3))
                           {
                              p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;

                              gfx.DrawRectangle(p, rect);

                              string topleft = info.Area.LocationTopLeft.ToString();
                              SizeF s = gfx.MeasureString(topleft, f);

                              gfx.DrawString(topleft, f, p.Brush, rect.X + s.Height / 2, rect.Y + s.Height / 2);

                              string rightBottom = new PointLatLng(info.Area.Bottom, info.Area.Right).ToString();
                              SizeF s2 = gfx.MeasureString(rightBottom, f);

                              gfx.DrawString(rightBottom, f, p.Brush, rect.Right - s2.Width - s2.Height / 2, rect.Bottom - s2.Height - s2.Height / 2);
                           }

                           // draw scale
                           using(Pen p = new Pen(Brushes.Blue, 1))
                           {
                              double rez = info.Type.Projection.GetGroundResolution(info.Zoom, info.Area.Bottom);
                              int px100 = (int)(100.0 / rez); // 100 meters
                              int px1000 = (int)(1000.0 / rez); // 1km   

                              gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px1000, 10);
                              gfx.DrawRectangle(p, rect.X + 10, rect.Bottom - 20, px100, 10);

                              string leftBottom = "scale: 100m | 1Km";
                              SizeF s = gfx.MeasureString(leftBottom, f);
                              gfx.DrawString(leftBottom, f, p.Brush, rect.X + 10, rect.Bottom - s.Height - 20);
                           }
                        }
                     }
                  }

                  bmpDestination.Save(bigImage, ImageFormat.Png);
               }
            }

            //The worldfile for the original image is:

            //0.000067897543      // the horizontal size of a pixel in coordinate units (longitude degrees in this case);
            //0.0000000
            //0.0000000
            //-0.0000554613012    // the comparable vertical pixel size in latitude degrees, negative because latitude decreases as you go from top to bottom in the image.
            //-111.743323868834   // longitude of the pixel in the upper-left-hand corner.
            //35.1254392635083    // latitude of the pixel in the upper-left-hand corner.

            // generate world file
            if(info.MakeWorldFile)
            {
               string wf = bigImage + "w";
               using(StreamWriter world = File.CreateText(wf))
               {
                  world.WriteLine("{0:0.000000000000}", (info.Area.WidthLng / pxDelta.X));
                  world.WriteLine("0.0000000");
                  world.WriteLine("0.0000000");
                  world.WriteLine("{0:0.000000000000}", (-info.Area.HeightLat / pxDelta.Y));
                  world.WriteLine("{0:0.000000000000}", info.Area.Left);
                  world.WriteLine("{0:0.000000000000}", info.Area.Top);
                  world.Close();
               }
            }
         }
      }
コード例 #26
0
ファイル: GRect.cs プロジェクト: Hogan2/MyMap
 public void OffsetNegative(GPoint pos)
 {
     Offset(-pos.X, -pos.Y);
 }
コード例 #27
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            while (!IsHandleCreated)
            {
                Thread.Sleep(100);
            }

            if (list != null)
            {
                list.Clear();
                list = null;
            }
            list       = provider.Projection.GetAreaTileList(area, zoom, 0);
            maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
            all        = list.Count;

            int countOk    = 0;
            int retryCount = 0;

            if (Shuffle)
            {
                Stuff.Shuffle <GPoint>(list);
            }

            lock (this)
            {
                CachedTiles.Clear();
            }

            for (int i = 0; i < all; i++)
            {
                if (worker.CancellationPending)
                {
                    break;
                }

                GPoint p = list[i];
                {
                    if (CacheTiles(zoom, p))
                    {
                        if (Overlay != null)
                        {
                            lock (this)
                            {
                                CachedTiles.Enqueue(p);
                            }
                        }
                        countOk++;
                        retryCount = 0;
                    }
                    else
                    {
                        if (++retryCount <= retry) // retry only one
                        {
                            i--;
                            System.Threading.Thread.Sleep(1111);
                            continue;
                        }
                        else
                        {
                            retryCount = 0;
                        }
                    }
                }

                worker.ReportProgress((int)((i + 1) * 100 / all), i + 1);

                if (sleep > 0)
                {
                    System.Threading.Thread.Sleep(sleep);
                }
            }

            e.Result = countOk;

            if (!IsDisposed)
            {
                try
                {
                    done.WaitOne();
                }
                catch { }
            }
        }
コード例 #28
0
ファイル: GMaps.cs プロジェクト: sonjk/Logistics
        /// <summary>
        /// gets image from tile server
        /// </summary>
        /// <param name="provider"></param>
        /// <param name="pos"></param>
        /// <param name="zoom"></param>
        /// <returns></returns>
        public PureImage GetImageFrom(GMapProvider provider, GPoint pos, int zoom, out Exception result)
        {
            PureImage ret = null;

            result = null;

            try {
                var rtile = new RawTile(provider.DbId, pos, zoom);

                // let't check memmory first
                if (UseMemoryCache)
                {
                    var m = MemoryCache.GetTileFromMemoryCache(rtile);
                    if (m != null)
                    {
                        if (GMapProvider.TileImageProxy != null)
                        {
                            ret = GMapProvider.TileImageProxy.FromArray(m);
                            if (ret == null)
                            {
#if DEBUG
                                Debug.WriteLine("Image disposed in MemoryCache o.O, should never happen ;} " + new RawTile(provider.DbId, pos, zoom));
                                if (Debugger.IsAttached)
                                {
                                    Debugger.Break();
                                }
#endif
                                m = null;
                            }
                        }
                    }
                }

                if (ret == null)
                {
                    if (Mode != AccessMode.ServerOnly && !provider.BypassCache)
                    {
                        if (PrimaryCache != null)
                        {
                            // hold writer for 5s
                            if (cacheOnIdleRead)
                            {
                                Interlocked.Exchange(ref readingCache, 5);
                            }

                            ret = PrimaryCache.GetImageFromCache(provider.DbId, pos, zoom);
                            if (ret != null)
                            {
                                if (UseMemoryCache)
                                {
                                    MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                                }
                                return(ret);
                            }
                        }

                        if (SecondaryCache != null)
                        {
                            // hold writer for 5s
                            if (cacheOnIdleRead)
                            {
                                Interlocked.Exchange(ref readingCache, 5);
                            }

                            ret = SecondaryCache.GetImageFromCache(provider.DbId, pos, zoom);
                            if (ret != null)
                            {
                                if (UseMemoryCache)
                                {
                                    MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                                }
                                EnqueueCacheTask(new CacheQueueItem(rtile, ret.Data.GetBuffer(), CacheUsage.First));
                                return(ret);
                            }
                        }
                    }

                    if (Mode != AccessMode.CacheOnly)
                    {
                        ret = provider.GetTileImage(pos, zoom);
                        {
                            // Enqueue Cache
                            if (ret != null)
                            {
                                if (UseMemoryCache)
                                {
                                    MemoryCache.AddTileToMemoryCache(rtile, ret.Data.GetBuffer());
                                }

                                if (Mode != AccessMode.ServerOnly && !provider.BypassCache)
                                {
                                    EnqueueCacheTask(new CacheQueueItem(rtile, ret.Data.GetBuffer(), CacheUsage.Both));
                                }
                            }
                        }
                    }
                    else
                    {
                        result = noDataException;
                    }
                }
            } catch (Exception ex) {
                result = ex;
                ret    = null;
                Debug.WriteLine("GetImageFrom: " + ex.ToString());
            }

            return(ret);
        }
コード例 #29
0
ファイル: PureProjection.cs プロジェクト: honfika/GMap.NET
 /// <summary>
 ///     gets pixel coordinate from tile coordinate
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public virtual GPoint FromTileXYToPixel(GPoint p)
 {
     return(new GPoint(p.X * TileSize.Width, p.Y * TileSize.Height));
 }
コード例 #30
0
ファイル: PureProjection.cs プロジェクト: honfika/GMap.NET
 /// <summary>
 ///     gets tile coorddinate from pixel coordinates
 /// </summary>
 /// <param name="p"></param>
 /// <returns></returns>
 public virtual GPoint FromPixelToTileXY(GPoint p)
 {
     return(new GPoint(p.X / TileSize.Width, p.Y / TileSize.Height));
 }
コード例 #31
0
ファイル: TilePrefetcher.cs プロジェクト: mikhp/greatmaps
      bool CacheTiles(int zoom, GPoint p)
      {
         foreach(var pr in provider.Overlays)
         {
            Exception ex;
            PureImage img;

            // tile number inversion(BottomLeft -> TopLeft)
            if(pr.InvertedAxisY)
            {
               img = GMaps.Instance.GetImageFrom(pr, new GPoint(p.X, maxOfTiles.Height - p.Y), zoom, out ex);
            }
            else // ok
            {
               img = GMaps.Instance.GetImageFrom(pr, p, zoom, out ex);
            }

            if(img != null)
            {
               img.Dispose();
               img = null;
            }
            else
            {
               return false;
            }
         }
         return true;
      }
コード例 #32
0
ファイル: GPoint.cs プロジェクト: artifact113/matsps
 public void Offset(GPoint p)
 {
     Offset(p.X, p.Y);
 }
コード例 #33
0
ファイル: MySQLPureImageCache.cs プロジェクト: Jeffiy/ypmap
        public PureImage GetImageFromCache(MapType type, GPoint pos, int zoom)
        {
            PureImage ret = null;
             {
            if(Initialize())
            {
               try
               {
                  object odata = null;
                  lock(cmdFetch)
                  {
                     cnGet.Ping();

                     if(cnGet.State != ConnectionState.Open)
                     {
                        cnGet.Open();
                     }

                     cmdFetch.Parameters["@type"].Value = (int)type;
                     cmdFetch.Parameters["@zoom"].Value = zoom;
                     cmdFetch.Parameters["@x"].Value = pos.X;
                     cmdFetch.Parameters["@y"].Value = pos.Y;
                     odata = cmdFetch.ExecuteScalar();
                  }

                  if(odata != null && odata != DBNull.Value)
                  {
                     byte[] tile = (byte[])odata;
                     if(tile != null && tile.Length > 0)
                     {
                        if(GMapProvider.TileImageProxy != null)
                        {
                           ret = GMapProvider.TileImageProxy.FromArray(tile);
                        }
                     }
                     tile = null;
                  }
               }
               catch(Exception ex)
               {
                  Debug.WriteLine(ex.ToString());
                  ret = null;
                  Dispose();
               }
            }
             }
             return ret;
        }
コード例 #34
0
        private void BUT_geinjection_Click(object sender, EventArgs e)
        {
            GMapControl MainMap = new GMapControl();

            MainMap.MapProvider = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;

            MainMap.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "/gmapcache/";

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            try
            {
                fbd.SelectedPath = @"C:\Users\hog\Documents\albany 2011\New folder";
            }
            catch { }

            if (fbd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            if (fbd.SelectedPath != "")
            {
                string[] files  = Directory.GetFiles(fbd.SelectedPath, "*.jpg", SearchOption.AllDirectories);
                string[] files1 = Directory.GetFiles(fbd.SelectedPath, "*.png", SearchOption.AllDirectories);

                int origlength = files.Length;
                Array.Resize(ref files, origlength + files1.Length);
                Array.Copy(files1, 0, files, origlength, files1.Length);

                foreach (string file in files)
                {
                    log.Info(DateTime.Now.Millisecond + " Doing " + file);
                    Regex reg = new Regex(@"Z([0-9]+)\\([0-9]+)\\([0-9]+)");

                    Match mat = reg.Match(file);

                    if (mat.Success == false)
                    {
                        continue;
                    }

                    int temp = 1 << int.Parse(mat.Groups[1].Value);

                    GMap.NET.GPoint pnt = new GMap.NET.GPoint(int.Parse(mat.Groups[3].Value), int.Parse(mat.Groups[2].Value));

                    BUT_geinjection.Text = file;
                    BUT_geinjection.Refresh();

                    //MainMap.Projection.

                    MemoryStream tile = new MemoryStream();

                    Image Img = Image.FromFile(file);
                    Img.Save(tile, System.Drawing.Imaging.ImageFormat.Jpeg);

                    tile.Seek(0, SeekOrigin.Begin);
                    log.Info(pnt.X + " " + pnt.Y);

                    Application.DoEvents();

                    GMaps.Instance.PrimaryCache.PutImageToCache(tile.ToArray(), Maps.Custom.Instance.DbId, pnt, int.Parse(mat.Groups[1].Value));

                    // Application.DoEvents();
                }
            }
        }
コード例 #35
0
 public override PureImage GetTileImage(GPoint pos, int zoom)
 {
     string url = this.MakeTileImageUrl(pos, zoom, GMapProvider.LanguageStr);
     return base.GetTileImageUsingHttp(url);
 }
コード例 #36
0
ファイル: GRect.cs プロジェクト: Hogan2/MyMap
 public void Offset(GPoint pos)
 {
     Offset(pos.X, pos.Y);
 }
コード例 #37
0
ファイル: GPoint.cs プロジェクト: artifact113/matsps
 public static GPoint Subtract(GPoint pt, GSize sz)
 {
     return(new GPoint(pt.X - sz.Width, pt.Y - sz.Height));
 }
コード例 #38
0
ファイル: GRect.cs プロジェクト: Hogan2/MyMap
 public bool Contains(GPoint pt)
 {
     return(Contains(pt.X, pt.Y));
 }
コード例 #39
0
ファイル: GPoint.cs プロジェクト: Jeffiy/ypmap
 public void OffsetNegative(GPoint p)
 {
     Offset(-p.X, -p.Y);
 }
コード例 #40
0
ファイル: GSize.cs プロジェクト: OOP-03376400/Software
 public GSize(GPoint pt)
 {
     width  = pt.X;
     height = pt.Y;
 }
コード例 #41
0
ファイル: temp.cs プロジェクト: jchevin/MissionPlanner-master
        private void BUT_geinjection_Click(object sender, EventArgs e)
        {
            GMapControl MainMap = new GMapControl();

            MainMap.MapProvider = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;

            MainMap.CacheLocation = Path.GetDirectoryName(Application.ExecutablePath) + "/gmapcache/";

            FolderBrowserDialog fbd = new FolderBrowserDialog();

            try
            {
                fbd.SelectedPath = @"C:\Users\hog\Documents\albany 2011\New folder";
            }
            catch { }

            if (fbd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                return;

            if (fbd.SelectedPath != "")
            {

                string[] files = Directory.GetFiles(fbd.SelectedPath,"*.jpg",SearchOption.AllDirectories);
                string[] files1 = Directory.GetFiles(fbd.SelectedPath, "*.png", SearchOption.AllDirectories);

                int origlength = files.Length;
                Array.Resize(ref files, origlength + files1.Length);
                Array.Copy(files1, 0, files, origlength, files1.Length);

                foreach (string file in files)
                {
                    log.Info(DateTime.Now.Millisecond +  " Doing "+ file);
                    Regex reg = new Regex(@"Z([0-9]+)\\([0-9]+)\\([0-9]+)");

                    Match mat = reg.Match(file);

                    if (mat.Success == false)
                        continue;

                    int temp = 1 << int.Parse(mat.Groups[1].Value);

                    GMap.NET.GPoint pnt = new GMap.NET.GPoint(int.Parse(mat.Groups[3].Value), int.Parse(mat.Groups[2].Value));

                    BUT_geinjection.Text = file;
                    BUT_geinjection.Refresh();

                    //MainMap.Projection.

                    MemoryStream tile = new MemoryStream();

                    Image Img = Image.FromFile(file);
                    Img.Save(tile,System.Drawing.Imaging.ImageFormat.Jpeg);

                    tile.Seek(0, SeekOrigin.Begin);
                    log.Info(pnt.X + " " + pnt.Y);

                    Application.DoEvents();

                    GMaps.Instance.PrimaryCache.PutImageToCache(tile.ToArray(), Maps.Custom.Instance.DbId, pnt, int.Parse(mat.Groups[1].Value));

                   // Application.DoEvents();
                }
            }
        }
コード例 #42
0
        void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            if (list != null)
            {
                list.Clear();
                list = null;
            }
            if (!area.IsEmpty)
            {
                list = provider.Projection.GetAreaTileList(area, zoom, 0);
            }
            else
            {
                list = provider.Projection.GetAreaTileList1(area1, zoom, 0);
            }
            maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom);
            all        = list.Count;

            int countOk    = 0;
            int retryCount = 0;

            if (Shuffle)
            {
                Stuff.Shuffle <GPoint>(list);
            }

            lock (this)
            {
                CachedTiles.Clear();
            }

            if (all < MyProcessThreadCount)//小数据量不用开线程
            {
                for (int i = 0; i < all; i++)
                {
                    if (worker.CancellationPending)
                    {
                        break;
                    }

                    GPoint p = list[i];
                    {
                        if (CacheTiles(zoom, p))
                        {
                            if (Overlay != null)
                            {
                                lock (this)
                                {
                                    CachedTiles.Enqueue(p);
                                }
                            }
                            countOk++;
                            retryCount = 0;
                        }
                        else
                        {
                            if (++retryCount <= retry) // retry only one
                            {
                                i--;
                                System.Threading.Thread.Sleep(1111);
                                continue;
                            }
                            else
                            {
                                retryCount = 0;
                            }
                        }
                    }
                    worker.ReportProgress((int)((i + 1) * 100 / all), i + 1);

                    if (sleep > 0)
                    {
                        System.Threading.Thread.Sleep(sleep);
                    }
                }
            }
            else
            {
                int threadCount = all / MyProcessThreadCount;
                threadCount = threadCount > MyProcessThreadCount ? MyProcessThreadCount : threadCount;
                int step = all / threadCount;
                int last = all % threadCount;
                MyThreadData.ProcessCount = 0;
                for (int i = 0; i < threadCount; i++)
                {
                    ParameterizedThreadStart ParStart = new ParameterizedThreadStart(ThreadMethod);
                    int start = i * step;
                    int end   = (i + 1) * step;
                    if (i == threadCount - 1)
                    {
                        end += last;
                    }
                    MyThreadData data     = new MyThreadData(start, end);
                    Thread       myThread = new Thread(ParStart);
                    myThread.Start(data);
                }
                while (true)
                {
                    if (MyThreadData.ThreadDataExist > 0)
                    {
                        System.Threading.Thread.Sleep(100);
                        int percent = (int)((MyThreadData.ProcessCount) * 100 / all);

                        worker.ReportProgress(percent > 101 ? 100 : percent, MyThreadData.ProcessCount > all ? all : MyThreadData.ProcessCount);
                    }
                    else
                    {
                        break;
                    }
                }
            }
            e.Result = countOk;

            if (!IsDisposed)
            {
                done.WaitOne();
            }
        }
コード例 #43
0
ファイル: LogMap.cs プロジェクト: RabidCicada/senior-design
        static Bitmap GetMap(RectLatLng area)
        {
            GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance;
            PureProjection prj = type.Projection;

            int zoom = 16;

            GPoint topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
            GPoint rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
            GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            // zoom based on pixel density
            while (pxDelta.X > 2000)
            {
                zoom--;

                // current area
                topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, zoom);
                rightButtomPx = prj.FromLatLngToPixel(area.Bottom, area.Right, zoom);
                pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y);

            }

            // get type list at new zoom level
            List<GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0);

            int padding = 10;

            Bitmap bmpDestination = new Bitmap((int)pxDelta.X + padding * 2, (int)pxDelta.Y + padding * 2);

            {
                using (Graphics gfx = Graphics.FromImage(bmpDestination))
                {
                    gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

                    // get tiles & combine into one
                    foreach (var p in tileArea)
                    {
                        Console.WriteLine("Downloading[" + p + "]: " + tileArea.IndexOf(p) + " of " + tileArea.Count);

                        foreach (var tp in type.Overlays)
                        {
                            Exception ex;
                            GMapImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage;

                            if (tile != null)
                            {
                                using (tile)
                                {
                                    long x = p.X * prj.TileSize.Width - topLeftPx.X + padding;
                                    long y = p.Y * prj.TileSize.Width - topLeftPx.Y + padding;
                                    {
                                        gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height);
                                    }
                                }
                            }
                        }
                    }
                }

                return bmpDestination;
            }
        }
コード例 #44
0
ファイル: PureProjection.cs プロジェクト: honfika/GMap.NET
 public PointLatLng FromPixelToLatLng(GPoint p, int zoom)
 {
     return(FromPixelToLatLng(p, zoom, false));
 }
コード例 #45
0
ファイル: GPoint.cs プロジェクト: LeoTosti/x-drone
 public static GPoint Subtract(GPoint pt, GSize sz)
 {
     return new GPoint(pt.X - sz.Width, pt.Y - sz.Height);
 }
コード例 #46
0
ファイル: GPoint.cs プロジェクト: LeoTosti/x-drone
 public void Offset(GPoint p)
 {
     Offset(p.X, p.Y);
 }
コード例 #47
-1
ファイル: GPoint.cs プロジェクト: LeoTosti/x-drone
 public static GPoint Add(GPoint pt, GSize sz)
 {
     return new GPoint(pt.X + sz.Width, pt.Y + sz.Height);
 }