diff --git a/ExtLibs/GMap.NET.Core/GMap.NET/PureProjection.cs b/ExtLibs/GMap.NET.Core/GMap.NET/PureProjection.cs index a8ba664517..30d313bdf4 100644 --- a/ExtLibs/GMap.NET.Core/GMap.NET/PureProjection.cs +++ b/ExtLibs/GMap.NET.Core/GMap.NET/PureProjection.cs @@ -232,6 +232,16 @@ public List GetAreaTileList(RectLatLng rect, int zoom, int padding) return ret; } + /// + /// get number of tiles in rect at specific zoom + /// + public long GetAreaTileNumber(RectLatLng rect, int zoom, int padding) + { + GPoint topLeft = FromPixelToTileXY(FromLatLngToPixel(rect.LocationTopLeft, zoom)); + GPoint rightBottom = FromPixelToTileXY(FromLatLngToPixel(rect.LocationRightBottom, zoom)); + return (rightBottom.X - topLeft.X + 1) * (rightBottom.Y - topLeft.Y + 1); + } + /// /// The ground resolution indicates the distance (in meters) on the ground that’s represented by a single pixel in the map. /// For example, at a ground resolution of 10 meters/pixel, each pixel represents a ground distance of 10 meters. diff --git a/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcher.cs b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcher.cs index e301fb551a..4dfad77f0a 100644 --- a/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcher.cs +++ b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcher.cs @@ -228,6 +228,7 @@ void worker_DoWork(object sender, DoWorkEventArgs e) list.Clear(); list = null; } + worker.ReportProgress(0, 0); list = provider.Projection.GetAreaTileList(area, zoom, 0); maxOfTiles = provider.Projection.GetTileMatrixMaxXY(zoom); all = list.Count; diff --git a/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.Designer.cs b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.Designer.cs new file mode 100644 index 0000000000..c67445f195 --- /dev/null +++ b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.Designer.cs @@ -0,0 +1,220 @@ +namespace GMap.NET +{ + partial class TilePrefetcherMenu + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.trackBarMaxZoom = new System.Windows.Forms.TrackBar(); + this.trackBarMinZoom = new System.Windows.Forms.TrackBar(); + this.labelMaxZoom = new System.Windows.Forms.Label(); + this.labelMinZoom = new System.Windows.Forms.Label(); + this.buttonOK = new System.Windows.Forms.Button(); + this.textBoxTile = new System.Windows.Forms.TextBox(); + this.labelTotal = new System.Windows.Forms.Label(); + this.numericUpDownMinZoom = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownMaxZoom = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.trackBarMaxZoom)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.trackBarMinZoom)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMinZoom)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxZoom)).BeginInit(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Location = new System.Drawing.Point(174, 360); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 0; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + // + // trackBarMaxZoom + // + this.trackBarMaxZoom.Location = new System.Drawing.Point(74, 46); + this.trackBarMaxZoom.Maximum = 20; + this.trackBarMaxZoom.Minimum = 1; + this.trackBarMaxZoom.Name = "trackBarMaxZoom"; + this.trackBarMaxZoom.Orientation = System.Windows.Forms.Orientation.Vertical; + this.trackBarMaxZoom.Size = new System.Drawing.Size(45, 295); + this.trackBarMaxZoom.TabIndex = 1; + this.trackBarMaxZoom.TickStyle = System.Windows.Forms.TickStyle.TopLeft; + this.trackBarMaxZoom.Value = 20; + this.trackBarMaxZoom.ValueChanged += new System.EventHandler(this.trackBarMaxZoom_ValueChanged); + // + // trackBarMinZoom + // + this.trackBarMinZoom.Location = new System.Drawing.Point(7, 46); + this.trackBarMinZoom.Maximum = 20; + this.trackBarMinZoom.Minimum = 1; + this.trackBarMinZoom.Name = "trackBarMinZoom"; + this.trackBarMinZoom.Orientation = System.Windows.Forms.Orientation.Vertical; + this.trackBarMinZoom.Size = new System.Drawing.Size(45, 295); + this.trackBarMinZoom.TabIndex = 1; + this.trackBarMinZoom.Value = 1; + this.trackBarMinZoom.ValueChanged += new System.EventHandler(this.trackBarMinZoom_ValueChanged); + // + // labelMaxZoom + // + this.labelMaxZoom.AutoSize = true; + this.labelMaxZoom.Location = new System.Drawing.Point(74, 4); + this.labelMaxZoom.Name = "labelMaxZoom"; + this.labelMaxZoom.Size = new System.Drawing.Size(64, 13); + this.labelMaxZoom.TabIndex = 2; + this.labelMaxZoom.Text = "Max zoom : "; + // + // labelMinZoom + // + this.labelMinZoom.AutoSize = true; + this.labelMinZoom.Location = new System.Drawing.Point(7, 4); + this.labelMinZoom.Name = "labelMinZoom"; + this.labelMinZoom.Size = new System.Drawing.Size(61, 13); + this.labelMinZoom.TabIndex = 2; + this.labelMinZoom.Text = "Min zoom : "; + // + // buttonOK + // + this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK; + this.buttonOK.Location = new System.Drawing.Point(7, 360); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 0; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + // + // textBoxTile + // + this.textBoxTile.Location = new System.Drawing.Point(144, 7); + this.textBoxTile.Multiline = true; + this.textBoxTile.Name = "textBoxTile"; + this.textBoxTile.ReadOnly = true; + this.textBoxTile.Size = new System.Drawing.Size(105, 334); + this.textBoxTile.TabIndex = 3; + // + // labelTotal + // + this.labelTotal.AutoSize = true; + this.labelTotal.Location = new System.Drawing.Point(7, 344); + this.labelTotal.Name = "labelTotal"; + this.labelTotal.Size = new System.Drawing.Size(132, 13); + this.labelTotal.TabIndex = 4; + this.labelTotal.Text = "Estimated : 0 tiles for 0 MB"; + // + // numericUpDownMinZoom + // + this.numericUpDownMinZoom.Location = new System.Drawing.Point(7, 20); + this.numericUpDownMinZoom.Maximum = new decimal(new int[] { + 20, + 0, + 0, + 0}); + this.numericUpDownMinZoom.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDownMinZoom.Name = "numericUpDownMinZoom"; + this.numericUpDownMinZoom.Size = new System.Drawing.Size(61, 20); + this.numericUpDownMinZoom.TabIndex = 6; + this.numericUpDownMinZoom.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.numericUpDownMinZoom.Value = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDownMinZoom.ValueChanged += new System.EventHandler(this.numericUpDownMinZoom_ValueChanged); + // + // numericUpDownMaxZoom + // + this.numericUpDownMaxZoom.Location = new System.Drawing.Point(74, 20); + this.numericUpDownMaxZoom.Maximum = new decimal(new int[] { + 20, + 0, + 0, + 0}); + this.numericUpDownMaxZoom.Minimum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDownMaxZoom.Name = "numericUpDownMaxZoom"; + this.numericUpDownMaxZoom.Size = new System.Drawing.Size(61, 20); + this.numericUpDownMaxZoom.TabIndex = 6; + this.numericUpDownMaxZoom.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.numericUpDownMaxZoom.Value = new decimal(new int[] { + 20, + 0, + 0, + 0}); + this.numericUpDownMaxZoom.ValueChanged += new System.EventHandler(this.numericUpDownMaxZoom_ValueChanged); + // + // TilePrefetcherMenu + // + this.AutoSize = true; + this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.CancelButton = this.buttonCancel; + this.ClientSize = new System.Drawing.Size(256, 388); + this.Controls.Add(this.numericUpDownMaxZoom); + this.Controls.Add(this.numericUpDownMinZoom); + this.Controls.Add(this.labelTotal); + this.Controls.Add(this.textBoxTile); + this.Controls.Add(this.labelMinZoom); + this.Controls.Add(this.labelMaxZoom); + this.Controls.Add(this.trackBarMinZoom); + this.Controls.Add(this.trackBarMaxZoom); + this.Controls.Add(this.buttonOK); + this.Controls.Add(this.buttonCancel); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.KeyPreview = true; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "TilePrefetcherMenu"; + this.Padding = new System.Windows.Forms.Padding(4); + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Tile Prefetcher Menu"; + ((System.ComponentModel.ISupportInitialize)(this.trackBarMaxZoom)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.trackBarMinZoom)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMinZoom)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMaxZoom)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } + + #endregion + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.TrackBar trackBarMaxZoom; + private System.Windows.Forms.TrackBar trackBarMinZoom; + private System.Windows.Forms.Label labelMaxZoom; + private System.Windows.Forms.Label labelMinZoom; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.TextBox textBoxTile; + private System.Windows.Forms.Label labelTotal; + private System.Windows.Forms.NumericUpDown numericUpDownMinZoom; + private System.Windows.Forms.NumericUpDown numericUpDownMaxZoom; + } +} \ No newline at end of file diff --git a/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.cs b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.cs new file mode 100644 index 0000000000..2dc9aec8c8 --- /dev/null +++ b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.cs @@ -0,0 +1,157 @@ +using GMap.NET.MapProviders; +using System; +using System.Globalization; +using System.Windows.Forms; + +namespace GMap.NET +{ + /// + /// form helping to prefetch tiles on local db + /// + public partial class TilePrefetcherMenu : Form + { + public int Minimum { get; set; } = 1; + public int Maximum { get; set; } = 20; + + private RectLatLng area; + private GMapProvider provider; + + public TilePrefetcherMenu(int min, int max, RectLatLng area, GMapProvider provider) + { + InitializeComponent(); + numericUpDownMinZoom.Minimum = numericUpDownMaxZoom.Minimum = trackBarMinZoom.Minimum = trackBarMaxZoom.Minimum = min; + numericUpDownMinZoom.Maximum = numericUpDownMaxZoom.Maximum = trackBarMinZoom.Maximum = trackBarMaxZoom.Maximum = max; + this.area = area; + this.provider = provider; + UpdateTilesCount(); + } + + private void UpdateTilesCount() + { + long count = 0; + string results = ""; + long total = 0; + var nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone(); + nfi.NumberGroupSeparator = " "; + for (int i = Minimum; i <= Maximum; i++) + { + count = provider.Projection.GetAreaTileNumber(area, i, 0); + + results += "Zoom " + i + " : " + count.ToString("#,0", nfi); + if (i < Maximum) + results += Environment.NewLine; + total += count; + } + textBoxTile.Text = results; + + long averageTileSize = 15000; // byte + labelTotal.Text = "Estimated: " + total.ToString("#,0", nfi) + " tile" + (total > 1 ? "s" : "") + " for " + sizeConverter(total * averageTileSize); + } + private string sizeConverter(float bytes) + { + try + { + float gb = 1024 * 1024 * 1024; + float mb = 1024 * 1024; + float kb = 1024; + float result = 0; + string ext = ""; + if (bytes >= gb) + { + result = bytes / gb; + ext = " GB "; + } + else if (bytes >= mb) + { + result = bytes / mb; + ext = " MB "; + } + else if (bytes >= kb) + { + result = bytes / kb; + ext = " KB "; + } + else + { + result = bytes; + ext = " B "; + } + string ret = (result).ToString("N2") + ext; + return ret; + } + catch + { + + } + return ""; + } + + private void numericUpDownMinZoom_ValueChanged(object sender, EventArgs e) + { + if (Minimum != (int)numericUpDownMinZoom.Value) + { + if ((int)numericUpDownMinZoom.Value <= (int)numericUpDownMaxZoom.Value) + { + Minimum = (int)numericUpDownMinZoom.Value; + trackBarMinZoom.Value = Minimum; + UpdateTilesCount(); + } + else + { + numericUpDownMinZoom.Value = Minimum; + } + } + } + + private void trackBarMinZoom_ValueChanged(object sender, EventArgs e) + { + if (Minimum != (int)trackBarMinZoom.Value) + { + if ((int)trackBarMinZoom.Value <= (int)trackBarMaxZoom.Value) + { + Minimum = (int)trackBarMinZoom.Value; + numericUpDownMinZoom.Value = Minimum; + UpdateTilesCount(); + } + else + { + trackBarMinZoom.Value = Minimum; + } + } + } + + private void numericUpDownMaxZoom_ValueChanged(object sender, EventArgs e) + { + if (Maximum != (int)numericUpDownMaxZoom.Value) + { + if ((int)numericUpDownMinZoom.Value <= (int)numericUpDownMaxZoom.Value) + { + Maximum = (int)numericUpDownMaxZoom.Value; + trackBarMaxZoom.Value = Maximum; + UpdateTilesCount(); + } + else + { + numericUpDownMaxZoom.Value = Maximum; + } + } + } + + private void trackBarMaxZoom_ValueChanged(object sender, EventArgs e) + { + if (Maximum != (int)trackBarMaxZoom.Value) + { + if ((int)trackBarMinZoom.Value <= (int)trackBarMaxZoom.Value) + { + Maximum = (int)trackBarMaxZoom.Value; + numericUpDownMaxZoom.Value = Maximum; + UpdateTilesCount(); + } + else + { + trackBarMaxZoom.Value = Maximum; + } + } + } + } +} diff --git a/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.resx b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.resx new file mode 100644 index 0000000000..d58980a38d --- /dev/null +++ b/ExtLibs/GMap.NET.WindowsForms/GMap.NET.WindowsForms/TilePrefetcherMenu.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GCSViews/FlightPlanner.cs b/GCSViews/FlightPlanner.cs index cb7e1945ed..f8210dbe11 100644 --- a/GCSViews/FlightPlanner.cs +++ b/GCSViews/FlightPlanner.cs @@ -1886,10 +1886,6 @@ public void BUT_loadwpfile_Click(object sender, EventArgs e) } } - private void BUT_Prefetch_Click(object sender, EventArgs e) - { - } - public void BUT_saveWPFile_Click(object sender, EventArgs e) { SaveFile_Click(null, null); @@ -5052,38 +5048,18 @@ public void prefetchToolStripMenuItem_Click(object sender, EventArgs e) if (!area.IsEmpty) { - string maxzoomstring = "20"; - if (InputBox.Show("max zoom", "Enter the max zoom to prefetch to.", ref maxzoomstring) != - DialogResult.OK) - return; - - int maxzoom = 20; - if (!int.TryParse(maxzoomstring, out maxzoom)) - { - CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR); - return; - } + int maxzoom = MainMap.MaxZoom; + int minzoom = MainMap.MinZoom; + TilePrefetcherMenu tilePrefetcherMenu = new TilePrefetcherMenu(MainMap.MinZoom, MainMap.MaxZoom, area, MainMap.MapProvider); - maxzoom = Math.Min(maxzoom, MainMap.MaxZoom); - - string minzoomstring = "1"; - if (InputBox.Show("min zoom", "Enter the min zoom to prefetch to.", ref minzoomstring) != - DialogResult.OK) - return; - - int minzoom = 20; - if (!int.TryParse(minzoomstring, out minzoom)) + if (tilePrefetcherMenu.ShowDialog(this) != DialogResult.OK) { - CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR); - return; - } - minzoom = Math.Max(minzoom, MainMap.MinZoom); - - if (minzoom > maxzoom) - { - CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR); + tilePrefetcherMenu.Dispose(); return; } + minzoom = tilePrefetcherMenu.Minimum; + maxzoom = tilePrefetcherMenu.Maximum; + tilePrefetcherMenu.Dispose(); for (int i = minzoom; i <= maxzoom; i++) {