MapRangeSelectForm.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using DevExpress.CodeParser;
  2. using DevExpress.XtraEditors;
  3. using DevExpress.XtraEditors.Controls;
  4. using DevExpress.XtraMap;
  5. using Ips.Library.Basic;
  6. using Ips.Library.DxpLib;
  7. using Ips.Library.Entity;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Net;
  15. using System.Text;
  16. using System.Threading.Tasks;
  17. using System.Windows.Forms;
  18. namespace Ips.Sps.Maps
  19. {
  20. public partial class MapRangeSelectForm : DevExpress.XtraEditors.XtraForm
  21. {
  22. public MapRangeSelectForm()
  23. {
  24. InitializeComponent();
  25. InitMap();
  26. }
  27. public MapRangeSelectForm(GeoRange geoRange) : this()
  28. {
  29. SelectRange = geoRange;
  30. }
  31. MapEditor Editor { get { return mapControl.MapEditor; } }
  32. MapRectangle rectItem;
  33. MapDot centerPoint;
  34. public GeoRange SelectRange { get; set; }
  35. void InitMap()
  36. {
  37. mapControl.InitIpsOptions(new IpsMapOption()
  38. {
  39. ZoomLevel = 4d,
  40. CircularScrollingMode = CircularScrollingMode.None
  41. });
  42. centerPoint = new MapDot()
  43. {
  44. Fill = Color.Red,
  45. Size = 8,
  46. Visible = false
  47. };
  48. rectItemStorage.Items.Add(centerPoint);
  49. }
  50. private void MapRangeSelectForm_Load(object sender, EventArgs e)
  51. {
  52. Editor.ActiveLayer = rectItemsLayer;
  53. Editor.MapItemCreating += Editor_MapItemCreating;
  54. Editor.MapItemEditing += Editor_MapItemEditing;
  55. Editor.MapItemEdited += Editor_MapItemEdited;
  56. centerPoint.Visible = SelectRange != null;
  57. if (SelectRange != null)
  58. {
  59. var startPoint = new GeoPoint(SelectRange.LatMax, SelectRange.LonMin);
  60. var endPoint = new GeoPoint(SelectRange.LatMin, SelectRange.LonMax);
  61. rectItem = MapRectangle.FromLeftTopRightBottom(mapControl.CoordinateSystem, startPoint, endPoint);
  62. rectItemStorage.Items.Clear();
  63. SetItemStyle(rectItem);
  64. rectItemStorage.Items.Add(rectItem);
  65. rectItemStorage.Items.Add(centerPoint);
  66. centerPoint.Location = new GeoPoint(SelectRange.Lat, SelectRange.Lon);
  67. txtLon.EditValue = SelectRange.Lon;
  68. txtLat.EditValue = SelectRange.Lat;
  69. txtAlt.EditValue = SelectRange.Alt;
  70. txtLonRange.EditValue = SelectRange.LonRange;
  71. txtLatRange.EditValue = SelectRange.LatRange;
  72. }
  73. }
  74. private void Editor_MapItemEditing(object sender, MapItemEditingEventArgs e)
  75. {
  76. }
  77. private void Editor_MapItemEdited(object sender, MapItemEditedEventArgs e)
  78. {
  79. if (e.Action == MapEditorAction.Remove)
  80. {
  81. rectItem = null;
  82. SelectRange = null;
  83. centerPoint.Visible = false;
  84. }
  85. else
  86. {
  87. var bound = rectItem.GetBounds();
  88. var lonRange = bound.Right - bound.Left;
  89. var latRange = bound.Top - bound.Bottom;
  90. var lon = bound.Left + lonRange / 2;
  91. var lat = bound.Bottom + latRange / 2;
  92. txtLon.EditValue = lon.ToString("F3");
  93. txtLat.EditValue = lat.ToString("F3");
  94. txtLonRange.EditValue = lonRange.ToString("F1");
  95. txtLatRange.EditValue = latRange.ToString("F1");
  96. }
  97. }
  98. private void Editor_MapItemCreating(object sender, MapItemCreatingEventArgs e)
  99. {
  100. if (rectItem != null)
  101. {
  102. Editor.RemoveItems(new MapItem[] { rectItem });
  103. }
  104. rectItem = e.Item as MapRectangle;
  105. SetItemStyle(e.Item);
  106. centerPoint.Visible = true;
  107. }
  108. private void SetItemStyle(MapItem item)
  109. {
  110. item.Fill = Color.FromArgb(50, Color.Green);
  111. item.Stroke = Color.White;
  112. }
  113. private void btnOk_Click(object sender, EventArgs e)
  114. {
  115. var lonRange = txtLonRange.Text.IfNullOrWhitespace("360").To(0d);
  116. var latRange = txtLatRange.Text.IfNullOrWhitespace("180").To(0d);
  117. var lon = txtLon.Text.To(0d);
  118. var lat = txtLat.Text.To(0d);
  119. var alt = txtAlt.Text.To(0d);
  120. SelectRange = new GeoRange(lon, lat, alt, lonRange, latRange);
  121. this.DialogResult = DialogResult.OK;
  122. Close();
  123. }
  124. private void mapControl_DrawMapItem(object sender, DrawMapItemEventArgs e)
  125. {
  126. if (e.Item == rectItem && rectItem != null)
  127. {
  128. centerPoint.Location = rectItem.GetCenter();
  129. }
  130. }
  131. }
  132. }