/// <summary> /// 计算宽 /// </summary> /// <returns></returns> private int CalcuWidth() { var point1 = gmapControl.FromLatLngToLocal(listPoints[1]); var point2 = gmapControl.FromLatLngToLocal(listPoints[3]); return(Math.Abs((int)point1.X - (int)point2.X)); }
/// <summary> /// regenerates shape of route /// </summary> public virtual void RegenerateShape(GMapControl map) { if (map != null) { Map = map; if (Points.Count > 1) { Position = Points[0]; var localPath = new List <System.Windows.Point>(); var offset = Map.FromLatLngToLocal(Points[0]); foreach (var i in Points) { var p = Map.FromLatLngToLocal(new PointLatLng(i.Lat, i.Lng)); localPath.Add(new System.Windows.Point(p.X - offset.X, p.Y - offset.Y)); } var shape = map.CreateRoutePath(localPath); if (this.Shape != null && this.Shape is Path) { (this.Shape as Path).Data = shape.Data; } else { this.Shape = shape; } } else { this.Shape = null; } } }
private void drawRect(SquareRect sRect, DrawingContext context) { GPoint[] points = new GPoint[] { mapView.FromLatLngToLocal(new PointLatLng(sRect.rect.Y + sRect.rect.Height, sRect.rect.X)), mapView.FromLatLngToLocal(new PointLatLng(sRect.rect.Y, sRect.rect.X + sRect.rect.Width)) }; Rect rect = new Rect(points[0].X, points[0].Y, points[1].X - points[0].X, points[1].Y - points[0].Y);; context.DrawRectangle(sRect.brush, sRect.pen, rect); }
/* 滑鼠位於標記點上時,滾輪滑動事件處理 * * 說明: * 在GMap中,如果對Zoom值直接修,作畫面進行縮放時,中心點會維持不變 * 而此事件情況為滑鼠滑鼠位於標記點上時,使用者通常希望觀看標記點的資訊 * 所以滑鼠所位於的標記點,必須在畫面上保持不動 * * 以下作法為 * 先記錄標記點在畫面的位置 (mouseLastZoom) * 以標記點做為中心進行縮放 (Zoom+-) * * 算出先前已記錄畫面位置的點與畫面中心的像素差 (renderOffset) * 此像素差即為整張地圖所需的位移量 * * 算出新的中心點像素位置:當前標記點的像素位置+位移量 * 算出中心點經緯座標:FromPixelToLatLng */ private void ProjectMarker_MouseWheel(object sender, MouseWheelEventArgs e) { // latlng position of the project PointLatLng projectPosition = new PointLatLng(Project.lat, Project.lng); // local position of the project GPoint mouseLastZoom = gMap.FromLatLngToLocal(projectPosition); // center zoom to project gMap.Position = projectPosition; gMap.Zoom += (e.Delta > 0) ? 1 : -1; int zoom = (int)gMap.Zoom; // compute render offset GPoint renderOffset = GPoint.Empty; renderOffset.X = (int)gMap.RenderSize.Width / 2 - mouseLastZoom.X; renderOffset.Y = (int)gMap.RenderSize.Height / 2 - mouseLastZoom.Y; // current pixel position of the project GPoint positionPixel = gMap.MapProvider.Projection.FromLatLngToPixel(projectPosition, zoom); // new center position in pixel positionPixel.Offset(renderOffset); // compute and set the latlng of new center position gMap.Position = gMap.MapProvider.Projection.FromPixelToLatLng(positionPixel, zoom); }
/// <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; }
/// <summary> /// 地理坐标转化为屏幕坐标 /// </summary> /// <param name="lon">经度</param> /// <param name="lat">纬度</param> /// <param name="alt">高度</param> /// <returns></returns> public System.Drawing.Point GeographyToScenePoint(double lon, double lat, double alt = 0) { PointLatLng latlng = new PointLatLng(lat, lon); GPoint p = gmapControl.FromLatLngToLocal(latlng); System.Drawing.Point point = new System.Drawing.Point((int)p.X, (int)p.Y); return(point); }
public PointLatLng[] CreateBesizer(GMapControl mapControl, PointLatLng startPos, PointLatLng endPos) { Point point = new Point((int)mapControl.FromLatLngToLocal(startPos).X, (int)mapControl.FromLatLngToLocal(startPos).Y); Point point2 = new Point((int)mapControl.FromLatLngToLocal(endPos).X, (int)mapControl.FromLatLngToLocal(endPos).Y); double x = Math.Sqrt(Math.Pow((double)(point2.X - point.X), 2.0) + Math.Pow((double)(point2.Y - point.Y), 2.0)) / 4.0; int num2 = 1; if ((point2.Y - point.Y) != 0) { num2 = (point2.Y - point.Y) / Math.Abs((int)(point2.Y - point.Y)); } else if ((point2.X - point.X) != 0) { num2 = (point2.X - point.X) / Math.Abs((int)(point2.X - point.X)); } double num3 = ((double)(point.X - point2.X)) / ((double)(point2.Y - point.Y)); PointF tf = new PointF((((float)(3 * point.X)) / 4f) + (((float)point2.X) / 4f), (((float)(3 * point.Y)) / 4f) + (((float)point2.Y) / 4f)); PointF tf2 = new PointF((((float)point.X) / 4f) + (((float)(3 * point2.X)) / 4f), (((float)point.Y) / 4f) + (((float)(3 * point2.Y)) / 4f)); double num4 = tf.Y - (num3 * tf.X); double num5 = tf2.Y - (num3 * tf2.X); double num6 = Math.Pow(num3, 2.0) + 1.0; double num7 = 2.0 * (((num3 * num4) - (num3 * tf.Y)) - tf.X); double num8 = (Math.Pow((double)tf.X, 2.0) + Math.Pow(num4 - tf.Y, 2.0)) - Math.Pow(x, 2.0); double num9 = (-num7 + (num2 * Math.Sqrt(Math.Pow(num7, 2.0) - ((4.0 * num6) * num8)))) / (2.0 * num6); double num10 = (num3 * num9) + num4; double num11 = Math.Pow(num3, 2.0) + 1.0; double num12 = 2.0 * (((num3 * num5) - (num3 * tf2.Y)) - tf2.X); double num13 = (Math.Pow((double)tf2.X, 2.0) + Math.Pow(num5 - tf2.Y, 2.0)) - Math.Pow(x, 2.0); double num14 = (-num12 + (num2 * Math.Sqrt(Math.Pow(num12, 2.0) - ((4.0 * num11) * num13)))) / (2.0 * num11); double num15 = (num3 * num14) + num5; PointF tf3 = new PointF((float)num9, (float)num10); PointF tf4 = new PointF((float)num14, (float)num15); if ((point2.Y - point.Y) == 0) { tf3 = new PointF(tf.X, tf.Y + ((float)(num2 * x))); tf4 = new PointF(tf2.X, tf.Y + ((float)(num2 * x))); } List<PointLatLng> pointList = new List<PointLatLng>(); PointLatLng pll3 = mapControl.FromLocalToLatLng((int)tf3.X, (int)tf3.Y); PointLatLng pll4 = mapControl.FromLocalToLatLng((int)tf4.X, (int)tf4.Y); pointList.Add(startPos); pointList.Add(pll3); pointList.Add(pll4); pointList.Add(endPos); PointLatLng[] points = GetBezierPoints(pointList.ToArray(), 1000); return points; }
public override void RegenerateShape(GMapControl map) { if (map != null) { if (Points.Count > 1) { var localPath = new List <Point>(); var offset = map.FromLatLngToLocal(Points[0]); foreach (PointLatLng i in Points) { var p = map.FromLatLngToLocal(new PointLatLng(i.Lat, i.Lng)); localPath.Add(new Point(p.X - offset.X, p.Y - offset.Y)); } // Create a StreamGeometry to use to specify myPath. var geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(localPath[0], true, true); // Draw a line to the next specified point. ctx.PolyLineTo(localPath, true, true); } // Freeze the geometry (make it unmodifiable) // for additional performance benefits. geometry.Freeze(); // Create a path to draw a geometry with. Shape = new Path { Data = geometry, Fill = Brushes.Transparent, StrokeThickness = 20, Stroke = Brushes.Transparent, IsHitTestVisible = true }; } else { Shape = null; } } }
private RectLatLng GetBounds(PointLatLng point) { var local = _gMap.FromLatLngToLocal(point); var t = local.Y - _gridYPixels / 2; var l = local.X - _gridXPixels / 2; var b = local.Y + _gridYPixels / 2; var r = local.X + _gridXPixels / 2; var tl = _gMap.FromLocalToLatLng((int)l, (int)t); var br = _gMap.FromLocalToLatLng((int)r, (int)b); return(new RectLatLng(tl.Lat, tl.Lng, br.Lng - tl.Lng, Math.Abs(br.Lat - tl.Lat))); }
public double GetSlope(PointLatLng InitialPosition, PointLatLng FinalPosition) { GMapControl control = new GMapControl(); GPoint p1 = control.FromLatLngToLocal(InitialPosition); GPoint p2 = control.FromLatLngToLocal(FinalPosition); Point3D point = Geodetic2ENU(FinalPosition, InitialPosition); double slope1 = Math.PI / 2 - Math.Atan2((point.Y), (point.X)); double slope2 = -Math.PI / 2 - Math.Atan2((InitialPosition.Lat - FinalPosition.Lat), (InitialPosition.Lng - FinalPosition.Lng)); double slope3 = Math.Atan2(p2.Y - p1.Y, p2.X - p1.X); if (slope2 > Math.PI) { slope2 -= 2 * Math.PI; } else if (slope2 < -Math.PI) { slope2 += 2 * Math.PI; } return(slope2);// -Math.PI / 2 - Math.Atan2((InitialPosition.Lat - FinalPosition.Lat), (InitialPosition.Lng - FinalPosition.Lng)); //return Math.PI / 2 - Math.Atan2((point.Y) ,(point.X)); }
/// <summary> /// 画圆 /// </summary> /// <param name="circleCenter">圆心</param> /// <param name="r">半径</param> public static void CreateCircle(PointLatLng circleCenter, double radius1, double radius2, GMapControl gMapCtrl) { radius1 = radius1 * 1000; radius2 = radius2 * 1000; GSCoordConvertionClass_Xian80 cc = new GSCoordConvertionClass_Xian80(); cc.IsBigNumber = true; cc.Strip = EnumStrip.Strip3; cc.L0 = decimal.Parse(circleCenter.Lng.ToString()); decimal x = decimal.MinValue, y = decimal.MinValue; cc.GetXYFromBL(decimal.Parse(circleCenter.Lat.ToString()), decimal.Parse(circleCenter.Lng.ToString()), ref x, ref y); GPoint gp = gMapCtrl.FromLatLngToLocal(circleCenter); List <PointLatLng> gpollist = new List <PointLatLng>(); double seg = Math.PI * 2 / 100; for (int i = 0; i < 100; i++) { double theta = seg * i; decimal a = decimal.Parse((double.Parse(x.ToString()) + Math.Cos(theta) * radius1).ToString()); decimal b = decimal.Parse((double.Parse(y.ToString()) + Math.Sin(theta) * radius1).ToString()); decimal B = decimal.MinValue, L = decimal.MinValue; cc.GetBLFromXY(a, b, ref B, ref L); PointLatLng gpoi = new PointLatLng(double.Parse(B.ToString()), double.Parse(L.ToString())); gpollist.Add(gpoi); } GMapMarkerCircle gpol = new GMapMarkerCircle(circleCenter, (int)radius1, (int)radius2); // GMapPolygon gpol = new GMapPolygon(gpollist, "circlePolygon"); //gpol.Fill = new SolidBrush(Color.FromArgb(50, 0, 155, 255)); //gpol.Stroke = new Pen(Color.FromArgb(50, 0, 155, 255), 0); GMapOverlay CircleOverlay = new GMapOverlay("circleOverlay"); CircleOverlay.Markers.Add(gpol); gMapCtrl.Overlays.Add(CircleOverlay); }
//鼠标双击,打开文字编辑控件 private void gmapControl_DoubleClick(object sender, EventArgs e) { if (bTextOn == false) { return; } Font font = element.GetFont(); Color color = element.GetColor(); GPoint p = gmapControl.FromLatLngToLocal(marker.Position); Point viewPoint = new Point((int)p.X, (int)p.Y); beforeContext = element.GetContext(); textCtrl.Location = viewPoint; textCtrl.SetText(beforeContext); textCtrl.SetColor(color); textCtrl.SetFont(font); gmapControl.Controls.Add(textCtrl); }
/// <summary> /// 地理坐标转屏幕坐标 /// </summary> /// <param name="position">地理坐标</param> /// <returns>屏幕坐标</returns> public System.Drawing.Point FromLngLatToLocal(MapLngLat position) { var p = mapControl.FromLatLngToLocal(new PointLatLng(position.Lat, position.Lng)); return(new System.Drawing.Point((int)p.X, (int)p.Y)); }
private Point GetPoint(GpsPointData data, GMapControl map) { GMap.NET.GPoint pt0 = map.FromLatLngToLocal(new GMap.NET.PointLatLng(data.Latitude, data.Longitude)); return(new Point(pt0.X, pt0.Y)); }
public GPoint FromLatLngToLocal(PointLatLng p) { return(_gMap.FromLatLngToLocal(p)); }
public override void RegenerateShape(GMapControl map) { if (map != null) { if (Points.Count > 1) { var localPath = new List <Point>(); var offset = map.FromLatLngToLocal(Points[0]); foreach (PointLatLng i in Points) { var p = map.FromLatLngToLocal(new PointLatLng(i.Lat, i.Lng)); localPath.Add(new Point(p.X - offset.X, p.Y - offset.Y)); } // Create a StreamGeometry to use to specify myPath. var geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(localPath[0], true, true); // Draw a line to the next specified point. ctx.PolyLineTo(localPath, true, true); } // Freeze the geometry (make it unmodifiable) // for additional performance benefits. geometry.Freeze(); var fillBrush = new SolidColorBrush(); BindingOperations.SetBinding(fillBrush, SolidColorBrush.ColorProperty, new Binding("Variety.ClusterIndex") { Converter = new IndexToColorConverter(), ConverterParameter = Colors.CornflowerBlue }); var strokeBrush = new SolidColorBrush(); BindingOperations.SetBinding(strokeBrush, SolidColorBrush.ColorProperty, new Binding("Color") { Source = fillBrush, Converter = new ColorBrightnessConverter(), ConverterParameter = -0.15 }); // Create a path to draw a geometry with. var path = new Path { Data = geometry, Effect = new BlurEffect { KernelType = KernelType.Gaussian, Radius = 3.0, RenderingBias = RenderingBias.Quality }, Stroke = strokeBrush, Fill = fillBrush, StrokeThickness = 3, Opacity = 0.5, IsHitTestVisible = true, DataContext = _region, Visibility = Shape == null ? Visibility.Visible : Shape.Visibility }; Shape = path; Shape.MouseEnter += Shape_MouseEnter; Shape.MouseLeave += Region_MouseLeave; } else { Shape = null; } } }
public override void OnRender(Graphics g) { base.OnRender(g); g.SmoothingMode = SmoothingMode.AntiAlias; if (this.isArrow) { pen.EndCap = LineCap.ArrowAnchor; pen.CustomEndCap = new AdjustableArrowCap(5f, 10f, true); } GMapControl control = this.Overlay.Control; Point point = new Point(base.LocalPosition.X, base.LocalPosition.Y); Point point2 = new Point(base.LocalPosition.X + (((int)control.FromLatLngToLocal(this.endPos).X) - ((int)control.FromLatLngToLocal(this.startPos).X)), (base.LocalPosition.Y + ((int)control.FromLatLngToLocal(this.endPos).Y)) - ((int)control.FromLatLngToLocal(this.startPos).Y)); double x = Math.Sqrt(Math.Pow((double)(point2.X - point.X), 2.0) + Math.Pow((double)(point2.Y - point.Y), 2.0)) / 4.0; int num2 = 1; if ((point2.Y - point.Y) != 0) { num2 = (point2.Y - point.Y) / Math.Abs((int)(point2.Y - point.Y)); } else if ((point2.X - point.X) != 0) { num2 = (point2.X - point.X) / Math.Abs((int)(point2.X - point.X)); } double num3 = ((double)(point.X - point2.X)) / ((double)(point2.Y - point.Y)); PointF tf = new PointF((((float)(3 * point.X)) / 4f) + (((float)point2.X) / 4f), (((float)(3 * point.Y)) / 4f) + (((float)point2.Y) / 4f)); PointF tf2 = new PointF((((float)point.X) / 4f) + (((float)(3 * point2.X)) / 4f), (((float)point.Y) / 4f) + (((float)(3 * point2.Y)) / 4f)); double num4 = tf.Y - (num3 * tf.X); double num5 = tf2.Y - (num3 * tf2.X); double num6 = Math.Pow(num3, 2.0) + 1.0; double num7 = 2.0 * (((num3 * num4) - (num3 * tf.Y)) - tf.X); double num8 = (Math.Pow((double)tf.X, 2.0) + Math.Pow(num4 - tf.Y, 2.0)) - Math.Pow(x, 2.0); double num9 = (-num7 + (num2 * Math.Sqrt(Math.Pow(num7, 2.0) - ((4.0 * num6) * num8)))) / (2.0 * num6); double num10 = (num3 * num9) + num4; double num11 = Math.Pow(num3, 2.0) + 1.0; double num12 = 2.0 * (((num3 * num5) - (num3 * tf2.Y)) - tf2.X); double num13 = (Math.Pow((double)tf2.X, 2.0) + Math.Pow(num5 - tf2.Y, 2.0)) - Math.Pow(x, 2.0); double num14 = (-num12 + (num2 * Math.Sqrt(Math.Pow(num12, 2.0) - ((4.0 * num11) * num13)))) / (2.0 * num11); double num15 = (num3 * num14) + num5; PointF tf3 = new PointF((float)num9, (float)num10); PointF tf4 = new PointF((float)num14, (float)num15); if ((point2.Y - point.Y) == 0) { tf3 = new PointF(tf.X, tf.Y + ((float)(num2 * x))); tf4 = new PointF(tf2.X, tf.Y + ((float)(num2 * x))); } g.DrawBezier(pen, (PointF)point, tf3, tf4, (PointF)point2); List <Point> pointList = new List <Point>(); pointList.Add(point); pointList.Add(new Point((int)tf3.X, (int)tf3.Y)); pointList.Add(new Point((int)tf4.X, (int)tf4.Y)); pointList.Add(point2); Point[] points = GetBezierPoints(pointList.ToArray(), 1000); if (tipText != null) { System.Drawing.Size st = g.MeasureString(tipText, TipFont).ToSize(); g.DrawString(tipText, TipFont, TipBrush, points[points.Length / 2], TipFormat); } }