/// <summary> /// 屏幕坐标系转地理坐标系 /// </summary> /// <param name="screenPos"></param> /// <returns></returns> private MyPoint ScreenToWGS84(Point screenPoint) { screenPoint.Y = picBoxMap.Height - screenPoint.Y; double centerScreenX = (double)picBoxMap.Width / 2; //屏幕坐标系中心点X坐标 double centerScreenY = (double)picBoxMap.Height / 2; //屏幕坐标系中心点Y坐标 double x = centerXY.X - (centerScreenX - screenPoint.X) * ratio * scaleChoice[scaleIndex]; //投影坐标系目标点X坐标 double y = centerXY.Y - (centerScreenY - screenPoint.Y) * ratio * scaleChoice[scaleIndex]; //投影坐标系目标点Y坐标 MyPoint xy = new MyPoint(x, y); //投影坐标系下的目标点 MyPoint lnglat = ETCProjection.XY2LngLat(xy); //WGS84坐标系下的目标点 return(lnglat); }
/// <summary> /// 移动选中的要素 /// </summary> /// <param name="deltaX">X方向移动量,屏幕坐标系</param> /// <param name="deltaY">y方向移动量,屏幕坐标系</param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> internal override void MoveSelectedFeature(int deltaX, int deltaY, Rectangle bounds, PointF centerPos, double scale) { for (int i = 0; i < polygons.Count; i++) { if (polygons[i].Selected == true) { for (int j = 0; j < polygons[i].PointCount; j++) { MyPoint pointXY = ETCProjection.LngLat2XY(polygons[i].Points[j]); pointXY.X += scale * deltaX; pointXY.Y -= scale * deltaY; polygons[i].Points[j] = ETCProjection.XY2LngLat(pointXY); } } } SetMaxMin(); }
/// <summary> /// 移动选中的要素 /// </summary> /// <param name="deltaX">X方向移动量,屏幕坐标系</param> /// <param name="deltaY">y方向移动量,屏幕坐标系</param> /// <param name="bounds"></param> /// <param name="centerPos"></param> /// <param name="scale"></param> internal override void MoveSelectedFeature(int deltaX, int deltaY, Rectangle bounds, PointF centerPos, double scale) { for (int i = 0; i < myPoints.Count; i++) { if (myPoints[i].Selected == true) { int id = myPoints[i].FID; MyPoint pointXY = ETCProjection.LngLat2XY(myPoints[i]); pointXY.X += scale * deltaX; pointXY.Y -= scale * deltaY; myPoints[i] = ETCProjection.XY2LngLat(pointXY); myPoints[i].FID = id; myPoints[i].Selected = true; } } SetMaxMin(); }
/// <summary> /// 地图鼠标移动事件 /// </summary> private void picBoxMap_MouseMove(object sender, MouseEventArgs e) { isClick = false; switch (operationType) { case MapOperation.SelectElement: break; case MapOperation.ZoomIn: break; case MapOperation.ZoomOut: break; case MapOperation.Pan: //漫游 if (e.Button == MouseButtons.Left) { int deltaX = e.X - mouseOldLoc.X; int deltaY = e.Y - mouseOldLoc.Y; centerXY = ETCProjection.LngLat2XY(centerLngLat); centerXY.X -= deltaX * (float)ratio * (float)scaleChoice[scaleIndex]; centerXY.Y += deltaY * (float)ratio * (float)scaleChoice[scaleIndex]; //由于屏幕坐标系是左上坐标系,和地理坐标系相反,所以这里应该是+ centerLngLat = ETCProjection.XY2LngLat(centerXY); mouseOldLoc = e.Location; UpdateMapImg(); } break; case MapOperation.SelectFeatures: //选择要素 if (e.Button == MouseButtons.Left) { picBoxMap.Refresh(); int minX = Math.Min(startPoint.X, e.Location.X); int maxX = Math.Max(startPoint.X, e.Location.X); int minY = Math.Min(startPoint.Y, e.Location.Y); int maxY = Math.Max(startPoint.Y, e.Location.Y); DrawSelectBox(minX, minY, maxX - minX, maxY - minY); //画选择盒 } break; case MapOperation.Edit: //编辑要素 if (e.Button == System.Windows.Forms.MouseButtons.Left) { int deltaX = e.X - mouseOldLoc.X; int deltaY = e.Y - mouseOldLoc.Y; myMap.Layers[EditingIndex].MoveSelectedFeature(deltaX, deltaY, picBoxMap.Bounds, centerLngLat, ratio * scaleChoice[scaleIndex]); mouseOldLoc = e.Location; UpdateMapImg(); } break; case MapOperation.EditVertices: //编辑要素顶点 if (e.Button == System.Windows.Forms.MouseButtons.Left) { picBoxMap.Cursor = Cursors.SizeAll; myMap.Layers[EditingIndex].MoveVertex(ScreenToWGS84(e.Location)); UpdateMapImg(); } break; case MapOperation.CreateFeatures: //创建要素 if (trackingPoints.Count > 0) { picBoxMap.Refresh(); DrawTrackingFeature(); DrawRubberBand(e.Location); //画橡皮筋 } break; } //更新鼠标当前位置对应地理坐标 MyPoint mouseLngLat = ScreenToWGS84(e.Location); StatusStripLblCoordinate.Text = mouseLngLat.X.ToString() + "," + mouseLngLat.Y.ToString(); StatusStripLblScale.Text = MapScale.ToString(); }