void GmapWidget_MotionNotifyEvent(object o, Gtk.MotionNotifyEventArgs args) { if (gmapWidget.IsMouseOverRoute) { GPoint tl = new GPoint((long)args.Event.X - 4, (long)args.Event.Y - 4); var TLPoint = gmapWidget.FromLocalToLatLng(tl); GPoint br = new GPoint((long)args.Event.X + 4, (long)args.Event.Y + 4); var BRPoint = gmapWidget.FromLocalToLatLng(br); GPoint mouse = new GPoint((long)args.Event.X, (long)args.Event.Y); var geopoint = gmapWidget.FromLocalToLatLng(mouse); var rect = RectLatLng.FromLTRB(TLPoint.Lng, TLPoint.Lat, BRPoint.Lng, BRPoint.Lat); var nearest = track.TrackPoints .Where(x => rect.Contains(x.Latitude, x.Longitude)) .OrderBy(x => GMapProviders.EmptyProvider.Projection.GetDistance(geopoint, new PointLatLng(x.Latitude, x.Longitude))) .FirstOrDefault(); if (nearest != null) { ylabelPoint.LabelProp = String.Format("(ш.{0:F6} д.{1:F6}) - {2:T}", nearest.Latitude, nearest.Longitude, nearest.TimeStamp); } else { ylabelPoint.LabelProp = String.Empty; } } else { ylabelPoint.LabelProp = String.Empty; } }
public void 定位(List <M经纬度> __位置列表) { if (this.InvokeRequired) { this.BeginInvoke(new Action <List <M经纬度> >(定位), __位置列表); return; } if (__位置列表.Count == 1) { this.out地图控件.Position = GPS转换(__位置列表[0]); } else { double __最小经度 = 180; double __最大经度 = -180; double __最小纬度 = 90; double __最大纬度 = -90; __位置列表.ForEach(q => { __最小经度 = Math.Min(__最小经度, q.经度); __最大经度 = Math.Max(__最大经度, q.经度); __最小纬度 = Math.Min(__最小纬度, q.纬度); __最大纬度 = Math.Max(__最大纬度, q.纬度); }); var __左上 = GPS转换(new M经纬度(__最小经度, __最大纬度)); var __右下 = GPS转换(new M经纬度(__最大经度, __最小纬度)); this.out地图控件.SetZoomToFitRect(RectLatLng.FromLTRB(__左上.Lng, __左上.Lat, __右下.Lng, __右下.Lat)); } }
public RectLatLng?GetRectOfAllMarkers() { //стремная, слегка измененная(чтобы учитывать невилимые/сгруппированные точки) копипаста из MapControl RectLatLng?rect = null; var leftLng = double.MaxValue; var topLat = double.MinValue; var rightLng = double.MinValue; var bottomLat = double.MaxValue; foreach (var marker in _gMap.Markers.OfType <MapMarker>().Where(m => m.IsVisible)) { if (marker.Position.Lng < leftLng) { leftLng = marker.Position.Lng; } if (marker.Position.Lat > topLat) { topLat = marker.Position.Lat; } if (marker.Position.Lng > rightLng) { rightLng = marker.Position.Lng; } if (marker.Position.Lat < bottomLat) { bottomLat = marker.Position.Lat; } } if (leftLng != double.MaxValue && rightLng != double.MinValue && topLat != double.MinValue && bottomLat != double.MaxValue) { rect = RectLatLng.FromLTRB(leftLng, topLat, rightLng, bottomLat); } return(rect); }
private RectLatLng GetProjectedView() { PointLatLng point1 = this.mapProvider.Projection.GetProjectedPoint(new PointLatLng(this.exportArea.Top, this.exportArea.Left)); PointLatLng point2 = this.mapProvider.Projection.GetProjectedPoint(new PointLatLng(this.exportArea.Bottom, this.exportArea.Right)); return(RectLatLng.FromLTRB(point1.Lng, point1.Lat, point2.Lng, point2.Lat)); }
public void Add(GMapPolygon footprint) { // if the same name footprint exists exit if (footprintpolys.Any(p => p.Name == footprint.Name)) { return; } // if this is the first entry reset area if (footprintpolys.Count == 0) { Position = footprint.Points[0]; area = new RectLatLng(footprint.Points[0], new SizeLatLng(0, 0)); } // add the new footprint footprintpolys.Add(footprint); // recalc the area foreach (var point in footprint.Points) { if (!area.Contains(point)) { double tllat = Math.Max(area.Lat, point.Lat); double tllng = Math.Min(area.Lng, point.Lng); double brlat = Math.Min(area.Bottom, point.Lat); double brlng = Math.Max(area.Right, point.Lng); // enlarge the area area = RectLatLng.FromLTRB(tllng, tllat, brlng, brlat); } } generateCoverageFP(footprint); }
private void Setup() { if (mEntry != null && mEntry.Records.Count > 0) { double left = double.MaxValue; double top = double.MinValue; double right = double.MinValue; double bottom = double.MaxValue; foreach (Record rec in mEntry.Records) { left = Math.Min(left, rec.Location.Lng); top = Math.Max(top, rec.Location.Lat); right = Math.Max(right, rec.Location.Lng); bottom = Math.Min(bottom, rec.Location.Lat); } mBounds = RectLatLng.FromLTRB(left, top, right, bottom); mPoints = new Point[mEntry.Records.Count]; SetZoomToFitRect(mBounds); } else { mPoints = null; } }
/// <summary> /// gets rectangle with all objects inside /// </summary> /// <param name="ZIndex">z index or null to check all</param> /// <returns></returns> public RectLatLng?GetRectOfAllMarkers(int?ZIndex) { RectLatLng?ret = null; double left = double.MaxValue; double top = double.MinValue; double right = double.MinValue; double bottom = double.MaxValue; IEnumerable <GMapMarker> Overlays; if (ZIndex.HasValue) { Overlays = Markers.Where(p => p != null && p.ZIndex == ZIndex); } else { Overlays = Markers; } if (Overlays != null) { foreach (var m in Overlays) { if (m.Shape != null && m.Shape.IsVisible) { // left if (m.Position.Lng < left) { left = m.Position.Lng; } // top if (m.Position.Lat > top) { top = m.Position.Lat; } // right if (m.Position.Lng > right) { right = m.Position.Lng; } // bottom if (m.Position.Lat < bottom) { bottom = m.Position.Lat; } } } } if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) { ret = RectLatLng.FromLTRB(left, top, right, bottom); } return(ret); }
/// <summary> /// gets rectangle with all polygons objects inside /// </summary> /// <param name="overlayId">overlay id or null to check all</param> /// <returns></returns> public RectLatLng?GetRectOfAllPolygons(string overlayId) { RectLatLng?ret = null; double left = double.MaxValue; double top = double.MinValue; double right = double.MinValue; double bottom = double.MaxValue; foreach (GMapOverlay o in Overlays) { if (overlayId == null || o.Id == overlayId) { if (o.IsVisibile && o.Polygons.Count > 0) { foreach (GMapPolygon m in o.Polygons) { if (m.IsVisible) { foreach (var p in m.Points) { // left if (p.Lng < left) { left = p.Lng; } // top if (p.Lat > top) { top = p.Lat; } // right if (p.Lng > right) { right = p.Lng; } // bottom if (p.Lat < bottom) { bottom = p.Lat; } } } } } } } if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) { ret = RectLatLng.FromLTRB(left, top, right, bottom); } return(ret); }
private void LoadMap() { if (MapSelectedItem != null) { try { monitorWnd.IsMaskVisible = true; var providersList = GMapProviders.List; foreach (var provider in GMapProviders.List) { if (provider.ToString() == MapSelectedItem.MapProvider) { monitorWnd.MapControl.MapProvider = provider; break; } } monitorWnd.MapControl.Manager.Mode = AccessMode.CacheOnly; monitorWnd.MapControl.CacheLocation = AppDomain.CurrentDomain.BaseDirectory + "caches\\"; //缓存位置 monitorWnd.MapControl.CacheLocationFlieName = MapSelectedItem.MapName + ".gmdb"; monitorWnd.MapControl.MouseWheelZoomType = MouseWheelZoomType.MousePositionWithoutCenter; var bounds = MapSelectedItem.MapBound.Split(','); var boundsOfMap = RectLatLng.FromLTRB(double.Parse(bounds[0]), double.Parse(bounds[1]), double.Parse(bounds[2]), double.Parse(bounds[3])); //monitorWnd.MapControl.BoundsOfMap = boundsOfMap; monitorWnd.MapControl.ShowCenter = false; monitorWnd.MapControl.MinZoom = MapSelectedItem.MinZoom; monitorWnd.MapControl.MaxZoom = MapSelectedItem.MaxZoom; monitorWnd.MapControl.Zoom = MapSelectedItem.Zoom; var center = MapSelectedItem.Center.Split(','); monitorWnd.MapControl.Position = new PointLatLng(double.Parse(center[1]), double.Parse(center[0])); monitorWnd.MapControl.DragButton = MouseButton.Left; if (!MarkerLayerLoaded) { CameraMarker = new GMapOverlay("cameraMarkerLayer"); monitorWnd.MapControl.Overlays.Add(CameraMarker); TextMarker = new GMapOverlay("textMarkerLayer"); monitorWnd.MapControl.Overlays.Add(TextMarker); var layerGamera = new LayerInfo(); layerGamera.GMapOverlayLayer = CameraMarker; layerGamera.LayerName = "摄像头图层"; var layerText = new LayerInfo(); layerText.GMapOverlayLayer = TextMarker; layerText.LayerName = "标注图层"; MarkerLayers.Add(layerGamera); MarkerLayers.Add(layerText); MarkerLayerLoaded = true; } Notice.Show("地图加载成功!", "地图消息", 3, MessageBoxIcon.Success); } finally { monitorWnd.IsMaskVisible = false; } } }
/// <summary> /// Returns bounding rect of this marker /// </summary> /// <returns></returns> public RectLatLng GetBoundRect() { double degrees_radius = MyTools.KilometerToDegree(((double)Radius) / 1000.0, this.Position.Lat); double latmin = this.Position.Lat - degrees_radius; double latmax = this.Position.Lat + degrees_radius; double lonmin = this.Position.Lng - degrees_radius; double lonmax = this.Position.Lng + degrees_radius; return(RectLatLng.FromLTRB(lonmin, latmax, lonmax, latmin)); }
private void 显示行政区(M行政区位置 __行政区) { this.out地图.Position = new PointLatLng(__行政区.纬度, __行政区.经度); //绘制边界 _边界图层.Routes.Clear(); var __位置列表 = new List <PointLatLng>(); __行政区.边界坐标.ForEach(__点列表 => { var __GPS = new List <PointLatLng>(); __点列表.ForEach(q => { //double __谷歌经度 = q.Lng; //double __谷歌纬度 = q.Lat; //HGPS坐标转换.百度坐标转谷歌坐标(q.Lat, q.Lng, out __谷歌纬度, out __谷歌经度); //__GPS.Add(new PointLatLng(__谷歌纬度, __谷歌经度)); if (!Equals(_当前地图, GMapProviders.BaiduMap)) { __GPS.Add(H坐标转换.bd09_To_Gcj02(q.Lat, q.Lng)); } else { __GPS.Add(q); } }); __位置列表.AddRange(__GPS); var __线 = new GMapRoute(__GPS, "") { Stroke = new Pen(Color.Blue) { Width = 2, } }; _边界图层.Routes.Add(__线); }); if (__位置列表.Count > 0) { double __最小经度 = 180; double __最大经度 = -180; double __最小纬度 = 90; double __最大纬度 = -90; __位置列表.ForEach(q => { __最小经度 = Math.Min(__最小经度, q.Lng); __最大经度 = Math.Max(__最大经度, q.Lng); __最小纬度 = Math.Min(__最小纬度, q.Lat); __最大纬度 = Math.Max(__最大纬度, q.Lat); }); this.out地图.SetZoomToFitRect(RectLatLng.FromLTRB(__最小经度, __最大纬度, __最大经度, __最小纬度)); } }
public void UpdateGraphicsPath() { if (graphicsPath == null) { graphicsPath = new GraphicsPath(); } else { graphicsPath.Reset(); } { if (LocalPoints.Count == 0) { return; } // inside or within the current view var minx = Points.Min(a => a.Lng); var maxx = Points.Max(a => a.Lng); var miny = Points.Min(a => a.Lat); var maxy = Points.Max(a => a.Lat); Bounds = RectLatLng.FromLTRB(minx, maxy, maxx, miny); List <Point> pnts = new List <Point>(); var last = Point.Empty; for (int i = 0; i < LocalPoints.Count; i++) { Point p2 = new Point((int)LocalPoints[i].X, (int)LocalPoints[i].Y); if (p2 == last) { continue; } pnts.Add(p2); last = p2; } //close it pnts.Add(new Point((int)LocalPoints[LocalPoints.Count - 1].X, (int)LocalPoints[LocalPoints.Count - 1].Y)); if (pnts.Count > 2) { graphicsPath.AddPolygon(pnts.ToArray()); } else if (pnts.Count == 2) { graphicsPath.AddLines(pnts.ToArray()); } } }
private PointLatLng[] MinBoundingBox(PointLatLngAlt[] list) { RectLatLng minBox = RectLatLng.Empty; var minAngle = 0d; //foreach edge of the convex hull for (var i = 0; i < list.Length; i++) { var nextIndex = i + 1; var current = list[i]; var next = list[nextIndex % list.Length]; //min / max points var top = double.MinValue; var bottom = double.MaxValue; var left = double.MaxValue; var right = double.MinValue; //get angle of segment to x axis var angle = AngleToXAxis(current, next); //rotate every point and get min and max values for each direction foreach (var p in list) { var rotatedPoint = RotateToXAxis(p, angle); top = Math.Max(top, rotatedPoint.Lat); bottom = Math.Min(bottom, rotatedPoint.Lat); left = Math.Min(left, rotatedPoint.Lng); right = Math.Max(right, rotatedPoint.Lng); } //create axis aligned bounding box var box = RectLatLng.FromLTRB(left, top, right, bottom); if (minBox == RectLatLng.Empty || minBox.Size.HeightLat * minBox.Size.WidthLng > box.Size.HeightLat * box.Size.WidthLng) { minBox = box; minAngle = angle; } } return(new[] { RotateToXAxis(new PointLatLng(minBox.Top, minBox.Left), -minAngle), RotateToXAxis(new PointLatLng(minBox.Top, minBox.Right), -minAngle), RotateToXAxis(new PointLatLng(minBox.Bottom, minBox.Left), -minAngle), RotateToXAxis(new PointLatLng(minBox.Bottom, minBox.Right), -minAngle) }); }
private RectLatLng GetLatLngBox(PointLatLng center, object levelObj) { int result = 0x10; if (levelObj != null) { int.TryParse(levelObj.ToString(), out result); } double num2 = 360.0; double num3 = num2 / Math.Pow(2.0, (double)result); return(RectLatLng.FromLTRB(center.Lng - (num3 / 2.0), center.Lat + (num3 / 2.0), center.Lng + (num3 / 2.0), center.Lat - (num3 / 2.0))); }
public TrafficDlg() { InitializeComponent(); // set initial settings for Map gm_Options_Traffic.MapProvider = GMapProviders.Find(Properties.Settings.Default.Map_Provider); gm_Options_Traffic.IgnoreMarkerOnMouseWheel = true; gm_Options_Traffic.MinZoom = 0; gm_Options_Traffic.MaxZoom = 20; gm_Options_Traffic.Zoom = 6; gm_Options_Traffic.DragButton = System.Windows.Forms.MouseButtons.Left; gm_Options_Traffic.CanDragMap = true; gm_Options_Traffic.ScalePen = new Pen(Color.Black, 3); gm_Options_Traffic.HelperLinePen = null; gm_Options_Traffic.SelectionPen = null; gm_Options_Traffic.MapScaleInfoEnabled = true; gm_Options_Traffic.Overlays.Add(Coveragepolygons); gm_Options_Traffic.Overlays.Add(routes); // add tile to map polygons List <PointLatLng> l = new List <PointLatLng>(); l.Add(new PointLatLng(Properties.Settings.Default.MinLat, Properties.Settings.Default.MinLon)); l.Add(new PointLatLng(Properties.Settings.Default.MinLat, Properties.Settings.Default.MaxLon)); l.Add(new PointLatLng(Properties.Settings.Default.MaxLat, Properties.Settings.Default.MaxLon)); l.Add(new PointLatLng(Properties.Settings.Default.MaxLat, Properties.Settings.Default.MinLon)); GMapPolygon p = new GMapPolygon(l, "Coverage"); p.Stroke = new Pen(Color.FromArgb(255, Color.Magenta), 3); p.Fill = new SolidBrush(Color.FromArgb(0, Color.Magenta)); Coveragepolygons.Polygons.Add(p); // zoom the map gm_Options_Traffic.SetZoomToFitRect(RectLatLng.FromLTRB(Properties.Settings.Default.MinLon - 1, Properties.Settings.Default.MaxLat + 1, Properties.Settings.Default.MaxLon + 1, Properties.Settings.Default.MinLat - 1)); try { dtp_Options_Traffic_Start.Value = AircraftPositionData.Database.AircraftPositionOldestEntry(); dtp_Options_Traffic_Stop.Value = AircraftPositionData.Database.AircraftPositionYoungestEntry(); } catch { dtp_Options_Traffic_Start.Value = DateTime.UtcNow; dtp_Options_Traffic_Stop.Value = DateTime.UtcNow; } }
private bool GetRectangle(IEnumerable <RegionMarker> regionMarkers, out RectLatLng rect) { double left = double.MaxValue; double top = double.MinValue; double right = double.MinValue; double bottom = double.MaxValue; foreach (PointLatLng p in regionMarkers.SelectMany(rm => rm.Points)) { // left if (p.Lng < left) { left = p.Lng; } // top if (p.Lat > top) { top = p.Lat; } // right if (p.Lng > right) { right = p.Lng; } // bottom if (p.Lat < bottom) { bottom = p.Lat; } } if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) { rect = RectLatLng.FromLTRB(left, top, right, bottom); return(true); } rect = new RectLatLng(); return(false); }
public void ShowAll() { if (_gMap == null) { return; } var rect = GetRectOfAllMarkers(); if (rect.HasValue && !double.IsNaN(rect.Value.Lat) && !double.IsInfinity(rect.Value.Lat) && !double.IsNaN(rect.Value.Lng) && !double.IsInfinity(rect.Value.Lng) && !double.IsNaN(rect.Value.WidthLng) && !double.IsInfinity(rect.Value.WidthLng) && !double.IsNaN(rect.Value.HeightLat) && !double.IsInfinity(rect.Value.HeightLat) && RectLatLng.FromLTRB(-180, 90, 180, -90).Contains(rect.Value)) { _gMap.SetZoomToFitRect(rect.Value); } }
private void DrawHorizonPoint(int azimuth, HorizonPoint hp, bool closing = false) { Elevation_Polar_Series.Points.Add(new DataPoint(hp.Epsmin / Math.PI * 180.0, azimuth)); pm_Elevation_Polar.InvalidatePlot(true); if (!closing) { Elevation_Cartesian_Series.Points.Add(new DataPoint(azimuth, hp.Epsmin / Math.PI * 180.0)); } pm_Elevation_Cartesian.InvalidatePlot(true); Distance_Polar_Series.Points.Add(new DataPoint(hp.Dist, azimuth)); pm_Distance_Polar.InvalidatePlot(true); if (!closing) { Distance_Cartesian_Series.Points.Add(new DataPoint(azimuth, hp.Dist)); } pm_Distance_Cartesian.InvalidatePlot(true); LatLon.GPoint gp = LatLon.DestinationPoint(Location.Lat, Location.Lon, azimuth, hp.Dist); PointLatLng p = new PointLatLng(gp.Lat, gp.Lon); horizon.Points.Add(p); if (p.Lng < Map_Left) { Map_Left = p.Lng; } if (p.Lng > Map_Right) { Map_Right = p.Lng; } if (p.Lat < Map_Bottom) { Map_Bottom = p.Lat; } if (p.Lat > Map_Top) { Map_Top = p.Lat; } // toggle visible to redraw horizon.IsVisible = false; horizon.IsVisible = true; gm_Horizon.SetZoomToFitRect(RectLatLng.FromLTRB(Map_Left, Map_Top, Map_Right, Map_Bottom)); }
private void DownLoadMap() {//C:\Users\NNNNN\AppData\Local\GMap.NET\TileDBv5\zh-CN RectLatLng area = RectLatLng.FromLTRB(104.28077393000, 26.58757324030, 112.25690002000, 20.70236091970); if (!area.IsEmpty) { try { for (int i = 10; i <= 11; i++) { GMap.NET.WindowsPresentation.TilePrefetcher obj = new GMap.NET.WindowsPresentation.TilePrefetcher(); obj.Owner = MainWindow.obj; obj.ShowCompleteMessage = true; obj.Start(area, i, m_mapCtl.MapProvider, 100); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } }
private void TrafficDlg_SizeChanged(object sender, EventArgs e) { gm_Options_Traffic.SetZoomToFitRect(RectLatLng.FromLTRB(Properties.Settings.Default.MinLon - 1, Properties.Settings.Default.MaxLat + 1, Properties.Settings.Default.MaxLon + 1, Properties.Settings.Default.MinLat - 1)); }
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) { DateTime start = DateTime.Now; if (this.DesignMode) { return; } if (area.LocationMiddle.Lat == 0 && area.LocationMiddle.Lng == 0) { return; } try { base.OnPaint(e); } catch { return; } utmzone = center.GetUTMZone(); double heightscale = 1;//(step/90.0)*5; var campos = convertCoords(center); cameraX = campos[0]; cameraY = campos[1]; cameraZ = (campos[2] < 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 = campos[0] + Math.Sin(MathHelper.Radians(rpy.Z)) * 100; lookY = campos[1] + Math.Cos(MathHelper.Radians(rpy.Z)) * 100; lookZ = cameraZ; var size = 20000; // in front PointLatLngAlt front = center.newpos(rpy.Z, size); // behind PointLatLngAlt behind = center.newpos(rpy.Z, -50); // left : 90 allows for 180 degree viewing angle PointLatLngAlt left = center.newpos(rpy.Z - 45, size); // right PointLatLngAlt right = center.newpos(rpy.Z + 45, size); double maxlat = Math.Max(left.Lat, Math.Max(right.Lat, Math.Max(front.Lat, behind.Lat))); double minlat = Math.Min(left.Lat, Math.Min(right.Lat, Math.Min(front.Lat, behind.Lat))); double maxlng = Math.Max(left.Lng, Math.Max(right.Lng, Math.Max(front.Lng, behind.Lng))); double minlng = Math.Min(left.Lng, Math.Min(right.Lng, Math.Min(front.Lng, behind.Lng))); area = RectLatLng.FromLTRB(minlng, maxlat, maxlng, minlat); zoom = 20; float screenscale = 1;//this.Width/(float) this.Height*1f; //if(!Context.IsCurrent) MakeCurrent(); GL.MatrixMode(MatrixMode.Projection); OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView((float)(90 * MathHelper.deg2rad), screenscale, 0.00000001f, (float)20000); GL.LoadMatrix(ref projection); Console.WriteLine("cam: {0} {1} {2} lookat: {3} {4} {5}", (float)cameraX, (float)cameraY, (float)cameraZ, (float)lookX, (float)lookY, (float)lookZ); Matrix4 modelview = Matrix4.LookAt((float)cameraX, (float)cameraY, (float)cameraZ + 100f * 0, (float)lookX, (float)lookY, (float)lookZ, 0, 0, 1); GL.MatrixMode(MatrixMode.Modelview); // roll modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationZ((float)(rpy.X * MathHelper.deg2rad))); // pitch modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationX((float)(rpy.Y * -MathHelper.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)4000); GL.Fog(FogParameter.FogEnd, (float)size); GL.Disable(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(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.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(); core.fillEmptyTiles = true; core.LevelsKeepInMemmory = 20; core.Provider = type; core.Position = center; //core.ReloadMap(); List <tileZoomArea> tileArea = new List <tileZoomArea>(); for (int a = 10; a <= zoom; a++) { core.Zoom = a; var area2 = new RectLatLng(center.Lat, center.Lng, 0, 0); // 200m at max zoom // step at 0 zoom var distm = MathHelper.map(a, 0, zoom, size, 50); var offset = center.newpos(rpy.Z, distm); area2.Inflate(Math.Abs(center.Lat - offset.Lat), Math.Abs(center.Lng - offset.Lng)); var extratile = 0; if (a == zoom) { extratile = 1; } var tiles = new tileZoomArea() { zoom = a, points = prj.GetAreaTileList(area2, a, extratile), area = area2 }; tileArea.Add(tiles); } //tileArea.Reverse(); while (textureid.Count > 250) { var first = textureid.Keys.First(); GL.DeleteTexture(textureid[first]); textureid.Remove(first); } // get tiles & combine into one foreach (var tilearea in tileArea) { foreach (var p in tilearea.points) { core.tileDrawingListLock.AcquireReaderLock(); core.Matrix.EnterReadLock(); try { GMap.NET.Internals.Tile t = core.Matrix.GetTileWithNoLock(tilearea.zoom, p); if (t.NotEmpty) { foreach (GMapImage img in t.Overlays) { if (img.IsParent) { } if (!textureid.ContainsKey(p)) { try { generateTexture(p, (Bitmap)img.Img); } catch { continue; } } } } else { } } finally { core.Matrix.LeaveReadLock(); core.tileDrawingListLock.ReleaseReaderLock(); } if (textureid.ContainsKey(p)) { int texture = textureid[p]; GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, texture); } else { //Console.WriteLine("Missing tile"); GL.Disable(EnableCap.Texture2D); continue; } 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(4); GL.Color3(Color.White); GL.Clear(ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); // generate terrain GL.Begin(PrimitiveType.Points); GL.PointSize((float)(20)); //GL.Begin(PrimitiveType.Points); GL.Color3(Color.Blue); var latlng = prj.FromPixelToLatLng(xr, yr, tilearea.zoom); var utm = convertCoords(latlng); utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; GL.TexCoord2(0, 0); GL.Vertex3(utm[0], utm[1], utm[2]); // next down latlng = prj.FromPixelToLatLng(xr, y2, tilearea.zoom); utm = convertCoords(latlng); utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; GL.TexCoord2(0, 1); GL.Vertex3(utm[0], utm[1], utm[2]); // next right latlng = prj.FromPixelToLatLng(x2, yr, tilearea.zoom); utm = convertCoords(latlng); utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; GL.TexCoord2(1, 0); GL.Vertex3(utm[0], utm[1], utm[2]); // next right down latlng = prj.FromPixelToLatLng(x2, y2, tilearea.zoom); utm = convertCoords(latlng); utm[2] = srtm.getAltitude(latlng.Lat, latlng.Lng).alt; GL.TexCoord2(1, 1); GL.Vertex3(utm[0], utm[1], utm[2]); GL.End(); var dist = LocationCenter.GetDistance(latlng); var pxstep = 128; if (dist < 500) { pxstep = 32; } double[] oldutm = null; GL.Begin(PrimitiveType.TriangleStrip); for (long x = xr; x < x2; x += pxstep) { long xnext = x + pxstep; //GL.Begin(PrimitiveType.LineStrip); for (long y = yr; y < y2; y += pxstep) { long ynext = y + pxstep; //GL.Begin(PrimitiveType.Lines); var latlng1 = prj.FromPixelToLatLng(x, y, tilearea.zoom); var utm1 = convertCoords(latlng1); utm1[2] = srtm.getAltitude(latlng1.Lat, latlng1.Lng).alt; var imgx = MathHelper.map(x, xr, x2, 0, 1); var imgy = MathHelper.map(y, yr, y2, 0, 1); GL.TexCoord2(imgx, imgy); GL.Vertex3(utm1[0], utm1[1], utm1[2]); // var latlng2 = prj.FromPixelToLatLng(x, ynext, tilearea.zoom); var utm2 = convertCoords(latlng2); utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt; imgx = MathHelper.map(x, xr, x2, 0, 1); imgy = MathHelper.map(ynext, yr, y2, 0, 1); GL.TexCoord2(imgx, imgy); GL.Vertex3(utm2[0], utm2[1], utm2[2]); // latlng2 = prj.FromPixelToLatLng(xnext, y, tilearea.zoom); utm2 = convertCoords(latlng2); utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt; imgx = MathHelper.map(xnext, xr, x2, 0, 1); imgy = MathHelper.map(y, yr, y2, 0, 1); GL.TexCoord2(imgx, imgy); GL.Vertex3(utm2[0], utm2[1], utm2[2]); // latlng2 = prj.FromPixelToLatLng(xnext, ynext, tilearea.zoom); utm2 = convertCoords(latlng2); utm2[2] = srtm.getAltitude(latlng2.Lat, latlng2.Lng).alt; imgx = MathHelper.map(xnext, xr, x2, 0, 1); imgy = MathHelper.map(ynext, yr, y2, 0, 1); GL.TexCoord2(imgx, imgy); GL.Vertex3(utm2[0], utm2[1], utm2[2]); } } GL.End(); GL.Disable(EnableCap.Texture2D); } } GL.Flush(); try { this.SwapBuffers(); Context.MakeCurrent(null); } catch { } //this.Invalidate(); var delta = DateTime.Now - start; Console.WriteLine("OpenGLTest2 {0}", delta.TotalMilliseconds); }
static void Main(string[] args) { GMaps.Instance.UseMemoryCache = false; GMaps.Instance.Mode = AccessMode.ServerAndCache; GMapProvider provider = GMapProviders.BingMap; provider.OnInitialized(); int zoom = 12; RectLatLng area = RectLatLng.FromLTRB(25.013809204101563, 54.832138557519563, 25.506134033203125, 54.615623046071839); if (!area.IsEmpty) { try { List <GPoint> tileArea = provider.Projection.GetAreaTileList(area, zoom, 0); string bigImage = zoom + "-" + provider + "-vilnius.png"; Console.WriteLine("Preparing: " + bigImage); Console.WriteLine("Zoom: " + zoom); Console.WriteLine("Type: " + provider.ToString()); Console.WriteLine("Area: " + area); // current area GPoint topLeftPx = provider.Projection.FromLatLngToPixel(area.LocationTopLeft, zoom); GPoint rightButtomPx = provider.Projection.FromLatLngToPixel(area.Bottom, area.Right, zoom); GPoint pxDelta = new GPoint(rightButtomPx.X - topLeftPx.X, rightButtomPx.Y - topLeftPx.Y); int padding = 22; { 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 (var tp in provider.Overlays) { Exception ex; var tile = GMaps.Instance.GetImageFrom(tp, p, zoom, out ex) as GMapImage; if (tile != null) { using (tile) { long x = p.X * provider.Projection.TileSize.Width - topLeftPx.X + padding; long y = p.Y * provider.Projection.TileSize.Width - topLeftPx.Y + padding; { gfx.DrawImage(tile.Img, x, y, provider.Projection.TileSize.Width, provider.Projection.TileSize.Height); } } } } } } // 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)) using (Graphics gfx = Graphics.FromImage(bmpDestination)) { // draw bounds & coordinates using (Pen p = new Pen(Brushes.Red, 3)) { p.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot; gfx.DrawRectangle(p, rect); string topleft = 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(area.Bottom, 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 = provider.Projection.GetGroundResolution(zoom, 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, System.Drawing.Imaging.ImageFormat.Png); } } // ok, lets see what we get { Console.WriteLine("Done! Starting Image: " + bigImage); Process.Start(bigImage); } } catch (Exception ex) { Console.WriteLine("Error: " + ex.ToString()); Console.ReadLine(); } } }
ArcGIS_DarbAE_Q2_2011_NAVTQ_Eng_V5_MapProvider() { MaxZoom = 12; Area = RectLatLng.FromLTRB(49.8846923723311, 28.0188609585523, 58.2247031977662, 21.154115956732); Copyright = string.Format("©{0} ESRI - Map data ©{0} ArcGIS", DateTime.Today.Year); }
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; }
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 static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg") || logfile.Contains("Telemetry Logs")) { continue; } MAVLinkInterface mine = new MAVLinkInterface(); List <MAVLink.mavlink_global_position_int_t> locs = new List <MAVLink.mavlink_global_position_int_t>(); try { double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read))) { mine.logreadmode = true; CurrentState cs = new CurrentState(); while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { byte[] packet = mine.readPacket(); //Console.Write((mine.logplaybackfile.BaseStream.Position / (double)mine.logplaybackfile.BaseStream.Length) +"\r"); if (packet.Length < 5) { continue; } try { if (MainV2.speechEngine != null) { MainV2.speechEngine.SpeakAsyncCancelAll(); } } catch { } if (packet[5] == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ByteArrayToStructure <MAVLink.mavlink_global_position_int_t>(6); if (loc.lat == 0 || loc.lon == 0) { continue; } locs.Add(loc); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } if (locs.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); PointF lastpoint = new PointF(); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(Pens.Red, lastpoint, newpoint); } lastpoint = newpoint; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { var map = new Bitmap(100, 100); var grap = Graphics.FromImage(map); grap.DrawString("NO MAP", SystemFonts.DefaultFont, Brushes.Red, 0, 0, StringFormat.GenericDefault); map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } } catch { continue; } } }
public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) { continue; } double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; Dictionary <int, List <PointLatLngAlt> > loc_list = new Dictionary <int, List <PointLatLngAlt> >(); try { if (logfile.ToLower().EndsWith(".tlog")) { using (MAVLinkInterface mine = new MAVLinkInterface()) using ( mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ) { mine.logreadmode = true; while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { MAVLink.MAVLinkMessage packet = mine.readPacket(); if (packet.Length < 5) { continue; } try { if (MainV2.speechEngine != null) { MainV2.speechEngine.SpeakAsyncCancelAll(); } } catch { } if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ToStructure <MAVLink.mavlink_global_position_int_t>(); if (loc.lat == 0 || loc.lon == 0) { continue; } var id = MAVList.GetID(packet.sysid, packet.compid); if (!loc_list.ContainsKey(id)) { loc_list[id] = new List <PointLatLngAlt>(); } loc_list[id].Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); BinaryLog binlog = new BinaryLog(); DFLog dflog = new DFLog(); using (var st = File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(st)) { loc_list[0] = new List <PointLatLngAlt>(); while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = binlog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { dflog.FMTLine(line); } else if (line.StartsWith("GPS")) { var item = dflog.GetDFItemFromLine(line, 0); var lat = double.Parse(item.items[dflog.FindMessageOffset(item.msgtype, "Lat")]); var lon = double.Parse(item.items[dflog.FindMessageOffset(item.msgtype, "Lng")]); if (lat == 0 || lon == 0) { continue; } loc_list[0].Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (loc_list.First().Value.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; int a = 0; foreach (var locs in loc_list.Values) { PointF lastpoint = new PointF(); var pen = new Pen(colours[a % (colours.Length - 1)]); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(pen, lastpoint, newpoint); } lastpoint = newpoint; } a++; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) { DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); } continue; } } }
public static void MapLogs(string[] logs) { foreach (var logfile in logs) { if (File.Exists(logfile + ".jpg")) { continue; } double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; List <PointLatLngAlt> locs = new List <PointLatLngAlt>(); try { if (logfile.ToLower().EndsWith(".tlog")) { MAVLinkInterface mine = new MAVLinkInterface(); using (mine.logplaybackfile = new BinaryReader(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.Read))) { mine.logreadmode = true; CurrentState cs = new CurrentState(); while (mine.logplaybackfile.BaseStream.Position < mine.logplaybackfile.BaseStream.Length) { byte[] packet = mine.readPacket(); if (packet.Length < 5) { continue; } try { if (MainV2.speechEngine != null) { MainV2.speechEngine.SpeakAsyncCancelAll(); } } catch { } if (packet[5] == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ByteArrayToStructure <MAVLink.mavlink_global_position_int_t>(6); if (loc.lat == 0 || loc.lon == 0) { continue; } locs.Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } } } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { bool bin = logfile.ToLower().EndsWith(".bin"); using (var st = File.OpenRead(logfile)) { using (StreamReader sr = new StreamReader(st)) { while (sr.BaseStream.Position < sr.BaseStream.Length) { string line = ""; if (bin) { line = BinaryLog.ReadMessage(sr.BaseStream); } else { line = sr.ReadLine(); } if (line.StartsWith("FMT")) { DFLog.FMTLine(line); } else if (line.StartsWith("GPS")) { var item = DFLog.GetDFItemFromLine(line, 0); var lat = double.Parse(item.items[DFLog.FindMessageOffset(item.msgtype, "Lat")]); var lon = double.Parse(item.items[DFLog.FindMessageOffset(item.msgtype, "Lng")]); if (lat == 0 || lon == 0) { continue; } locs.Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } } if (locs.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); var map = GetMap(area); var grap = Graphics.FromImage(map); PointF lastpoint = new PointF(); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(Pens.Red, lastpoint, newpoint); } lastpoint = newpoint; } map.Save(logfile + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); map.Dispose(); map = null; } else { DoTextMap(logfile + ".jpg", "No gps data"); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) { DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); } continue; } } }
public void doPaint() { DateTime start = DateTime.Now; if (this.DesignMode) { return; } if (area.LocationMiddle.Lat == 0 && area.LocationMiddle.Lng == 0) { return; } core.Position = center; double heightscale = 1; //(step/90.0)*5; var campos = convertCoords(center); cameraX = campos[0]; cameraY = campos[1]; cameraZ = (campos[2] < 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 = campos[0] + Math.Sin(MathHelper.Radians(rpy.Z)) * 100; lookY = campos[1] + Math.Cos(MathHelper.Radians(rpy.Z)) * 100; lookZ = cameraZ; var size = 5000; // in front PointLatLngAlt front = center.newpos(rpy.Z, size); // behind PointLatLngAlt behind = center.newpos(rpy.Z, -50); // left : 90 allows for 180 degree viewing angle PointLatLngAlt left = center.newpos(rpy.Z - 45, size); // right PointLatLngAlt right = center.newpos(rpy.Z + 45, size); double maxlat = Math.Max(left.Lat, Math.Max(right.Lat, Math.Max(front.Lat, behind.Lat))); double minlat = Math.Min(left.Lat, Math.Min(right.Lat, Math.Min(front.Lat, behind.Lat))); double maxlng = Math.Max(left.Lng, Math.Max(right.Lng, Math.Max(front.Lng, behind.Lng))); double minlng = Math.Min(left.Lng, Math.Min(right.Lng, Math.Min(front.Lng, behind.Lng))); area = RectLatLng.FromLTRB(minlng, maxlat, maxlng, minlat); if (!Context.IsCurrent) { MakeCurrent(); } GL.MatrixMode(MatrixMode.Projection); OpenTK.Matrix4 projection = OpenTK.Matrix4.CreatePerspectiveFieldOfView((float)(90 * MathHelper.deg2rad), (float)Width / Height, 0.1f, (float)20000); GL.LoadMatrix(ref projection); /*Console.WriteLine("cam: {0} {1} {2} lookat: {3} {4} {5}", (float) cameraX, (float) cameraY, (float) cameraZ, * (float) lookX, * (float) lookY, (float) lookZ); */ Matrix4 modelview = Matrix4.LookAt((float)cameraX, (float)cameraY, (float)cameraZ + 100f * 0, (float)lookX, (float)lookY, (float)lookZ, 0, 0, 1); GL.MatrixMode(MatrixMode.Modelview); // roll modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationZ((float)(rpy.X * MathHelper.deg2rad))); // pitch modelview = Matrix4.Mult(modelview, Matrix4.CreateRotationX((float)(rpy.Y * -MathHelper.deg2rad))); GL.LoadMatrix(ref modelview); GL.Viewport(0, 0, Width, Height); GL.ClearColor(Color.CornflowerBlue); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.AccumBufferBit); GL.Disable(EnableCap.Fog); GL.Enable(EnableCap.Fog); GL.Disable(EnableCap.Lighting); Lighting.SetupAmbient(0.1f); Lighting.SetDefaultMaterial(1f); // Lighting.SetupLightZero(new Vector3d(cameraX, cameraY, cameraZ + 100), 0f); 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)300); GL.Fog(FogParameter.FogEnd, (float)2000); GL.Disable(EnableCap.DepthTest); //GL.DepthFunc(DepthFunction.Always); var texlist = textureid.ToArray().ToSortedList((a, b) => { return(a.Value.zoom.CompareTo(b.Value.zoom)); }); int textureload = 0; foreach (var tidict in texlist) { if (!tidict.Value.textureReady) { if (textureload < 1) { textureload++; } else { continue; } } long xr = tidict.Key.X * prj.TileSize.Width; long yr = tidict.Key.Y * prj.TileSize.Width; long x2 = (tidict.Key.X + 1) * prj.TileSize.Width; long y2 = (tidict.Key.Y + 1) * prj.TileSize.Width; GL.Clear(ClearBufferMask.DepthBufferBit); GL.Enable(EnableCap.DepthTest); if (tidict.Value.texture.Count != 0) { tidict.Value.Draw(); } GL.Disable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, 0); { if (GCSViews.FlightPlanner.instance.pointlist.Count > 1) { GL.Color3(Color.Red); GL.LineWidth(3); // render wps GL.Begin(PrimitiveType.LineStrip); foreach (var point in GCSViews.FlightPlanner.instance.pointlist) { if (point == null) { continue; } var co = convertCoords(point); GL.Vertex3(co[0], co[1], co[2]); } GL.End(); } if (green == 0) { green = generateTexture(GMap.NET.Drawing.Properties.Resources.green.ToBitmap()); } GL.Enable(EnableCap.DepthTest); GL.DepthMask(false); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Texture2D); GL.BindTexture(TextureTarget.Texture2D, green); var list = GCSViews.FlightPlanner.instance.pointlist.ToList(); if (MainV2.comPort.MAV.cs.TargetLocation != PointLatLngAlt.Zero) { list.Add(MainV2.comPort.MAV.cs.TargetLocation); } foreach (var point in list) { if (point == null) { continue; } var co = convertCoords(point); GL.Begin(PrimitiveType.TriangleStrip); GL.Color3(Color.Red); //tr GL.TexCoord2(0, 0); GL.Vertex3(Math.Sin(MathHelper.Radians(rpy.Z + 90)) * 2 + co[0], Math.Cos(MathHelper.Radians(rpy.Z + 90)) * 2 + co[1], co[2] + 10); GL.Color3(Color.Green); //tl GL.TexCoord2(1, 0); GL.Vertex3(co[0] - Math.Sin(MathHelper.Radians(rpy.Z + 90)) * 2, co[1] - Math.Cos(MathHelper.Radians(rpy.Z + 90)) * 2, co[2] + 10); GL.Color3(Color.Blue); // br GL.TexCoord2(0, 1); GL.Vertex3(co[0] + Math.Sin(MathHelper.Radians(rpy.Z + 90)) * 2, co[1] + Math.Cos(MathHelper.Radians(rpy.Z + 90)) * 2, co[2] - 1); GL.Color3(Color.Yellow); // bl GL.TexCoord2(1, 1); GL.Vertex3(co[0] - Math.Sin(MathHelper.Radians(rpy.Z + 90)) * 2, co[1] - Math.Cos(MathHelper.Radians(rpy.Z + 90)) * 2, co[2] - 1); GL.End(); } GL.Disable(EnableCap.Blend); GL.DepthMask(true); /* * WPs.ForEach(a => * { * var co = convertCoords(new PointLatLngAlt(a.lat, a.lng, a.alt)); * GL.Vertex3(co[0], co[1], co[2]); * });*/ } } try { this.SwapBuffers(); //Context.MakeCurrent(null); } catch { } //this.Invalidate(); var delta = DateTime.Now - start; Console.Write("OpenGLTest2 {0}\r", delta.TotalMilliseconds); }
public static void ProcessFile(string logfile) { if (File.Exists(logfile + ".jpg")) { return; } double minx = 99999; double maxx = -99999; double miny = 99999; double maxy = -99999; bool sitl = false; Dictionary <int, List <PointLatLngAlt> > loc_list = new Dictionary <int, List <PointLatLngAlt> >(); try { if (logfile.ToLower().EndsWith(".tlog")) { Comms.CommsFile cf = new CommsFile(); cf.Open(logfile); using (CommsStream cs = new CommsStream(cf, cf.BytesToRead)) { MAVLink.MavlinkParse parse = new MAVLink.MavlinkParse(true); while (cs.Position < cs.Length) { try { MAVLink.MAVLinkMessage packet = parse.ReadPacket(cs); if (packet == null || packet.Length < 5) { continue; } if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIM_STATE || packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.SIMSTATE) { sitl = true; } if (packet.msgid == (byte)MAVLink.MAVLINK_MSG_ID.GLOBAL_POSITION_INT) { var loc = packet.ToStructure <MAVLink.mavlink_global_position_int_t>(); if (loc.lat == 0 || loc.lon == 0) { continue; } var id = packet.sysid * 256 + packet.compid; if (!loc_list.ContainsKey(id)) { loc_list[id] = new List <PointLatLngAlt>(); } loc_list[id].Add(new PointLatLngAlt(loc.lat / 10000000.0f, loc.lon / 10000000.0f)); minx = Math.Min(minx, loc.lon / 10000000.0f); maxx = Math.Max(maxx, loc.lon / 10000000.0f); miny = Math.Min(miny, loc.lat / 10000000.0f); maxy = Math.Max(maxy, loc.lat / 10000000.0f); } } catch { } } } cf.Close(); } else if (logfile.ToLower().EndsWith(".bin") || logfile.ToLower().EndsWith(".log")) { using ( DFLogBuffer colbuf = new DFLogBuffer(File.Open(logfile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) ) { loc_list[0] = new List <PointLatLngAlt>(); foreach (var item in colbuf.GetEnumeratorType("GPS")) { if (item.msgtype.StartsWith("GPS")) { if (!colbuf.dflog.logformat.ContainsKey("GPS")) { continue; } var status = double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Status")]); var lat = double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Lat")]); var lon = double.Parse(item.items[colbuf.dflog.FindMessageOffset(item.msgtype, "Lng")]); if (lat == 0 || lon == 0 || status < 3) { continue; } loc_list[0].Add(new PointLatLngAlt(lat, lon)); minx = Math.Min(minx, lon); maxx = Math.Max(maxx, lon); miny = Math.Min(miny, lat); maxy = Math.Max(maxy, lat); } } } } if (loc_list.Count > 0 && loc_list.First().Value.Count > 10) { // add a bit of buffer var area = RectLatLng.FromLTRB(minx - 0.001, maxy + 0.001, maxx + 0.001, miny - 0.001); using (var map = GetMap(area)) using (var grap = Graphics.FromImage(map)) { if (sitl) { AddTextToMap(grap, "SITL"); } Color[] colours = { Color.Red, Color.Orange, Color.Yellow, Color.Green, Color.Blue, Color.Indigo, Color.Violet, Color.Pink }; int a = 0; foreach (var locs in loc_list.Values) { PointF lastpoint = new PointF(); var pen = new Pen(colours[a % (colours.Length - 1)]); foreach (var loc in locs) { PointF newpoint = GetPixel(area, loc, map.Size); if (!lastpoint.IsEmpty) { grap.DrawLine(pen, lastpoint, newpoint); } lastpoint = newpoint; } a++; } map.Save(logfile + ".jpg", SKEncodedImageFormat.Jpeg); File.SetLastWriteTime(logfile + ".jpg", new FileInfo(logfile).LastWriteTime); } } else { DoTextMap(logfile + ".jpg", "No gps data"); File.SetLastWriteTime(logfile + ".jpg", new FileInfo(logfile).LastWriteTime); } } catch (Exception ex) { if (ex.ToString().Contains("Mavlink 0.9")) { DoTextMap(logfile + ".jpg", "Old log\nMavlink 0.9"); } } }