原理:
先获取控件的四个顶点,逐一将其转换成经纬度坐标。
private void GetBonds() { //左上↖ PointLatLng pLeftTop = map1.FromLocalToLatLng(map1.Left, map1.Top); //左下↙ PointLatLng pLeftDown = map1.FromLocalToLatLng(map1.Left, map1.Top + map1.Height); //右上↗ PointLatLng pRightTop = map1.FromLocalToLatLng(map1.Left + map1.Width, map1.Top); //右下↘ PointLatLng pRightDown = map1.FromLocalToLatLng(map1.Left + map1.Width, map1.Top + map1.Height); MapHelper.AddMarker(layMarkers, pLeftTop, Properties.Resources.mark_red_dot); MapHelper.AddMarker(layMarkers, pLeftDown, Properties.Resources.mark_red_dot); MapHelper.AddMarker(layMarkers, pRightTop, Properties.Resources.mark_red_dot); MapHelper.AddMarker(layMarkers, pRightDown, Properties.Resources.mark_red_dot); }
拖拽完成后执行
void map1_MouseUp(object sender, MouseEventArgs e) { if (map1.IsDragging) { GetBonds(); } }