public MapInfo(PureProjection Projection, RectLatLng Area, int Zoom, MapType Type) { this.Projection = Projection; this.Area = Area; this.Zoom = Zoom; this.Type = Type; }
public MapInfo(PureProjection Projection, RectLatLng Area, int Zoom, MapType Type, bool makeWorldFile) { this.Projection = Projection; this.Area = Area; this.Zoom = Zoom; this.Type = Type; this.MakeWorldFile = makeWorldFile; }
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { PureProjection proj = map.MapProvider.Projection; GSize size1 = proj.GetTileMatrixSizeXY(1); GSize sizeCurrent = proj.GetTileMatrixSizeXY((int)(double)value); return(sizeCurrent.Width / (double)size1.Width * 0.001); }
/// <summary> /// gets tiles count in rect at specific zoom /// </summary> public int GetAreaTileCount(PureProjection projection, RectLatLng rect, int zoom, int padding) { GPoint topLeft = projection.FromPixelToTileXY(projection.FromLatLngToPixel(rect.LocationTopLeft, zoom)); GPoint rightBottom = projection.FromPixelToTileXY(projection.FromLatLngToPixel(rect.LocationRightBottom, zoom)); return((int)(((rightBottom.X + padding) - (topLeft.X - padding) + 1) * ((rightBottom.Y + padding) - (topLeft.Y - padding) + 1))); }
public override GPoint FromLatLngToPixel(double lat, double lng, int zoom) { GPoint empty = GPoint.Empty; lat = PureProjection.Clip(lat, this.MinLatitude, this.MaxLatitude); lng = PureProjection.Clip(lng, this.MinLongitude, this.MaxLongitude); double tileMatrixResolution = GetTileMatrixResolution(zoom); empty.X = (long)Math.Round((double)((lng - orignX) / tileMatrixResolution)); empty.Y = (long)Math.Round((double)((orignY - lat) / tileMatrixResolution)); return(this.RectiryPixelPoint(empty)); }
/// <summary> /// 下载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnDownload_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSaveFolder.Text)) { MessageBox.Show("保存路径不能为空"); btnSaveFolder.Focus(); return; } if (!Util.Validation.IsNumber(txtMinLongitude.Text) || !Util.Validation.IsNumber(txtMaxLongitude.Text) || !Util.Validation.IsNumber(txtMinLatitude.Text) || !Util.Validation.IsNumber(txtMaxLatitude.Text)) { MessageBox.Show("坐标格式不正确"); return; } PureProjection proj = mapControl.MapProvider.Projection; int zoom = Convert.ToInt32(mapControl.Zoom); GSize minOfTiles = proj.GetTileMatrixMinXY(zoom); GSize maxOfTiles = proj.GetTileMatrixMaxXY(zoom); PointLatLng position = new PointLatLng(double.Parse(txtMinLatitude.Text), double.Parse(txtMinLongitude.Text)); PointLatLng position1 = new PointLatLng(double.Parse(txtMaxLatitude.Text), double.Parse(txtMaxLongitude.Text)); Core.MapPoint minPoint = new Core.MapPoint() { X = position.Lng, Y = position.Lat }; Core.MapPoint maxPoint = new Core.MapPoint() { X = position1.Lng, Y = position1.Lat }; Core.Log.Clear(logFile); downloader = new Core.Provider.GoogleChinaMapDownloader( new Core.Extent(minPoint.X, minPoint.Y, maxPoint.X, maxPoint.Y), int.Parse(txtMinZoom.Text), int.Parse(txtMaxZoom.Text) ) { SavePath = txtSaveFolder.Text }; downloader.TileDownloadCompleted += TileDownloadCompleted; downloader.DownloadCompleted += DownloadCompleted; downloader.BeginDownload(); statusbar_progress.Visible = true; statusbar_progress.Maximum = 100; statusbar_status.Text = "下载中......"; }
public static PointLatLng FindPointByDistanceAndRadians(PointLatLng startPoint, double initialRadians, double distanceKilometers) { const double radiusEarthKilometers = 6371.01d; var distRatio = distanceKilometers / radiusEarthKilometers; var distRatioSine = Math.Sin(distRatio); var distRatioCosine = Math.Cos(distRatio); var startLatRad = PureProjection.DegreesToRadians(startPoint.Lat); var startLonRad = PureProjection.DegreesToRadians(startPoint.Lng); var startLatCos = Math.Cos(startLatRad); var startLatSin = Math.Sin(startLatRad); var endLatRads = Math.Asin((startLatSin * distRatioCosine) + (startLatCos * distRatioSine * Math.Cos(initialRadians))); var endLonRads = startLonRad + Math.Atan2(Math.Sin(initialRadians) * distRatioSine * startLatCos, distRatioCosine - startLatSin * Math.Sin(endLatRads)); return(new PointLatLng(PureProjection.RadiansToDegrees(endLatRads), PureProjection.RadiansToDegrees(endLonRads))); }
public void Start(RectLatLng area, PureProjection prj, int zoom, MapType type, int sleep) { if (!worker.IsBusy) { this.label1.Content = "..."; this.progressBar1.Value = 0; this.prj = prj; this.area = area; this.zoom = zoom; this.type = type; this.sleep = sleep; GMaps.Instance.UseMemoryCache = false; worker.RunWorkerAsync(); this.ShowDialog(); } }
public OpenGLtest2() { instance = this; InitializeComponent(); core.OnMapOpen(); type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance; prj = type.Projection; this.Invalidate(); Thread bg = new Thread(imageLoader) { IsBackground = true }; bg.Start(); }
public override GPoint FromLatLngToPixel(double lat, double lng, int zoom) { double[] latlng = new double[2]; this.transform(lat, lng, latlng); lat = latlng[0]; lng = latlng[1]; GPoint empty = GPoint.Empty; lat = PureProjection.Clip(lat, MinLatitude, MaxLatitude); lng = PureProjection.Clip(lng, MinLongitude, MaxLongitude); double num = (lng + 180.0) / 360.0; double num2 = Math.Sin((lat * 3.1415926535897931) / 180.0); double num3 = 0.5 - (Math.Log((1.0 + num2) / (1.0 - num2)) / 12.566370614359172); GSize tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom); long width = tileMatrixSizePixel.Width; long height = tileMatrixSizePixel.Height; empty.X = (long)PureProjection.Clip((num * width) + 0.5, 0.0, (double)(width - 1L)); empty.Y = (long)PureProjection.Clip((num3 * height) + 0.5, 0.0, (double)(height - 1L)); return(empty); }
public override PointLatLng FromPixelToLatLng(long x, long y, int zoom) { PointLatLng empty = PointLatLng.Empty; GSize tileMatrixSizePixel = this.GetTileMatrixSizePixel(zoom); double width = tileMatrixSizePixel.Width; double height = tileMatrixSizePixel.Height; double num3 = (PureProjection.Clip((double)x, 0.0, width - 1.0) / width) - 0.5; double num4 = 0.5 - (PureProjection.Clip((double)y, 0.0, height - 1.0) / height); empty.Lat = 90.0 - ((360.0 * Math.Atan(Math.Exp((-num4 * 2.0) * 3.1415926535897931))) / 3.1415926535897931); empty.Lng = 360.0 * num3; PointLatLng lng2 = new PointLatLng(); double[] latlng = new double[2]; this.transform(empty.Lat, empty.Lng, latlng); lng2.Lat = latlng[0]; lng2.Lng = latlng[1]; empty.Lat -= lng2.Lat - empty.Lat; empty.Lng -= lng2.Lng - empty.Lng; return(empty); }
public override void OnRender(Graphics g) { double num = (double)this.radius; PureProjection projection = base.Overlay.Control.MapProvider.Projection; int zoom = checked ((int)base.Overlay.Control.Zoom); PointLatLng position = base.Position; float r = (float)(num / projection.GetGroundResolution(zoom, position.Lat)); Point localPosition = base.LocalPosition; float x = (float)localPosition.X - r; localPosition = base.LocalPosition; RectangleF rect = new RectangleF(x, (float)localPosition.Y - r, 2f * r, 2f * r); this.path = new GraphicsPath(); this.path.AddEllipse(rect); this.pthGrBrush = new PathGradientBrush(this.path) { CenterColor = Color.FromArgb(86, Color.DarkOrange) }; Color[] colorArray = new Color[] { Color.FromArgb(0, Color.Transparent) }; this.pthGrBrush.SurroundColors = colorArray; g.FillEllipse(this.pthGrBrush, rect); g.DrawEllipse(this.Stroke, rect); }
public GroundTruthImporter(PureProjection aProjection) { mProjection = aProjection; OriginMarker = null; OtherReferencePoint = null; }
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 = 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; using (var tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex)) { 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; { try { tile.Data.Position = 0; gfx.DrawImage(Image.FromStream(tile.Data), x, y, prj.TileSize.Width, prj.TileSize.Height); } catch (Exception ex2) { } } } } } } } } return(bmpDestination); } }
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)) ? (srtm.getAltitude(center.Lat, center.Lng) + 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); 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); 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); 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); 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; }
public GridExporter(PureProjection aProjection) { OriginMarker = null; OtherReferencePoint = null; mProjection = aProjection; }
void getImage() { GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance; PureProjection prj = type.Projection; //GMap.NET.GMaps.Instance.GetImageFrom(); DateTime startimage = DateTime.Now; if (!area.IsEmpty) { try { //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 = type; // GMaps.Instance.GetAllLayersOfType(type); // max zoom level zoom = 20; 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 tiles - bg core.Provider = type; core.Position = LocationCenter; core.Zoom = zoom; // get type list at new zoom level List <GPoint> tileArea = prj.GetAreaTileList(area, zoom, 0); //this.Invalidate(); Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); int padding = 0; { using ( Bitmap bmpDestination = new Bitmap((int)pxDelta.X + padding * 2, (int)pxDelta.Y + padding * 2) ) { Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); using (Graphics gfx = Graphics.FromImage(bmpDestination)) { Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); gfx.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver; gfx.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighSpeed; gfx.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighSpeed; // 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) { Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); GMapImage tile = ((PureImageCache)Maps.MyImageCache.Instance).GetImageFromCache(type.DbId, p, zoom) as GMapImage; //GMapImage tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage; //GMapImage tile = type.GetTileImage(p, zoom) as GMapImage; //tile.Img.Save(zoom + "-" + p.X + "-" + p.Y + ".bmp"); 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; { Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); gfx.DrawImage(tile.Img, x, y, prj.TileSize.Width, prj.TileSize.Height); Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); } } } else { } } } } Console.WriteLine((startimage - DateTime.Now).TotalMilliseconds); _terrain = new Bitmap(bmpDestination, 1024 * 2, 1024 * 2); // _terrain.Save(zoom +"-map.bmp"); 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); } } } catch (Exception ex) { Console.WriteLine(ex); } } }
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) * 1; float yawradians = (float)(Math.PI * (rpy.Z * 1) / 180.0f); //radians = 0; float mouseY = (float)step / 10f; cameraX = center.Lng; // -Math.Sin(yawradians) * mouseY; // multiplying by mouseY makes the cameraY = center.Lat; // -Math.Cos(yawradians) * mouseY; // camera get closer/farther away with mouseY cameraZ = (center.Alt < srtm.getAltitude(center.Lat, center.Lng).alt) ? (srtm.getAltitude(center.Lat, center.Lng).alt + 1) * heightscale : center.Alt * heightscale; // (srtm.getAltitude(lookZ, lookX, 20) + 100) * heighscale; lookX = center.Lng + Math.Sin(yawradians) * mouseY; lookY = center.Lat + Math.Cos(yawradians) * mouseY; lookZ = cameraZ; // cameraZ += 0.04; GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance; PureProjection prj = type.Projection; int size = (int)(cameraZ * 150000); // in front PointLatLngAlt leftf = center.newpos(rpy.Z, size); // behind PointLatLngAlt rightf = center.newpos(rpy.Z, 50); // left : 90 allows for 180 degree viewing angle PointLatLngAlt left = center.newpos(rpy.Z - 90, size); // right PointLatLngAlt right = center.newpos(rpy.Z + 90, size); 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))); // if (Math.Abs(area.Lat - maxlat) < 0.001) { } // else { 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 = 21; pxDelta.X = 9999; int otherzoomlevel = 12; // zoom based on pixel density while (pxDelta.X > this.Width) { 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); } otherzoomlevel = zoom - 4; Console.WriteLine("zoom {0}", zoom); // update once per seconds - we only read from disk, so need to let cahce settle if (lastrefresh.AddSeconds(0.5) < DateTime.Now) { // get tiles - bg core.Provider = type; core.Position = LocationCenter; // get zoom 10 core.Zoom = otherzoomlevel; core.OnMapSizeChanged(this.Width, this.Height); // get actual current zoom core.Zoom = zoom; core.OnMapSizeChanged(this.Width, this.Height); lastrefresh = DateTime.Now; } else { //return; } float screenscale = this.Width / (float)this.Height; MakeCurrent(); GL.MatrixMode(MatrixMode.Projection); OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView(120 * deg2rad, screenscale, 0.00001f, (float)step * 20000); 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 - 15) * -deg2rad)); GL.LoadMatrix(ref modelview); GL.ClearColor(Color.CornflowerBlue); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.AccumBufferBit); GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 1f, 1f, 1f, 1f }); // GL.Disable(EnableCap.Fog); GL.Enable(EnableCap.Fog); //GL.Enable(EnableCap.Lighting); //GL.Enable(EnableCap.Light0); GL.Fog(FogParameter.FogColor, new float[] { 100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 1f }); //GL.Fog(FogParameter.FogDensity,0.1f); GL.Fog(FogParameter.FogMode, (int)FogMode.Linear); GL.Fog(FogParameter.FogStart, (float)step * 40); GL.Fog(FogParameter.FogEnd, (float)(step * 50)); // GL.Enable(EnableCap.DepthTest); GL.DepthFunc(DepthFunction.Always); /* * GL.Begin(BeginMode.LineStrip); * * GL.Color3(Color.White); * GL.Vertex3(0, 0, 0); * * //GL.Color3(Color.Red); * GL.Vertex3(area.Bottom, 0, area.Left); * * //GL.Color3(Color.Yellow); * GL.Vertex3(lookX, lookY, lookZ); * * //GL.Color3(Color.Green); * GL.Vertex3(cameraX, cameraY, cameraZ); * * GL.End(); */ /* * GL.PointSize(10); * GL.Color4(Color.Yellow); * GL.LineWidth(5); * * * GL.Begin(PrimitiveType.LineStrip); * * //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, (float)cameraZ); * GL.Vertex3(area.LocationTopLeft.Lng, area.LocationRightBottom.Lat, (float)cameraZ); * GL.Vertex3(area.LocationRightBottom.Lng, area.LocationRightBottom.Lat, (float)cameraZ); * GL.Vertex3(area.LocationRightBottom.Lng, area.LocationTopLeft.Lat, (float)cameraZ); * GL.Vertex3(area.LocationTopLeft.Lng, area.LocationTopLeft.Lat, (float)cameraZ); * * GL.End(); */ GL.Finish(); GL.PointSize((float)(step * 1)); GL.Color3(Color.Blue); GL.Begin(PrimitiveType.Points); GL.Vertex3(new Vector3((float)center.Lng, (float)center.Lat, (float)cameraZ)); GL.End(); //GL.ClampColor(ClampColorTarget.ClampReadColor, ClampColorMode.True); /* * GL.Enable(EnableCap.Blend); * GL.DepthMask(false); * GL.BlendFunc(BlendingFactorSrc.Zero, BlendingFactorDest.Src1Color); * GL.DepthMask(true); * GL.Disable(EnableCap.Blend); */ // textureid.Clear(); // get level 10 tiles List <GPoint> tileArea1 = prj.GetAreaTileList(area, otherzoomlevel, 1); // get type list at new zoom level List <GPoint> tileArea2 = prj.GetAreaTileList(area, zoom, 2); List <GPoint> tileArea = new List <GPoint>(); tileArea.AddRange(tileArea1); tileArea.AddRange(tileArea2); // get tiles & combine into one foreach (var p in tileArea) { int localzoom = zoom; core.tileDrawingListLock.AcquireReaderLock(); core.Matrix.EnterReadLock(); try { if (tileArea1.Contains(p)) { localzoom = otherzoomlevel; } topLeftPx = prj.FromLatLngToPixel(area.LocationTopLeft, localzoom); GMap.NET.Internals.Tile t = core.Matrix.GetTileWithNoLock(localzoom, 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 { //Console.WriteLine("Missing tile"); continue; } 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; GL.LineWidth(0); GL.Color3(Color.White); // generate terrain GL.Begin(PrimitiveType.TriangleStrip); var latlng = prj.FromPixelToLatLng(xr, yr, localzoom); double heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; if (localzoom == 10) { heightl = 0; } //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, localzoom); heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; if (localzoom == 10) { heightl = 0; } GL.TexCoord2(0, 1); GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale); // next right latlng = prj.FromPixelToLatLng(x2, yr, localzoom); heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; if (localzoom == 10) { heightl = 0; } GL.TexCoord2(1, 0); GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale); // next right down latlng = prj.FromPixelToLatLng(x2, y2, localzoom); heightl = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; if (localzoom == 10) { heightl = 0; } GL.TexCoord2(1, 1); GL.Vertex3(latlng.Lng, latlng.Lat, heightl * heightscale); GL.End(); } GL.Flush(); try { this.SwapBuffers(); Context.MakeCurrent(null); } catch { } //this.Invalidate(); return; }
void getImage() { MapType type = MapType.GoogleSatellite; PureProjection prj = null; int maxZoom; GMaps.Instance.AdjustProjection(type, ref prj, out maxZoom); int zoom = 11; // 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); 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); } } } } } } _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); } } } catch { } } }
public ContactFuser(PureProjection aProjection) { mProjection = aProjection; mEpsilon = 10.0F; // distance in cm }
void getImage() { GMapProvider type = GMap.NET.MapProviders.GoogleSatelliteMapProvider.Instance; PureProjection prj = type.Projection; 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 = type;// 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((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 (GMapProvider tp in types) { GMapImage tile = type.GetTileImage(p, zoom) 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); } } } } 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 { } } }