【发布时间】:2017-01-05 08:30:18
【问题描述】:
我的GMap .Net Windows form Application 中有一个名为"BBB"(figure1,figure2) 的路线/多边形。我正在从鼠标中绘制路线/多边形并将所有纬度和经度存储到List<PointLatLng>。我想要的是两个相交之间的纬度和经度集点(纬度和经度)。
注意: 我有路线/多边形
"BBB"(figure1,figure2)和"CCC"(figure1,figure2)的所有纬度和经度。
如果有不清楚的地方请告诉我。是否有任何库或 Api ?
代码:一些创意代码
List<PointLatLng> ListOfDragLatLang = new List<PointLatLng>();
PointLatLng StartingLatLng = new PointLatLng();
PointLatLng EndingLatLng = new PointLatLng();
// polygons
GMapPolygon polygon;
readonly GMapOverlay top = new GMapOverlay();
internal readonly GMapOverlay objects = new GMapOverlay("objects");//for storing markers
internal readonly GMapOverlay routes = new GMapOverlay("routes");// for storing routes
internal readonly GMapOverlay polygons = new GMapOverlay("polygons");//for storing polygons
public bool IsErasorCursorVisible { get => _IsErasorCursorVisible; set => _IsErasorCursorVisible = value; }
public bool IsPencilCursorVisible { get => _IsPencilCursorVisible; set => _IsPencilCursorVisible = value; }
public bool IsNormalCursorVisible { get => _IsNormalCursorVisible; set => _IsNormalCursorVisible = value; }
private void MainMap_MouseUp(object sender, MouseEventArgs e)
{
PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);
lblLatitude.Text = OnMouse.Lat.ToString();
lblLongitude.Text = OnMouse.Lng.ToString();
if (IsPencilCursorVisible && IsDrawing)
{
EndingLatLng = MainMap.FromLocalToLatLng(e.X, e.Y);
ListOfDragLatLang.Add(StartingLatLng);
IsDragging = false;
IsDrawing = false;
MainMap.DragButton = MouseButtons.Right;
//polygon = new GMapPolygon(ListOfDragLatLang, txtZoneName.Text);
//polygon.LocalPoints.AddRange(ListOfPoints);
//polygon.Stroke = new Pen(Color.Black, 3);
//polygon.IsHitTestVisible = true;
//polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
//polygons.Polygons.Add(polygon);
//MainMap.UpdatePolygonLocalPosition(polygon);
lblTotalPolygonsAdded.Text = polygons.Polygons.Count.ToString();
for (int i = 0; i < ListOfDragLatLang.Count; i++)
{
AddPinPointToPolygon(ListOfDragLatLang[i], i, txtZoneName.Text);
}
RegenerateRoute(txtZoneName.Text);
GMarkerGoogle marker = new GMarkerGoogle(new PointLatLng(ListOfDragLatLang.Sum(c => c.Lat) / ListOfDragLatLang.Count, ListOfDragLatLang.Sum(c => c.Lng) / ListOfDragLatLang.Count), GMarkerGoogleType.orange_dot);
marker.ToolTip = new GMapBaloonToolTip(marker);
marker.ToolTipText = txtZoneName.Text;
marker.ToolTipMode = MarkerTooltipMode.Always;
marker.IsVisible = true;
marker.Tag = txtZoneName.Text;
objects.Markers.Add(marker);
MainMap.UpdateMarkerLocalPosition(marker);
MainMap.UpdatePolygonLocalPosition(polygon);
}
}
private void MainMap_MouseDown(object sender, MouseEventArgs e)
{
PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);
if (e.Button == MouseButtons.Left)
{
if (IsPencilCursorVisible && IsDrawing)
{
StartingLatLng = OnMouse;
ListOfDragLatLang.Add(StartingLatLng);
ListOfPoints.Add(new GPoint(e.X, e.Y));
IsDragging = true;
MainMap.DragButton = MouseButtons.Middle;
currentRoute = new GMapRoute(txtZoneName.Text);
currentRoute.Stroke = new Pen(Color.Black, 3);
currentRoute.IsHitTestVisible = true;
routes.Routes.Add(currentRoute);
MainMap.UpdateRouteLocalPosition(currentRoute);
//polygon = new GMapPolygon(ListOfDragLatLang,txtZoneName.Text);
//polygon.LocalPoints.AddRange(ListOfPoints);
//polygon.Stroke = new Pen(Color.Black, 3);
//polygon.IsHitTestVisible = true;
//polygon.Stroke.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
//polygons.Polygons.Add(polygon);
//MainMap.UpdatePolygonLocalPosition(polygon);
}
}
}
private void MainMap_MouseMove(object sender, MouseEventArgs e)
{
PointLatLng OnMouse = MainMap.FromLocalToLatLng(e.X, e.Y);
lblLatitude.Text = OnMouse.Lat.ToString();
lblLongitude.Text = OnMouse.Lng.ToString();
if (e.Button == MouseButtons.Left)
{
if (IsPencilCursorVisible && IsDrawing)
{
if (MainMap.IsMouseOverPolygon)
{
MainMap.Cursor = MainCursor;
}
else
{
MainMap.Cursor = PencilCursor;
}
IsDragging = true;
ListOfPoints.Add(new GPoint(e.X, e.Y));
ListOfDragLatLang.Add(OnMouse);
lblTotalLatLng.Text = ListOfDragLatLang.Count.ToString();
currentRoute.Points.Add(OnMouse);
MainMap.UpdateRouteLocalPosition(currentRoute);
//polygon.Points.Add(OnMouse);
//MainMap.UpdatePolygonLocalPosition(polygon);
}
else
{
PointLatLng pnew = MainMap.FromLocalToLatLng(e.X, e.Y);
if (CurentRectMarker == null)
{
return;
}
int? pIndex = (int?)CurentRectMarker.Tag;
if (pIndex.HasValue)
{
if (pIndex < currentRoute.Points.Count)
{
currentRoute.Points[pIndex.Value] = pnew;
MainMap.UpdateRouteLocalPosition(currentRoute);
}
//if (pIndex < polygon.Points.Count)
//{
// polygon.Points[pIndex.Value] = pnew;
// MainMap.UpdatePolygonLocalPosition(polygon);
//}
}
if (currentMarker.IsVisible)
{
currentMarker.Position = pnew;
}
CurentRectMarker.Position = pnew;
if (CurentRectMarker.InnerMarker != null)
{
CurentRectMarker.InnerMarker.Position = pnew;
}
}
MainMap.Refresh();
}
}
图 1
问题:图2中yellow color edge的经纬度在"A"和"B"的交点之间如何得到?
【问题讨论】:
-
如果您自己绘制多边形,您不应该已经拥有长纬度吗?对不起,我没有收到你的问题
-
@UzairAhmedSiddiqui 我有多边形红色和黑色的纬度,但我只想要黄色的纬度
标签: c# google-maps polygon gmap.net