using DevExpress.CodeParser; using DevExpress.XtraEditors; using DevExpress.XtraEditors.Controls; using DevExpress.XtraMap; using Ips.Library.Basic; using Ips.Library.DxpLib; using Ips.Library.Entity; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Ips.Sps.Maps { public partial class MapRangeSelectForm : DevExpress.XtraEditors.XtraForm { public MapRangeSelectForm() { InitializeComponent(); InitMap(); } public MapRangeSelectForm(GeoRange geoRange) : this() { SelectRange = geoRange; } MapEditor Editor { get { return mapControl.MapEditor; } } MapRectangle rectItem; MapDot centerPoint; public GeoRange SelectRange { get; set; } void InitMap() { mapControl.InitIpsOptions(new IpsMapOption() { ZoomLevel = 4d, CircularScrollingMode = CircularScrollingMode.None }); centerPoint = new MapDot() { Fill = Color.Red, Size = 8, Visible = false }; rectItemStorage.Items.Add(centerPoint); } private void MapRangeSelectForm_Load(object sender, EventArgs e) { Editor.ActiveLayer = rectItemsLayer; Editor.MapItemCreating += Editor_MapItemCreating; Editor.MapItemEditing += Editor_MapItemEditing; Editor.MapItemEdited += Editor_MapItemEdited; centerPoint.Visible = SelectRange != null; if (SelectRange != null) { var startPoint = new GeoPoint(SelectRange.LatMax, SelectRange.LonMin); var endPoint = new GeoPoint(SelectRange.LatMin, SelectRange.LonMax); rectItem = MapRectangle.FromLeftTopRightBottom(mapControl.CoordinateSystem, startPoint, endPoint); rectItemStorage.Items.Clear(); SetItemStyle(rectItem); rectItemStorage.Items.Add(rectItem); rectItemStorage.Items.Add(centerPoint); centerPoint.Location = new GeoPoint(SelectRange.Lat, SelectRange.Lon); txtLon.EditValue = SelectRange.Lon; txtLat.EditValue = SelectRange.Lat; txtAlt.EditValue = SelectRange.Alt; txtLonRange.EditValue = SelectRange.LonRange; txtLatRange.EditValue = SelectRange.LatRange; } } private void Editor_MapItemEditing(object sender, MapItemEditingEventArgs e) { } private void Editor_MapItemEdited(object sender, MapItemEditedEventArgs e) { if (e.Action == MapEditorAction.Remove) { rectItem = null; SelectRange = null; centerPoint.Visible = false; } else { var bound = rectItem.GetBounds(); var lonRange = bound.Right - bound.Left; var latRange = bound.Top - bound.Bottom; var lon = bound.Left + lonRange / 2; var lat = bound.Bottom + latRange / 2; txtLon.EditValue = lon.ToString("F3"); txtLat.EditValue = lat.ToString("F3"); txtLonRange.EditValue = lonRange.ToString("F1"); txtLatRange.EditValue = latRange.ToString("F1"); } } private void Editor_MapItemCreating(object sender, MapItemCreatingEventArgs e) { if (rectItem != null) { Editor.RemoveItems(new MapItem[] { rectItem }); } rectItem = e.Item as MapRectangle; SetItemStyle(e.Item); centerPoint.Visible = true; } private void SetItemStyle(MapItem item) { item.Fill = Color.FromArgb(50, Color.Green); item.Stroke = Color.White; } private void btnOk_Click(object sender, EventArgs e) { var lonRange = txtLonRange.Text.IfNullOrWhitespace("360").To(0d); var latRange = txtLatRange.Text.IfNullOrWhitespace("180").To(0d); var lon = txtLon.Text.To(0d); var lat = txtLat.Text.To(0d); var alt = txtAlt.Text.To(0d); SelectRange = new GeoRange(lon, lat, alt, lonRange, latRange); this.DialogResult = DialogResult.OK; Close(); } private void mapControl_DrawMapItem(object sender, DrawMapItemEventArgs e) { if (e.Item == rectItem && rectItem != null) { centerPoint.Location = rectItem.GetCenter(); } } } }