private void DrawGridForMap() { System.Drawing.Point topLeftReceived = new System.Drawing.Point(); System.Drawing.Point bottomRightReceived = new System.Drawing.Point(); if (_Core.tileDrawingList.GetExtension(ref topLeftReceived, ref bottomRightReceived)) { topLeftReceived = new System.Drawing.Point(topLeftReceived.X * _Core.Projection.TileSize.Width, topLeftReceived.Y * _Core.Projection.TileSize.Height); bottomRightReceived = new System.Drawing.Point((bottomRightReceived.X + 1) * _Core.Projection.TileSize.Width, (bottomRightReceived.Y + 1) * _Core.Projection.TileSize.Height); int zoom = _Core.Zoom; GMap.NET.PointLatLng topLeft = _Core.Projection.FromPixelToLatLng(topLeftReceived.X, topLeftReceived.Y, zoom); GMap.NET.PointLatLng bottomRight = _Core.Projection.FromPixelToLatLng(bottomRightReceived.X, bottomRightReceived.Y, zoom); //center: das wird als Mittelpunkt übergeben GMap.NET.PointLatLng center = new GMap.NET.PointLatLng((_YMax + _YMin) / 2, (_XMax + _XMin) / 2); Pen penLine = new Pen(Color.Wheat); Brush brushValue = Brushes.White; Font font = new Font("Arial", 8.0f); Graphics g = Graphics.FromImage(_Bitmap); try { //Y Axis double pot = 0.0; double dY = (topLeft.Lat - bottomRight.Lat) / 10; int decimals = 0; int log = Convert.ToInt32(Math.Floor(Math.Log10(dY))); if (log >= 0) { pot = Convert.ToInt32(Math.Pow(10, log)); decimals = 0; } else { pot = 1.0 / Math.Pow(10, -log); decimals = -log; } dY = pot * Math.Round(dY / pot, 0); double yStart = 0.0; if (Math.Abs(bottomRight.Lat) > 0.0001) { yStart = Convert.ToInt32(bottomRight.Lat / dY) * dY; } while (yStart <= topLeft.Lat) { GMap.NET.Point yPoint = _Core.Projection.FromLatLngToPixel(new GMap.NET.PointLatLng(yStart, center.Lng), zoom); int yPos = yPoint.Y - topLeftReceived.Y - _TopOffset + _TopMargin; //int yPos = Convert.ToInt32((topLeft.Lat - yStart) / _YFactor) - _TopOffset; g.DrawLine(penLine, 0, yPos, _Bitmap.Width, yPos); string str = yStart.ToString("F" + decimals.ToString()); g.DrawString(str, font, brushValue, 0.0f, (float)yPos); yStart = Math.Round(yStart + dY, decimals); } //x axis double dX = (bottomRight.Lng - topLeft.Lng) / 10; log = Convert.ToInt32(Math.Floor(Math.Log10(dX))); if (log >= 0) { pot = Convert.ToInt32(Math.Pow(10, log)); decimals = 0; } else { pot = 1.0 / Math.Pow(10, -log); decimals = -log; } dX = pot * Math.Round(dX / pot, 0); double xStart = 0.0; if (Math.Abs(topLeft.Lng) > 0.0001) { xStart = Convert.ToInt32(topLeft.Lng / dX) * dX; } while (xStart <= bottomRight.Lng) { GMap.NET.Point xPoint = _Core.Projection.FromLatLngToPixel(new GMap.NET.PointLatLng(center.Lat, xStart), zoom); int xPos = xPoint.X - topLeftReceived.X - _LeftOffset + _LeftMargin; //int xPos = Convert.ToInt32((xStart - topLeft.Lng) / _XFactor) - _TopOffset; g.DrawLine(penLine, xPos, 0, xPos, _Bitmap.Height); string str = xStart.ToString("F" + decimals.ToString()); g.DrawString(str, font, brushValue, (float)xPos, (float)pnlImage.ClientSize.Height - 12); xStart = Math.Round(xStart + dX, decimals); } } catch { } finally { penLine.Dispose(); g.Dispose(); } } }
public override GMap.NET.PointLatLng FromPixelToLatLng(int x, int y, int zoom) { if (m_buffer2.ContainsKey(x) && m_buffer2[x].ContainsKey(y) && m_buffer2[x][y].ContainsKey(zoom)) { return(m_buffer2[x][y][zoom]); } GMap.NET.PointLatLng p = base.FromPixelToLatLng(x, y, zoom); GMap.NET.GPoint offset = GoogleMapChinaOffset.Instance.GetOffset(p.Lat, p.Lng, zoom); p = base.FromPixelToLatLng(x - offset.X, y - offset.Y, zoom); if (!m_buffer2.ContainsKey(x)) { m_buffer2[x] = new Dictionary <int, Dictionary <int, GMap.NET.PointLatLng> >(); } if (!m_buffer2[x].ContainsKey(y)) { m_buffer2[x][y] = new Dictionary <int, GMap.NET.PointLatLng>(); } if (!m_buffer2[x][y].ContainsKey(zoom)) { m_buffer2[x][y][zoom] = p; } return(p); }
public GMap.NET.PointLatLng GetAntiOffseted(GMap.NET.PointLatLng latLon) { System.Drawing.Size offset = GetOffset(latLon.Lat, latLon.Lng, 18).Value; GMap.NET.GPoint point = m_projection.FromLatLngToPixel(latLon, 18); point = point - new GMap.NET.GSize(offset.Width, offset.Height); return(m_projection.FromPixelToLatLng(point, 18)); }
private void CalculateGhostPoint(int index, Position otherPosition, Position currentPosition, GMapRoute route) { double x, y; var point = new GMap.NET.PointLatLng(); if (currentPosition.DistanceTo(otherPosition) > _ghostMarkerThresholdDistance) { x = (currentPosition.Latitude.DecimalDegrees + otherPosition.Latitude.DecimalDegrees) / 2; y = (currentPosition.Longitude.DecimalDegrees + otherPosition.Longitude.DecimalDegrees) / 2; point.Lat = x; point.Lng = y; int ghostPointIndex = IsGhostPointExist(index, route); if (ghostPointIndex == -1) { point = CreateGhostPoint(index, point, route); } else { _ghostPointDictionary[route][ghostPointIndex].Marker.Position = point; } } else { RemoveGhostPointAt(index, route); } }
public static Geometry ToGeometry(this GMap.NET.PointLatLng input, int id) { return(new Geometry(input.Lat, input.Lng, id) { IsModified = true }); }
private void UpdateUAVPosition() { if (GPS != null) { CultureInfo cultureInfo = new CultureInfo("en-US"); lbl_hasfix.Text = "GPS State:" + GPS["lbGSAFixMode"].Value.ToString() + " Altitude " + GPS["lbGGAAltitude"].Value.ToString() + " " + GPS["lbGGAAltitudeUnit"].Value.ToString() + " Speed " + GPS["lbRMCSpeed"].Value.ToString(); GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(Convert.ToDouble(GPS["lbRMCPositionLatitude"].Value, cultureInfo), Convert.ToDouble(GPS["lbRMCPositionLongitude"].Value, cultureInfo)); if (UAVOverlay != null) { if (UAVOverlay.Markers.Count == 0) { UAVOverlay.Markers.Add(new GMapMarkerGoogleGreen(point)); } else { UAVOverlay.Markers[0].Position = point; } if (centerOnUAV) { this.gMapControl1.Position = point; this.gMapControl1.Update(); } this.gMapControl1.UpdateMarkerLocalPosition(UAVOverlay.Markers[0]); } } }
void MainMap_MouseDoubleClick(object sender, MouseEventArgs e) { GMap.NET.PointLatLng point = gmap.FromLocalToLatLng(e.X, e.Y); addMarker(point.Lat, point.Lng); sendGpsPoint(point.Lng, point.Lat); }
private void addMarker(double X, double Y) { sendGpsPoint(X, Y); GMap.NET.PointLatLng coors = new GMap.NET.PointLatLng(X, Y); GMapOverlay markersOverlay = new GMapOverlay("markers"); GMarkerCross marker = new GMarkerCross(coors); gmap.UpdateMarkerLocalPosition(marker); markersOverlay.Markers.Add(marker); gmap.Overlays.Add(markersOverlay); double lat = coors.Lat; double lng = coors.Lng; string coordinates = ++numMarkers + ") " + lat.ToString() + "," + lng.ToString(); futurePointsList.TopIndex = futurePointsList.Items.Add(coordinates); GMapOverlay polyOverlay = new GMapOverlay("polygons"); List <GMap.NET.PointLatLng> points = new List <GMap.NET.PointLatLng>(); points.Add(lastPoint); points.Add(coors); GMapPolygon polygon = new GMapPolygon(points, "mypolygon"); polygon.Fill = new SolidBrush(Color.FromArgb(50, Color.Red)); polygon.Stroke = new Pen(Color.Red, 1); polyOverlay.Polygons.Add(polygon); gmap.Overlays.Add(polyOverlay); lastPoint = coors; gmap.Zoom++; gmap.Zoom--; }
private void buttonTestLoadMap_Click(object sender, EventArgs e) { try { map.DragButton = MouseButtons.Left; map.MapProvider = GMapProviders.GoogleMap; double lat = Convert.ToDouble(lattitude); double lon = Convert.ToDouble(longitude); map.Position = new GMap.NET.PointLatLng(lat, lon); map.MinZoom = 5; map.MaxZoom = 100; map.Zoom = 10; GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(lat, lon); GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.blue_dot); GMapOverlay markers = new GMapOverlay("markers"); markers.Markers.Add(marker); map.Overlays.Add(markers); List <GMap.NET.PointLatLng> list = new List <GMap.NET.PointLatLng>(); list.Add(new GMap.NET.PointLatLng(lattitude, longitude)); GMapRoute r = new GMapRoute(list, "my route"); r.Stroke.Width = 8; r.Stroke.Color = Color.Red; map.ZoomAndCenterRoute(r); map.Zoom = 15; } catch (Exception ex) { //error handling } }
private void buttonTestLoadMap_Click(object sender, EventArgs e) { try { map.DragButton = MouseButtons.Left; map.MapProvider = GMapProviders.GoogleMap; double lat = Convert.ToDouble(labelLattitude.Text); double lon = Convert.ToDouble(labelLongitude.Text); map.Position = new GMap.NET.PointLatLng(lat, lon); map.MinZoom = 5; map.MaxZoom = 50; map.Zoom = 10; GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(lat, lon); GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.blue_dot); GMapOverlay markers = new GMapOverlay("markers"); markers.Markers.Add(marker); map.Overlays.Add(markers); } catch (Exception ex) { //error handling } }
/// <summary> /// Map moved to new position by dragging /// </summary> /// <param name="point"></param> public void UpdateRouteAndCarRefresh(GMapControl map) { if (RouteMain.Count == 0) { Visibility = Visibility.Hidden; return; } UpdateRouteUIPoints(_segmentMain, _figureMain, RouteMain, map); UpdateRouteUIPoints(_segmentPrev, _figurePrev, RoutePrev, map); //update car position if (_iCurrentPointIndex >= 0) { _car.Opacity = 0.8; GMap.NET.PointLatLng currentPosition = new GMap.NET.PointLatLng(RouteMain[_iCurrentPointIndex].Latitude, RouteMain[_iCurrentPointIndex].Longitude); GMap.NET.GPoint pt0 = map.FromLatLngToLocal(currentPosition); Point ptCar = new Point(pt0.X, pt0.Y); Canvas.SetLeft(_car, ptCar.X - _car.ActualWidth * _car.RenderTransformOrigin.X); //middle width Canvas.SetTop(_car, ptCar.Y - _car.ActualHeight * _car.RenderTransformOrigin.Y); //toward the front of car carDirection.Angle = RouteMain[_iCurrentPointIndex].Course; UpdateCarScale(map.Zoom); } else { _car.Opacity = 0.1; } Visibility = Visibility.Visible; }
private void mapControl_OnPositionChanged(GMap.NET.PointLatLng point) { if (PositionChanged != null) { PositionChanged.Invoke(mapControl, EventArgs.Empty); } }
public PositionGPS(double lat, double lon, int zoom) { Latitude = lat; Longitude = lon; Zoom = zoom; Point = new GMap.NET.PointLatLng(lat, lon); }
public GMapMarkerCustomEnum(GMap.NET.PointLatLng pos, EnumMarkerCustom enumMarker) : base(pos) { switch (enumMarker) { case EnumMarkerCustom.MarkerA: Icon = Taxi.Controls.Properties.Resources.STaxi_MarkerA; break; case EnumMarkerCustom.MarkerB: Icon = Taxi.Controls.Properties.Resources.STaxi_MarkerB; break; case EnumMarkerCustom.MarkerC: Icon = Taxi.Controls.Properties.Resources.STaxi_MarkerC; break; case EnumMarkerCustom.MarkerD: Icon = Taxi.Controls.Properties.Resources.STaxi_MarkerD; break; case EnumMarkerCustom.MarkerE: case EnumMarkerCustom.MarkerF: case EnumMarkerCustom.MarkerG: case EnumMarkerCustom.MarkerH: default: Icon = Taxi.Controls.Properties.Resources.icon_dot_green; break; } Size = new System.Drawing.Size(Icon.Width, Icon.Height); }
/// <summary> /// Hàm xử lý lộ trình Theo google /// </summary> /// <param name="A">Điểm đầu</param> /// <param name="B">Điểm cuối</param> /// <returns>Lộ trình</returns> private static KeyValuePair <float, string> LayLoTrinhGo(GMap.NET.PointLatLng A, GMap.NET.PointLatLng B) { try { var route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(A, B, false, false, 15); if (route != null) { string address = string.Empty; //int n = 1; //if (route.Points.Count > 20) // n = (int)(route.Points.Count / 10); for (int i = 1; i < route.Points.Count - 1; i++) { address += string.Format("{0} {1};", (float)route.Points[i].Lat, (float)route.Points[i].Lng); } return(new KeyValuePair <float, string>((float)route.Distance, address)); } return(new KeyValuePair <float, string>(0, string.Empty)); } catch (Exception ex) { new Log().WriteLog(ThongTinDangNhap.USER_ID, "LayLoTrinhBA", DateTime.Now, ex.Message); return(new KeyValuePair <float, string>(0, string.Empty)); } }
//private void buildProjectTree() //{ // TreeNode root = treeView1.Nodes.Add("蒙内铁路"); // root.Checked = true; // TreeNode tn, leaf; // root.Tag = null; // tn = root.Nodes.Add("火车"); // tn.Checked = false; // tn.ImageIndex = 6; // if (CRailwayScene.mRoadList.Count > 0) // { // tn = root.Nodes.Add("路基"); // tn.Checked = true; // tn.ImageIndex = 1; // foreach (CRailwayProject p in CRailwayScene.mRoadList) // { // leaf = tn.Nodes.Add(p.mProjectName); // leaf.Tag = p; // leaf.ImageIndex = 1; // } // tn = root.Nodes.Add("桥梁"); // tn.Checked = true; // tn.ImageIndex = 2; // foreach (CRailwayProject p in CRailwayScene.mBridgeList) // { // leaf = tn.Nodes.Add(p.mProjectName); // leaf.Tag = p; // leaf.ImageIndex = 2; // } // tn = root.Nodes.Add("涵洞"); // tn.Checked = true; // tn.ImageIndex = 3; // foreach (CRailwayProject p in CRailwayScene.mTunnelList) // { // leaf = tn.Nodes.Add(p.mProjectName); // leaf.Tag = p; // leaf.ImageIndex = 3; // } // tn = root.Nodes.Add("车站工程"); // tn.Checked = true; // tn.ImageIndex = 4; // foreach (CRailwayProject p in CRailwayScene.mStationList) // { // leaf = tn.Nodes.Add(p.mProjectName); // leaf.Tag = p; // leaf.ImageIndex = 4; // } // tn = root.Nodes.Add("其他"); // tn.Checked = false; // tn.ImageIndex = 5; // foreach (CRailwayProject p in CRailwayScene.mOtherList) // { // leaf = tn.Nodes.Add(p.mProjectName); // leaf.Tag = p; // leaf.ImageIndex = 5; // } // } //} private void timerSyncronize_Tick(object sender, EventArgs e) { try { IPosition66 wp = sgworld.Window.CenterPixelToWorld().Position; GMap.NET.PointLatLng LatLng = marker.Position; LatLng.Lat = wp.Y; LatLng.Lng = wp.X; marker.Position = LatLng; LatLng = markerTrain.Position; LatLng.Lat = GlobalVar.gScene.mDynamicTrain.Position.Y; LatLng.Lng = GlobalVar.gScene.mDynamicTrain.Position.X; markerTrain.Position = LatLng; if (isFlying) { flyingTick++; if (flyingTick % 100 == 0) { sgworld.Navigate.FlyTo(GlobalVar.gScene.mDynamicTrain, nextFLyCode()); } } } catch (Exception ex) { Console.WriteLine("Train is not ready"); } }
/// <summary> /// Hàm xử lý lấy lộ trình và quãng đường theo tọa độ 2 điểm /// </summary> /// <param name="Alat"></param> /// <param name="Alng"></param> /// <param name="Blat"></param> /// <param name="Blng"></param> /// <returns></returns> public static LoTrinh LayLoTrinh(float Alat, float Alng, float Blat, float Blng) { var A = new GMap.NET.PointLatLng(Alat, Alng); var B = new GMap.NET.PointLatLng(Blat, Blng); return(LayLoTrinh(A, B)); }
public GMapHeatImage(GMap.NET.PointLatLng p, Image image) : base(p) { DisableRegionCheck = true; IsHitTestVisible = false; this.Image = image; }
protected async override void OnDrop(System.Windows.DragEventArgs e) { double currMapX = 0; double currMapY = 0; System.Windows.DataObject d = (System.Windows.DataObject)e.Data; string[] dataFormats = d.GetFormats(); string dataText = d.GetText(); Point position = e.GetPosition(this); GMap.NET.PointLatLng curPosition = FromLocalToLatLng((int)position.X, (int)position.Y); currMapX = curPosition.Lng; currMapY = curPosition.Lat; for (int i = 0; i < dataFormats.Length; i++) { string dragFormat = dataFormats[i]; if (dragFormat.Contains("FormationTree") && dataText == "Actor") { object dragObject = d.GetData(dragFormat); FormationTree formation = dragObject as FormationTree; if (formation == null) { continue; } enOSMhighwayFilter highwayFilter = enOSMhighwayFilter.Undefined; SetHighwayFilter(highwayFilter); shPointId PointId = await clsRoadRoutingWebApi.GetNearestPointIdOnRoad("0", highwayFilter, currMapX, currMapY); if (PointId != null) { shPoint pnt = PointId.point; DeployedFormation deployFormation = new DeployedFormation(); deployFormation.x = pnt.x; deployFormation.y = pnt.y; deployFormation.formation = formation; AtomData atom = await TDSClient.SAGInterface.SAGSignalR.DeployFormationFromTree(VMMainViewModel.Instance.SimulationHubProxy, deployFormation); if (atom != null) { AtomDeployedEventArgs args = new AtomDeployedEventArgs(); args.atom = atom; if (AtomDeployedEvent != null) { AtomDeployedEvent(this, args); } } } return; } } }
private void timerSyncronize_Tick(object sender, EventArgs e) { try { IPosition66 wp = sgworld.Window.CenterPixelToWorld().Position; GMap.NET.PointLatLng LatLng = marker.Position; LatLng.Lat = wp.Y; LatLng.Lng = wp.X; marker.Position = LatLng; //LatLng = markerTrain.Position; //LatLng.Lat = GlobalVar.gScene.mDynamicTrain.Position.Y; //LatLng.Lng = GlobalVar.gScene.mDynamicTrain.Position.X; //markerTrain.Position = LatLng; //if (isFlying) //{ // flyingTick++; // if (flyingTick % 100 == 0) //sgworld.Navigate.FlyTo(GlobalVar.gScene.mDynamicTrain, nextFLyCode()); //} if (trainBack) { sgworld.Creator.DeleteObject(mDynamicTrain.ID); mDynamicTrain = sgworld.Creator.CreateDynamicObject(0, DynamicMotionStyle.MOTION_MANUAL, DynamicObjectType.DYNAMIC_3D_MODEL, fileName, 0.25, AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE, string.Empty, "Train");//创建对象 double[] x, y, z, d; int n; n = gRWScene.mMiddleLines.getSubLineByDKCode(gRWScene.mProjectList[0].Mileage_Start_Discription, gRWScene.mProjectList[1].Mileage_Start_Discription, 70, out x, out y, out z, out d); if (n > 0) { for (int i = 200; i < 500; i++) //CRailwayScene.mMiddleLine.mPointNum 将一个工点上所有点addWaypoint { if (d[i] > 180) { d[i] = d[i] - 180; } mDynamicTrain.Waypoints.AddWaypoint(sgworld.Creator.CreateRouteWaypoint(x[i], y[i], z[i], 300, d[i])); } } mDynamicTrain.CircularRoute = false; sgworld.Navigate.FlyTo(mDynamicTrain); trainBack = false; //trainFly = true; } if (trainFly) { trainFly = false; } } catch (Exception ex) { Console.WriteLine("Train is not ready"); } }
public RoutePointMarker(GMap.NET.PointLatLng p, int routePointIndex, GMapRoute route) : base(p) { _route = route; _routePointIndex = routePointIndex; base.Size = new Size(8, 8); base.Offset = new Point((-1) * base.Size.Width / 2, (-1) * base.Size.Height / 2); }
private void addMarker_prev(GMap.NET.PointLatLng newPos) { GMap.NET.WindowsForms.GMapMarker marker = new GMap.NET.WindowsForms.Markers.GMarkerGoogle( newPos, GMap.NET.WindowsForms.Markers.GMarkerGoogleType.white_small); prev_markers.Markers.Add(marker); }
public void ConvertCoordGroundToPixel(double GroundX, double GroundY, ref int PixelX, ref int PixelY) { GMap.NET.PointLatLng Position = new GMap.NET.PointLatLng(); Position.Lat = GroundY; Position.Lng = GroundX; GMap.NET.GPoint p = FromLatLngToLocal(Position); PixelX = (int)p.X; PixelY = (int)p.Y; }
private GMap.NET.PointLatLng getNewCoordinates_gmap(GMap.NET.PointLatLng currentPosition, double dx, double dy) { int r_earth = 6378; GMap.NET.PointLatLng newPos = new GMap.NET.PointLatLng( currentPosition.Lat + ((double)dy / (double)r_earth) * (180.0 / Math.PI), currentPosition.Lng + ((double)dx / (double)r_earth) * (180.0 / Math.PI) / Math.Cos(currentPosition.Lat * Math.PI / 180.0)); return(newPos); }
public GMapEx() { this.AllowDrop = true; GMap.NET.PointLatLng Position = new GMap.NET.PointLatLng(0, 0); marker = new GMapMarker(Position); UserLayer = new UserDrawLayer(); marker.Shape = UserLayer; this.Markers.Add(marker); }
public GMapMarkerImage(GMap.NET.PointLatLng p, Image image) : base(p) { Size = new System.Drawing.Size(image.Width / 2, image.Height / 2); Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2); this.image = image; Pen = null; OutPen = null; }
public void ConvertCoordGroundToPixel(double GroundX,double GroundY,ref int PixelX,ref int PixelY) { GMap.NET.PointLatLng Position = new GMap.NET.PointLatLng(); Position.Lat = GroundY; Position.Lng = GroundX; GMap.NET.GPoint p = FromLatLngToLocal(Position); PixelX = (int)p.X; PixelY = (int)p.Y; }
internal static GMarkerGoogle CreateMarker(FortData Fort) { var Position = new GMap.NET.PointLatLng(Fort.Latitude, Fort.Longitude); var Result = new GMarkerGoogle(Position, (Bitmap)Bitmap.FromFile(string.Format("forts/{0}.png", (Fort.Type == AllEnum.FortType.Gym) ? (int)Fort.OwnedByTeam : 4))); Result.ToolTipText = MakeTooltip(Fort); return(Result); }
public Form1() { InitializeComponent(); gmap.MapProvider = GMap.NET.MapProviders.BingMapProvider.Instance; GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly; gmap.Position = new GMap.NET.PointLatLng(42.292315, -83.715531); lastPoint = new GMap.NET.PointLatLng(42.292315, -83.715531); gmap.MouseDoubleClick += new MouseEventHandler(MainMap_MouseDoubleClick); DroneTerminal.AppendText("Drone Battery: 98%" + Environment.NewLine); xbee = new Xbee(this); }
bool OnLButtonUp(int Flags, int X, int Y) { mCurPos = sgworld.Window.PixelToWorld(X, Y).Position; //GlobalVar.gCurPos = sgworld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_ABSOLUTE); GMap.NET.PointLatLng LatLng = marker.Position; LatLng.Lat = mCurPos.Y; LatLng.Lng = mCurPos.X; marker.Position = LatLng; //wp.Distance return(false); }
public static GMarkerGoogle GetMarker(this MapPokemon Pokemon) { var Position = new GMap.NET.PointLatLng(Pokemon.Latitude, Pokemon.Longitude); var Result = new GMarkerGoogle(Position, (Bitmap)Bitmap.FromFile(string.Format("icons/{0}.png", Pokemon.GetID()))); //Result.Size = new Size(Settings.POKEMON_IMAGE_SIZE, Settings.POKEMON_IMAGE_SIZE); Result.ToolTipText = MakeTooltip(Pokemon); return(Result); }
public async void GetPokemonFromPokeVision(GMapOverlay overlay) { try { var request = await _client.PokemonHttpClient.GetAsync("https://pokevision.com/map/scan/" + _client.CurrentLatitude + "/" + _client.CurrentLongitude); var response = request.Content.ReadAsStringAsync().Result; var parser = JObject.Parse(response); if (parser["status"].ToString() != "success") { return; } var result = new JObject(); do { var jobId = parser["jobId"]; var dataUrl = "https://pokevision.com/map/data/" + _client.CurrentLatitude + "/" + _client.CurrentLongitude + "/" + jobId; var data = await _client.PokemonHttpClient.GetAsync(dataUrl); var dataresponse = data.Content.ReadAsStringAsync().Result; result = JObject.Parse(dataresponse); } while (result["jobStatus"]?.ToString() == "in_progress"); JArray pokemon = (JArray)result["pokemon"]; overlay.Markers.Clear(); foreach (var item in pokemon) { var position = new GMap.NET.PointLatLng(Math.Round((double)item["latitude"], 12), Math.Round((double)item["longitude"], 12)); var pokemonId = (int)item["pokemonId"]; if (CaughtMarkers.Contains(new KeyValuePair <int, GMap.NET.PointLatLng>((int)item["pokemonId"], position))) { continue; } overlay.Markers.Add(new GMarkerGoogle(position, Images.GetPokemonImage(pokemonId))); } } catch (Exception ex) { // throw; } }
public Location GetLastLocation(string sTrackId) { if (string.IsNullOrEmpty(sTrackId)) return null; long trackId = Convert.ToInt64(sTrackId); IList<TrackPoint> list = null; using (Feng.IRepository rep = new Feng.NH.Repository("zkzx.model.config")) { Track track = rep.Get<Track>(trackId); if (track != null) { list = rep.List<TrackPoint>("from TrackPoint g where g.Track = :Track order by g.GpsTime desc", new Dictionary<string, object> { { "Track", track }, { "MaxResults", 1 } }); } } if (list == null) return null; TrackPoint gpsData = list[0]; GMap.NET.PointLatLng p1 = new GMap.NET.PointLatLng { Lat = gpsData.Latitude, Lng = gpsData.Longitude }; GMap.NET.PointLatLng p2; lock (Feng.Map.GoogleMapChinaOffset.Instance) { p2 = Feng.Map.GoogleMapChinaOffset.Instance.GetOffseted(p1); } return new Location { Latitude = p1.Lat, Longitude = p1.Lng, Heading = gpsData.Heading, LatitudeChina = p2.Lat, LongitudeChina = p2.Lng }; }
private void insertTrackPoint(Location loc) { bufferedPointInserts[numBufferedPointInserts] = loc; numBufferedPointInserts++; numberOfLocations++; if (numBufferedPointInserts >= MAX_BUFFERED_LOCATIONS) { flushPointInserts(); } }
/// /// <summary> * Reads trackpoint attributes and assigns them to the current location. /// * </summary> /// * <param name="attributes"> xml attributes </param> /// private void onTrackPointElementStart(IDictionary<string, string> attributes) { if (location != Location.Zero) { string errorMsg = createErrorMessage("Found a track point inside another one."); throw new SAXException(errorMsg); } location = createLocationFromAttributes(attributes); }
/// /// <summary> * Track point finished, write in database. /// * </summary> /// * <exception cref="SAXException"> - thrown if track point is invalid </exception> /// private void onTrackPointElementEnd() { if (true) { // insert in db insertTrackPoint(location); // first track point? if (lastLocation == null && numberOfSegments == 1) { //track.StartId = LastPointId; } lastLocation = location; lastSegmentLocation = location; location = Location.Zero; } //else //{ // // invalid location - abort import // string msg = createErrorMessage("Invalid location detected: " + location); // throw new SAXException(msg); //} }
private void UpdateUAVPosition() { if (GPS != null) { CultureInfo cultureInfo = new CultureInfo("en-US"); lbl_hasfix.Text = "GPS State:" + GPS["lbGSAFixMode"].Value.ToString() + " Altitude " + GPS["lbGGAAltitude"].Value.ToString() + " " + GPS["lbGGAAltitudeUnit"].Value.ToString()+ " Speed "+GPS["lbRMCSpeed"].Value.ToString(); GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(Convert.ToDouble(GPS["lbRMCPositionLatitude"].Value, cultureInfo), Convert.ToDouble(GPS["lbRMCPositionLongitude"].Value, cultureInfo)); if (UAVOverlay != null) { if (UAVOverlay.Markers.Count == 0) { UAVOverlay.Markers.Add(new GMapMarkerGoogleGreen(point)); } else { UAVOverlay.Markers[0].Position = point; } if (centerOnUAV) { this.gMapControl1.Position = point; this.gMapControl1.Update(); } this.gMapControl1.UpdateMarkerLocalPosition(UAVOverlay.Markers[0]); } } }
/// /// <summary> * Track segment started. </summary> /// private void onTrackSegmentElementStart() { if (numberOfSegments > 0) { // Add a segment separator: location = new Location(); location.Lat = 0.0; location.Lng = 0.0; //location.Altitude = 0; //if (lastLocation != Location.Zero) //{ // location.Time = lastLocation.Time; //} insertTrackPoint(location); lastLocation = location; //lastSegmentLocation = null; location = Location.Zero; } numberOfSegments++; }
private void OnMapDrag() { this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, new Action(delegate() { var amap = dockManager.ActiveContent.Content as GMap.NET.WindowsPresentation.GMapControl; if(amap != null) { last = amap.Position; foreach(var d in dockManager.Documents) { var map = d.Content as GMap.NET.WindowsPresentation.GMapControl; if(map != null && map != amap) { map.Position = amap.Position; } } } })); }
/// /// <summary> * Track finished - update in database. </summary> /// private void onTrackElementEnd() { if (lastLocation != Location.Zero) { flushPointInserts(); //track.StopId = LastPointId; track.trk = trkTypes.ToArray(); track.wpt = wptTypes.ToArray(); tracksWritten.Add(track); isCurrentTrackRollbackable = false; isCurrentTrackRollbackable = false; lastSegmentLocation = Location.Zero; lastLocation = Location.Zero; } else { // track contains no track points makes no real // sense to import it as we have no location // information -> roll back rollbackUnfinishedTracks(); } }
public Location GetLocation(string sTrackId) { if (string.IsNullOrEmpty(sTrackId)) return null; long trackId = Convert.ToInt64(sTrackId); lock (m_gpsData) { if (!m_gpsData.ContainsKey(trackId)) { m_gpsData[trackId] = ReloadTrackLocation(trackId); m_gpsDataIdx[trackId] = 0; } } if (m_gpsData.ContainsKey(trackId)) { int idx = m_gpsDataIdx[trackId]; TrackPoint gpsData = m_gpsData[trackId][idx]; GMap.NET.PointLatLng p1 = new GMap.NET.PointLatLng { Lat = gpsData.Latitude, Lng = gpsData.Longitude }; GMap.NET.PointLatLng p2; lock (Feng.Map.GoogleMapChinaOffset.Instance) { p2 = Feng.Map.GoogleMapChinaOffset.Instance.GetOffseted(p1); } idx++; if (idx >= m_gpsData[trackId].Count) { m_gpsData[trackId] = ReloadTrackLocation(trackId); } if (idx >= m_gpsData[trackId].Count) { //idx = 0; idx = m_gpsData[trackId].Count - 1; } m_gpsDataIdx[trackId] = idx; return new Location { Latitude = p1.Lat, Longitude = p1.Lng, Heading = gpsData.Heading, LatitudeChina = p2.Lat, LongitudeChina = p2.Lng }; } return null; }
/// <summary>Show the map</summary> public void ShowMap(List<Models.Map.Coordinate> coordinates) { mapControl.ScaleMode = ScaleModes.Fractional; mapControl.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance; mapControl.MinZoom = 1; mapControl.MaxZoom = 17; mapControl.Zoom = 1.4; //2; var overlayOne = new GMapOverlay("OverlayOne"); mapControl.Overlays.Add(overlayOne); foreach (Models.Map.Coordinate coordinate in coordinates) { GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(coordinate.Latitude,coordinate.Longitude); overlayOne.Markers.Add(new GMap.NET.WindowsForms.Markers.GMarkerGoogle(point, GMap.NET.WindowsForms.Markers.GMarkerGoogleType.green)); } }
private void DetermineOffset() { if (_UseOffset) { System.Drawing.Point topLeftReceived = new System.Drawing.Point(); System.Drawing.Point bottomRightReceived = new System.Drawing.Point(); if (_Core.tileDrawingList.GetExtension(ref topLeftReceived, ref bottomRightReceived)) { topLeftReceived = new System.Drawing.Point(topLeftReceived.X * _Core.Projection.TileSize.Width, topLeftReceived.Y * _Core.Projection.TileSize.Height); int zoom = _Core.Zoom; GMap.NET.PointLatLng topLeft = new GMap.NET.PointLatLng(_YMax, _XMin); GMap.NET.PointLatLng bottomRight = new GMap.NET.PointLatLng(_YMin, _XMax); //wo liegen der unterste und der rechteste Punkt GMap.NET.Point bottomRightPixel = _Core.Projection.FromLatLngToPixel(bottomRight, zoom); if (bottomRightPixel.X - topLeftReceived.X > pnlImage.ClientSize.Width) { _LeftOffset = bottomRightPixel.X - topLeftReceived.X - pnlImage.ClientSize.Width + 5; } else { _LeftOffset = 0; } if (bottomRightPixel.Y - topLeftReceived.Y > pnlImage.ClientSize.Height) { _TopOffset = bottomRightPixel.Y - topLeftReceived.Y - pnlImage.ClientSize.Height + 5; } else { _TopOffset = 0; } } else { _LeftOffset = 0; _TopOffset = 0; } } else { _LeftOffset = 0; _TopOffset = 0; } }
public void Draw() { if ((_Tracks == null) || (_Tracks.Count == 0)) { //GPX_TrackControl_Draw0=The TrackSegment to be drawn was either not set or is empty. throw new ApplicationException(ResourceManager.GetString("GPX_TrackControl_Draw0")); } if ((_WayPointsOnMap == null) || (_TracksOnMap.Count != _Tracks.Count)) CreateWaypointsList(); //determine applicable values //get maximum and minimum for x and y values each _XMax = double.MinValue; _YMax = double.MinValue; _XMin = double.MaxValue; _YMin = double.MaxValue; foreach (WayPointOnMap wpm in _WayPointsOnMap) { //Selected value: latitude, longitude, elevation, time, what ever.... wpm.XValue = GetSelectedValueFromWaypoint(wpm.WayPoint, _XCategory); wpm.YValue = GetSelectedValueFromWaypoint(wpm.WayPoint, _YCategory); _XMax = (_XMax < wpm.XValue) ? wpm.XValue : _XMax; _YMax = (_YMax < wpm.YValue) ? wpm.YValue : _YMax; _XMin = (_XMin > wpm.XValue) ? wpm.XValue : _XMin; _YMin = (_YMin > wpm.YValue) ? wpm.YValue : _YMin; } //get the size of control for drawing, reserve space for axes pnlImage.Width = Convert.ToInt32(this.ClientSize.Width * _Zoom); pnlImage.Height = Convert.ToInt32(this.ClientSize.Height * _Zoom); int drawWidth = pnlImage.Width - _LeftMargin - _TopMargin; int drawHeight = pnlImage.Height - _LowerMargin - _TopMargin; //now differentiate between external maps and internal graphs if (_ShowMap) { _UseOffset = true; _Core.BeginUpdate(); GMap.NET.CacheProviders.FilePureImageCache.CacheDate = _CacheDate; //center: that's the center point for the _Core object GMap.NET.PointLatLng center = new GMap.NET.PointLatLng((_YMax + _YMin) / 2, (_XMax + _XMin) / 2); _Core.CurrentPosition = center; _Core.MapType = _MapType; //top left and bottom right: for calculating zoom GMap.NET.PointLatLng topLeft = new GMap.NET.PointLatLng(_YMax, _XMin); GMap.NET.PointLatLng bottomRight = new GMap.NET.PointLatLng(_YMin, _XMax); //number of tiles fitting into the image int tilesX = drawWidth / _Core.Projection.TileSize.Width; int tilesY = drawHeight / _Core.Projection.TileSize.Height; //calculating zoom: when more tiles are required in one direction than fitting into the image //the zoom has been exceeded by 1. for (int zoomTmp = 0; zoomTmp <= 25; zoomTmp++) { GMap.NET.Point pixelTopLeft = _Core.Projection.FromLatLngToPixel(topLeft, zoomTmp); GMap.NET.Point tileTopLeft = _Core.Projection.FromPixelToTileXY(pixelTopLeft); GMap.NET.Point pixelBottomRight = _Core.Projection.FromLatLngToPixel(bottomRight, zoomTmp); GMap.NET.Point tileBottomRight = _Core.Projection.FromPixelToTileXY(pixelBottomRight); if ((tileBottomRight.X - tileTopLeft.X > tilesX) || (tileBottomRight.Y - tileTopLeft.Y > tilesY)) { _Core.Zoom = zoomTmp - 1; break; } } //set size _Core.OnMapSizeChanged(drawWidth - _Core.Projection.TileSize.Width, drawHeight - _Core.Projection.TileSize.Height); //get the MAP images _Core.EndUpdate(); } else { _UseOffset = false; DetermineOffset(); //sets offset values to 0 //scale for internal representation _XFactor = (_XMax - _XMin) / drawWidth; _YFactor = (_YMax - _YMin) / drawHeight; if (_UseEqualScale) { _XFactor = (_XFactor > _YFactor) ? _XFactor : _YFactor; _YFactor = _XFactor; } } //calculate position for each point foreach (WayPointOnMap wpm in _WayPointsOnMap) { if (!wpm.IsHidden) { int xPixel, yPixel; ValueToPixel((double)wpm.XValue, (double)wpm.YValue, out xPixel, out yPixel); wpm.XPixels = xPixel; wpm.YPixels = yPixel; } else { wpm.XPixels = -1; wpm.YPixels = -1; } } //Points of Interest foreach (WayPointOnMap poi in _PointsOfInterest) { //Selected value: latitude, longitude, elevation, time, what ever.... poi.XValue = GetSelectedValueFromWaypoint(poi.WayPoint, _XCategory); poi.YValue = GetSelectedValueFromWaypoint(poi.WayPoint, _YCategory); int xPixel, yPixel; ValueToPixel((double)poi.XValue, (double)poi.YValue, out xPixel, out yPixel); poi.XPixels = xPixel; poi.YPixels = yPixel; } //and now draw it! _Bitmap = new Bitmap(pnlImage.Width, pnlImage.Height); DrawTracks(); if (_ShowMap) { DrawGridForMap(); } else { DrawGrid(); } DrawPoI(); _Bitmap.Save(Defaults.TrackControl_BitmapPath, System.Drawing.Imaging.ImageFormat.Bmp); //@"C:\temp\bitmap.bmp" this.Refresh(); }
/// /// <summary> * Creates and returns a location with the position parsed from the given /// * attributes. /// * </summary> /// * <param name="attributes"> the attributes to parse </param> /// * <returns> the created location </returns> /// * <exception cref="SAXException"> if the attributes cannot be parsed </exception> /// private Location createLocationFromAttributes(IDictionary<string, string> attributes) { string latitude = attributes[ATT_LAT]; string longitude = attributes[ATT_LON]; if (latitude == null || longitude == null) { throw new SAXException(createErrorMessage("Point with no longitude or latitude")); } // create new location and set attributes Location loc = new Location(); try { loc.Lat = Convert.ToDouble(latitude); loc.Lng = Convert.ToDouble(longitude); } catch (NumberFormatException e) { string msg = createErrorMessage("Unable to parse lat/long: " + latitude + "/" + longitude); throw new SAXException(msg, e); } return loc; }
private List<GMap.NET.PointLatLng> ConvertTrackSegment(ITrackSegment segment) { List<GMap.NET.PointLatLng> points = new List<GMap.NET.PointLatLng>(segment.SegmentWaypoints.Count); for (int i = 0; i < segment.SegmentWaypoints.Count; i++) { GMap.NET.PointLatLng point = new GMap.NET.PointLatLng(); point.Lat = (double)segment.SegmentWaypoints[i].Latitude; point.Lng = (double)segment.SegmentWaypoints[i].Longitude; points.Add(point); } return points; }