public Layer CreateLayer(LayerMakerDialogData data) { float colormin = 255 * 255 * 255; float colormax = 0; int[] tilelatlon = TileCoordinate.ConvertWorldToTile( double.Parse(data.Lat, CultureInfo.InvariantCulture), double.Parse(data.Lon, CultureInfo.InvariantCulture), 18 ); //высчитываем минимальную и максимальную границу цвета для данного слоя Color pix; string colorhex; foreach (Bitmap item in data.Tiles.Values) { for (int i = 0; i < item.Width; i++) { for (int j = 0; j < item.Height; j++) { pix = item.GetPixel(i, j); colorhex = string.Format("0x{0:X2}{1:X2}{2:X2}", pix.R, pix.G, pix.B); float pixpower = Convert.ToInt32(colorhex, 16); if (pix.A > 0) { if (pixpower > colormax) { colormax = pixpower; } else if (pixpower < colormin) { colormin = pixpower; } } } } } Layer layer = new Layer() { TileX = tilelatlon[0], TileY = tilelatlon[1], Min = float.Parse(data.Min), Max = float.Parse(data.Max), ColorMin = colormin, ColorMax = colormax, Name = Path.GetFileNameWithoutExtension(data.FilePath), ValueType = data.ValueType }; return(Loader.CreateLayer(data.Tiles, layer, data.FilePath)); }
private void OnLayerCreate_Click(object sender, EventArgs e) { Status.Text = "Создание нового слоя"; try { LayerMakerDialogData data = ShowLayerMakerDialog(); decisionSupport.OnLayerCreate(data); } catch (Exception exc) { ShowBouble(exc.Message); } Status.Text = "Ok"; }
public LayerMakerDialogData ShowLayerMakerDialog() { LayerMakerDialog layerMaker = new LayerMakerDialog(); LayerMakerDialogData data = new LayerMakerDialogData() { Tiles = null, Lat = null, Lon = null, Min = null, Max = null, FilePath = null }; if (layerMaker.ShowDialog() == DialogResult.OK) { if (layerMaker.LatInput.TextLength > 0 && layerMaker.LonInput.TextLength > 0 && layerMaker.NameInput.TextLength > 0) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.InitialDirectory = Environment.SpecialFolder.Desktop.ToString(); sfd.Filter = "Crop Pod Layer (*.cplay)|*.cplay"; sfd.FilterIndex = 2; sfd.FileName = layerMaker.NameInput.Text; sfd.RestoreDirectory = false; if (sfd.ShowDialog() == DialogResult.OK) { data.Tiles = layerMaker.tiles; data.Lat = layerMaker.LatInput.Text; data.Lon = layerMaker.LonInput.Text; data.Min = layerMaker.MinInput.Text; data.Max = layerMaker.MaxInput.Text; data.ValueType = layerMaker.ValueTypeInput.Text; data.FilePath = sfd.FileName; } } } } else { throw new Exception("Layer not created"); } layerMaker.Dispose(); return(data); }
public Layer OnLayerCreate(LayerMakerDialogData data) { return(LayerHandler.CreateLayer(data)); }