From a8c7eac509aaf3fc97f8e86085892734b47a2962 Mon Sep 17 00:00:00 2001 From: dl2alf Date: Thu, 23 Dec 2021 16:18:53 +0100 Subject: [PATCH 1/4] V1.3.3.6 --- .../Properties/AssemblyInfo.cs | 4 +- AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs | 138 ++++++++++---- .../Properties/AssemblyInfo.cs | 4 +- .../TLS.cs | 138 ++++++++++---- .../VirtualRadarServer.cs | 4 +- AirScout/AirScout.csproj | 10 ++ AirScout/CrossingHistoryDlg.Designer.cs | 90 +++++----- AirScout/DeleteSingleStationDlg.Designer.cs | 140 +++++++++++++++ AirScout/DeleteSingleStationDlg.cs | 71 ++++++++ AirScout/DeleteSingleStationDlg.resx | 124 +++++++++++++ AirScout/MapStationDlg.Designer.cs | 99 ++++++++-- AirScout/MapStationDlg.cs | 170 +++++++++++++++++- AirScout/MapStationDlg.resx | 6 + AirScout/OptionsDlg.Designer.cs | 15 ++ AirScout/OptionsDlg.cs | 6 + AirScout/Properties/AssemblyInfo.cs | 4 +- AirScout/Properties/Settings.Designer.cs | 12 ++ AirScout/Properties/Settings.settings | 3 + AirScout/Requirements.txt | 12 ++ AirScout/VersionHistory.txt | 15 +- AirScout/app.config | 3 + .../GMap.NET.WindowsForms/GMapControl.cs | 37 ++-- SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs | 32 ++-- .../ScoutBase.Elevation/ElevationDatabase.cs | 14 +- .../ScoutBase.Elevation/ElevationTile.cs | 4 +- .../PropagationDatabase.cs | 16 +- .../ScoutBase.Stations/StationDatabase.cs | 28 ++- 27 files changed, 1011 insertions(+), 188 deletions(-) create mode 100644 AirScout/DeleteSingleStationDlg.Designer.cs create mode 100644 AirScout/DeleteSingleStationDlg.cs create mode 100644 AirScout/DeleteSingleStationDlg.resx create mode 100644 AirScout/Requirements.txt diff --git a/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs index b85de67..0b00288 100644 --- a/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.0")] -[assembly: AssemblyFileVersion("1.3.3.0")] +[assembly: AssemblyVersion("1.3.3.1")] +[assembly: AssemblyFileVersion("1.3.3.1")] diff --git a/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs b/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs index 240b510..71d6a93 100644 --- a/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs @@ -43,7 +43,98 @@ namespace System.Net return clientExtensions; } - public static string DownloadFile (string url, int timeout) + private static bool ReadContent(Stream stream, int contentlength, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + int count = 0; + // assign buffer + byte[] buff = new byte[1]; + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return true; + } + + private static bool ReadChunkedContent(Stream stream, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + byte[] buff = new byte[1]; + int count = 0; + string strcontentlength = ""; + int contentlength = 0; + // chunked transfer, first line should contain content length + // read stream bytewise until CRLF is detected + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return false; + } + + public static string DownloadFile(string url, int timeout) { string response = ""; Uri uri = null; @@ -76,13 +167,15 @@ namespace System.Net var dataToSend = Encoding.ASCII.GetBytes(hdr.ToString()); stream.Write(dataToSend, 0, dataToSend.Length); + + byte[] buff; // set stop watch as timout Stopwatch st = new Stopwatch(); st.Start(); //read header bytewise string header = ""; int totalRead = 0; - byte[] buff = new byte[1]; + buff = new byte[1]; do { totalRead = stream.Read(buff, 0, buff.Length); @@ -91,47 +184,20 @@ namespace System.Net throw new TimeoutException("Connection to " + url + " timed out."); } while (!header.Contains("\r\n\r\n")); + Console.Write(header); int contentlength = 0; if (header.Contains("Transfer-Encoding: chunked")) { - // chunked transfer, first line should contain content length - string strcontentlength = ""; - do - { - totalRead = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // chunked transfer, read all chunks until complete + while (!ReadChunkedContent(stream, timeout, ref response)) + { } } else { // get content length from header - Regex strcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); - contentlength = int.Parse(strcontentlength.Match(header).Value); - } - // re-assign buffer - // read response - buff = new byte[1000]; - totalRead = 0; - do - { - int bytesRead = stream.Read(buff, 0, buff.Length); - string part = Encoding.UTF8.GetString(buff, 0, bytesRead); - Console.WriteLine(part); - response += part; - totalRead += bytesRead; - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (totalRead < contentlength); - // cut response at the end - if (response.Contains("\r\n")) - { - response = response.Substring(0, response.IndexOf("\r\n")); + Regex rcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); + contentlength = int.Parse(rcontentlength.Match(header).Value); + ReadContent(stream, contentlength, timeout, ref response); } st.Stop(); } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs index 2166a63..75276f8 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.0")] -[assembly: AssemblyFileVersion("1.3.3.0")] +[assembly: AssemblyVersion("1.3.3.1")] +[assembly: AssemblyFileVersion("1.3.3.1")] diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs index 3881267..b3bf035 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs @@ -4,11 +4,13 @@ using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Sockets; using System.Text; using System.Text.RegularExpressions; +using System.Threading; namespace System.Net { @@ -41,6 +43,97 @@ namespace System.Net return clientExtensions; } + private static bool ReadContent(Stream stream, int contentlength, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + int count = 0; + // assign buffer + byte[] buff = new byte[1]; + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return true; + } + + private static bool ReadChunkedContent(Stream stream, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + byte[] buff = new byte[1]; + int count = 0; + string strcontentlength = ""; + int contentlength = 0; + // chunked transfer, first line should contain content length + // read stream bytewise until CRLF is detected + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return false; + } + public static string DownloadFile (string url, int timeout, string apikey) { string response = ""; @@ -75,13 +168,15 @@ namespace System.Net var dataToSend = Encoding.ASCII.GetBytes(hdr.ToString()); stream.Write(dataToSend, 0, dataToSend.Length); + + byte[] buff; // set stop watch as timout Stopwatch st = new Stopwatch(); st.Start(); //read header bytewise string header = ""; int totalRead = 0; - byte[] buff = new byte[1]; + buff = new byte[1]; do { totalRead = stream.Read(buff, 0, buff.Length); @@ -90,47 +185,20 @@ namespace System.Net throw new TimeoutException("Connection to " + url + " timed out."); } while (!header.Contains("\r\n\r\n")); + Console.Write(header); int contentlength = 0; if (header.Contains("Transfer-Encoding: chunked")) { - // chunked transfer, first line should contain content length - string strcontentlength = ""; - do - { - totalRead = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // chunked transfer, read all chunks until complete + while (!ReadChunkedContent(stream, timeout, ref response)) + { } } else { // get content length from header - Regex strcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); - contentlength = int.Parse(strcontentlength.Match(header).Value); - } - // re-assign buffer - // read response - buff = new byte[1000]; - totalRead = 0; - do - { - int bytesRead = stream.Read(buff, 0, buff.Length); - string part = Encoding.UTF8.GetString(buff, 0, bytesRead); - Console.WriteLine(part); - response += part; - totalRead += bytesRead; - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (totalRead < contentlength); - // cut response at the end - if (response.Contains("\r\n")) - { - response = response.Substring(0, response.IndexOf("\r\n")); + Regex rcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); + contentlength = int.Parse(rcontentlength.Match(header).Value); + ReadContent(stream, contentlength, timeout, ref response); } st.Stop(); } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs index e2916dd..afeaffc 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs @@ -368,7 +368,6 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); // JavaScriptSerializer js = new JavaScriptSerializer(); // dynamic root = js.Deserialize(json); - dynamic root = JsonConvert.DeserializeObject(json); // 2017-07-23: workaround for "jumping planes" due to incorrect time stamps // try to get the server time to adjust the time stamps in plane positions // --> compare server time with local time and calculate offset @@ -376,6 +375,9 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer long toffset = 0; try { + // deserialize JSON + dynamic root = JsonConvert.DeserializeObject(json); + // get local time of request in milliseconds DateTime lt = DateTime.UtcNow; long ltime = (long)(lt - new DateTime(1970, 1, 1)).TotalMilliseconds; diff --git a/AirScout/AirScout.csproj b/AirScout/AirScout.csproj index 931e65c..b2adca3 100644 --- a/AirScout/AirScout.csproj +++ b/AirScout/AirScout.csproj @@ -136,6 +136,12 @@ + + Form + + + DeleteSingleStationDlg.cs + Form @@ -314,6 +320,7 @@ + Always @@ -329,6 +336,9 @@ DatabaseMaintenanceDlg.cs + + DeleteSingleStationDlg.cs + ElevationCopyrightDlg.cs diff --git a/AirScout/CrossingHistoryDlg.Designer.cs b/AirScout/CrossingHistoryDlg.Designer.cs index e85bdd9..3e7bf84 100644 --- a/AirScout/CrossingHistoryDlg.Designer.cs +++ b/AirScout/CrossingHistoryDlg.Designer.cs @@ -36,19 +36,19 @@ this.ss_Main = new System.Windows.Forms.StatusStrip(); this.tsl_Main = new System.Windows.Forms.ToolStripStatusLabel(); this.panel1 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.ud_Analysis_AmbiguousGap = new System.Windows.Forms.NumericUpDown(); + this.cb_Analysis_CrossingHistory_WithSignlaLevel = new System.Windows.Forms.CheckBox(); this.btn_History_Export = new System.Windows.Forms.Button(); this.btn_History_Cancel = new System.Windows.Forms.Button(); this.btn_History_Calculate = new System.Windows.Forms.Button(); this.tt_Crossing_History = new System.Windows.Forms.ToolTip(this.components); this.ch_Crossing_History = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.cb_Analysis_CrossingHistory_WithSignlaLevel = new System.Windows.Forms.CheckBox(); - this.ud_Analysis_AmbiguousGap = new System.Windows.Forms.NumericUpDown(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); this.ss_Main.SuspendLayout(); this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ud_Analysis_AmbiguousGap)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).BeginInit(); this.SuspendLayout(); // // bw_History @@ -90,6 +90,45 @@ this.panel1.Size = new System.Drawing.Size(893, 100); this.panel1.TabIndex = 2; // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(393, 51); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(32, 13); + this.label2.TabIndex = 6; + this.label2.Text = "secs."; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(9, 51); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(276, 13); + this.label1.TabIndex = 5; + this.label1.Text = "Timespan within two crossings considered as ambiguous:"; + // + // ud_Analysis_AmbiguousGap + // + this.ud_Analysis_AmbiguousGap.DataBindings.Add(new System.Windows.Forms.Binding("Value", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_AmbigousGap", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.ud_Analysis_AmbiguousGap.Location = new System.Drawing.Point(318, 49); + this.ud_Analysis_AmbiguousGap.Name = "ud_Analysis_AmbiguousGap"; + this.ud_Analysis_AmbiguousGap.Size = new System.Drawing.Size(60, 20); + this.ud_Analysis_AmbiguousGap.TabIndex = 4; + this.ud_Analysis_AmbiguousGap.Value = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_AmbigousGap; + // + // cb_Analysis_CrossingHistory_WithSignlaLevel + // + this.cb_Analysis_CrossingHistory_WithSignlaLevel.AutoSize = true; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Checked = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_WithSignalLevel; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_WithSignalLevel", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Location = new System.Drawing.Point(12, 21); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Name = "cb_Analysis_CrossingHistory_WithSignlaLevel"; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Size = new System.Drawing.Size(258, 17); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.TabIndex = 3; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Text = "Consider crossings with recorded signal level only"; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.UseVisualStyleBackColor = true; + // // btn_History_Export // this.btn_History_Export.Location = new System.Drawing.Point(697, 41); @@ -151,45 +190,6 @@ this.ch_Crossing_History.TabIndex = 5; this.ch_Crossing_History.Text = "History"; // - // cb_Analysis_CrossingHistory_WithSignlaLevel - // - this.cb_Analysis_CrossingHistory_WithSignlaLevel.AutoSize = true; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Checked = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_WithSignalLevel; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_WithSignalLevel", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Location = new System.Drawing.Point(12, 21); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Name = "cb_Analysis_CrossingHistory_WithSignlaLevel"; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Size = new System.Drawing.Size(258, 17); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.TabIndex = 3; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Text = "Consider crossings with recorded signal level only"; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.UseVisualStyleBackColor = true; - // - // ud_Analysis_AmbiguousGap - // - this.ud_Analysis_AmbiguousGap.DataBindings.Add(new System.Windows.Forms.Binding("Value", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_AmbiguousGap", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.ud_Analysis_AmbiguousGap.Location = new System.Drawing.Point(318, 49); - this.ud_Analysis_AmbiguousGap.Name = "ud_Analysis_AmbiguousGap"; - this.ud_Analysis_AmbiguousGap.Size = new System.Drawing.Size(60, 20); - this.ud_Analysis_AmbiguousGap.TabIndex = 4; - this.ud_Analysis_AmbiguousGap.Value = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_AmbigousGap; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(9, 51); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(276, 13); - this.label1.TabIndex = 5; - this.label1.Text = "Timespan within two crossings considered as ambiguous:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(393, 51); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(32, 13); - this.label2.TabIndex = 6; - this.label2.Text = "secs."; - // // CrossingHistoryDlg // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -206,8 +206,8 @@ this.ss_Main.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ud_Analysis_AmbiguousGap)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/AirScout/DeleteSingleStationDlg.Designer.cs b/AirScout/DeleteSingleStationDlg.Designer.cs new file mode 100644 index 0000000..9f71800 --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.Designer.cs @@ -0,0 +1,140 @@ +namespace AirScout +{ + partial class DeleteSingleStationDlg + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DeleteSingleStationDlg)); + this.label1 = new System.Windows.Forms.Label(); + this.cb_Call = new System.Windows.Forms.ComboBox(); + this.cb_Locator = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.btn_Delete = new System.Windows.Forms.Button(); + this.btn_Cancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(464, 92); + this.label1.TabIndex = 0; + this.label1.Text = resources.GetString("label1.Text"); + // + // cb_Call + // + this.cb_Call.FormattingEnabled = true; + this.cb_Call.Location = new System.Drawing.Point(55, 132); + this.cb_Call.Name = "cb_Call"; + this.cb_Call.Size = new System.Drawing.Size(121, 21); + this.cb_Call.TabIndex = 1; + this.cb_Call.DropDown += new System.EventHandler(this.cb_Call_DropDown); + this.cb_Call.SelectedIndexChanged += new System.EventHandler(this.cb_Call_SelectedIndexChanged); + this.cb_Call.TextChanged += new System.EventHandler(this.cb_Call_TextChanged); + this.cb_Call.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cb_Call_KeyPress); + // + // cb_Locator + // + this.cb_Locator.FormattingEnabled = true; + this.cb_Locator.Location = new System.Drawing.Point(279, 132); + this.cb_Locator.Name = "cb_Locator"; + this.cb_Locator.Size = new System.Drawing.Size(121, 21); + this.cb_Locator.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 135); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(27, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Call:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(223, 135); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(46, 13); + this.label3.TabIndex = 4; + this.label3.Text = "Locator:"; + // + // btn_Delete + // + this.btn_Delete.BackColor = System.Drawing.Color.Tomato; + this.btn_Delete.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_Delete.ForeColor = System.Drawing.Color.White; + this.btn_Delete.Location = new System.Drawing.Point(55, 173); + this.btn_Delete.Name = "btn_Delete"; + this.btn_Delete.Size = new System.Drawing.Size(121, 35); + this.btn_Delete.TabIndex = 5; + this.btn_Delete.Text = "Delete"; + this.btn_Delete.UseVisualStyleBackColor = false; + // + // btn_Cancel + // + this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btn_Cancel.Location = new System.Drawing.Point(279, 173); + this.btn_Cancel.Name = "btn_Cancel"; + this.btn_Cancel.Size = new System.Drawing.Size(121, 35); + this.btn_Cancel.TabIndex = 6; + this.btn_Cancel.Text = "Cancel"; + this.btn_Cancel.UseVisualStyleBackColor = true; + // + // DeleteSingleStationDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btn_Cancel; + this.ClientSize = new System.Drawing.Size(485, 220); + this.Controls.Add(this.btn_Cancel); + this.Controls.Add(this.btn_Delete); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.cb_Locator); + this.Controls.Add(this.cb_Call); + this.Controls.Add(this.label1); + this.Name = "DeleteSingleStationDlg"; + this.Text = "Delete Single Station"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cb_Call; + private System.Windows.Forms.ComboBox cb_Locator; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button btn_Delete; + private System.Windows.Forms.Button btn_Cancel; + } +} \ No newline at end of file diff --git a/AirScout/DeleteSingleStationDlg.cs b/AirScout/DeleteSingleStationDlg.cs new file mode 100644 index 0000000..425f14e --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.cs @@ -0,0 +1,71 @@ +using ScoutBase.Stations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace AirScout +{ + public partial class DeleteSingleStationDlg : Form + { + bool SelectionChanged = false; + + public DeleteSingleStationDlg() + { + InitializeComponent(); + } + + private void cb_Call_TextChanged(object sender, EventArgs e) + { + if (!SelectionChanged) + { + int start = cb_Call.SelectionStart; + int len = cb_Call.SelectionLength; + string text = cb_Call.Text.ToUpper().Trim(); + if (cb_Call.Text != text) + cb_Call.Text = text; + cb_Call.SelectionStart = start; + cb_Call.SelectionLength = len; + } + SelectionChanged = false; + } + + private void cb_Call_SelectedIndexChanged(object sender, EventArgs e) + { + // suppress handling on text input + if (!cb_Call.DroppedDown) + return; + if (cb_Call.SelectedItem != null) + { + SelectionChanged = true; + cb_Call.Text = (string)cb_Call.SelectedItem; + } + } + + private void cb_Call_KeyPress(object sender, KeyPressEventArgs e) + { + } + + private void cb_Call_DropDown(object sender, EventArgs e) + { + if (!cb_Call.DroppedDown && (cb_Call.Text.Length >= 2)) + { + List l = StationData.Database.LocationGetAll("%" + cb_Call.Text + "%"); + if (l != null) + { + cb_Call.Items.Clear(); + cb_Locator.Items.Clear(); + foreach (LocationDesignator ld in l) + { + cb_Call.Items.Add(ld.Call); + cb_Locator.Items.Add(ld.Loc); + } + } + } + } + } +} diff --git a/AirScout/DeleteSingleStationDlg.resx b/AirScout/DeleteSingleStationDlg.resx new file mode 100644 index 0000000..3b49f55 --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Use this dialog to find and remove a single station/locator combination from the local station database. +CAUTION: You can only remove own entries permanently. If a station/locator combination is part of the global database it would be re-inserted on next update. + + \ No newline at end of file diff --git a/AirScout/MapStationDlg.Designer.cs b/AirScout/MapStationDlg.Designer.cs index be4241c..1b9c7b1 100644 --- a/AirScout/MapStationDlg.Designer.cs +++ b/AirScout/MapStationDlg.Designer.cs @@ -40,7 +40,6 @@ this.label8 = new System.Windows.Forms.Label(); this.gm_Callsign = new GMap.NET.WindowsForms.GMapControl(); this.tb_Callsign = new ScoutBase.Core.CallsignTextBox(); - this.tb_Locator = new ScoutBase.Core.LocatorTextBox(); this.tb_Longitude = new ScoutBase.Core.DoubleTextBox(); this.tb_Latitude = new ScoutBase.Core.DoubleTextBox(); this.btn_Cancel = new System.Windows.Forms.Button(); @@ -48,6 +47,13 @@ this.label1 = new System.Windows.Forms.Label(); this.tb_Elevation = new ScoutBase.Core.DoubleTextBox(); this.label2 = new System.Windows.Forms.Label(); + this.ss_Main = new System.Windows.Forms.StatusStrip(); + this.tsl_Status = new System.Windows.Forms.ToolStripStatusLabel(); + this.bw_Elevationgrid = new System.ComponentModel.BackgroundWorker(); + this.tb_Locator = new ScoutBase.Core.LocatorTextBox(); + this.cb_Options_StationsMap_OverlayElevation = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); + this.ss_Main.SuspendLayout(); this.SuspendLayout(); // // label19 @@ -153,7 +159,7 @@ this.gm_Callsign.RoutesEnabled = true; this.gm_Callsign.SelectedAreaFillColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(65)))), ((int)(((byte)(105)))), ((int)(((byte)(225))))); this.gm_Callsign.ShowTileGridLines = false; - this.gm_Callsign.Size = new System.Drawing.Size(760, 621); + this.gm_Callsign.Size = new System.Drawing.Size(760, 617); this.gm_Callsign.TabIndex = 29; this.gm_Callsign.Zoom = 0D; this.gm_Callsign.OnMarkerEnter += new GMap.NET.WindowsForms.MarkerEnter(this.gm_Callsign_OnMarkerEnter); @@ -176,19 +182,6 @@ this.tb_Callsign.Size = new System.Drawing.Size(107, 21); this.tb_Callsign.TabIndex = 30; // - // tb_Locator - // - this.tb_Locator.DataBindings.Add(new System.Windows.Forms.Binding("SmallLettersForSubsquares", global::AirScout.Properties.Settings.Default, "Locator_SmallLettersForSubsquares", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.tb_Locator.ErrorBackColor = System.Drawing.Color.Red; - this.tb_Locator.ErrorForeColor = System.Drawing.Color.White; - this.tb_Locator.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tb_Locator.Location = new System.Drawing.Point(875, 140); - this.tb_Locator.Name = "tb_Locator"; - this.tb_Locator.Size = new System.Drawing.Size(107, 21); - this.tb_Locator.SmallLettersForSubsquares = global::AirScout.Properties.Settings.Default.Locator_SmallLettersForSubsquares; - this.tb_Locator.TabIndex = 35; - this.tb_Locator.TextChanged += new System.EventHandler(this.tb_Locator_TextChanged); - // // tb_Longitude // this.tb_Longitude.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -199,7 +192,7 @@ this.tb_Longitude.Name = "tb_Longitude"; this.tb_Longitude.Size = new System.Drawing.Size(107, 21); this.tb_Longitude.TabIndex = 33; - this.tb_Longitude.Text = "10.68327000"; + this.tb_Longitude.Text = "10.68327"; this.tb_Longitude.Value = 10.68327D; this.tb_Longitude.TextChanged += new System.EventHandler(this.tb_Longitude_TextChanged); // @@ -213,14 +206,14 @@ this.tb_Latitude.Name = "tb_Latitude"; this.tb_Latitude.Size = new System.Drawing.Size(107, 21); this.tb_Latitude.TabIndex = 32; - this.tb_Latitude.Text = "50.93706700"; + this.tb_Latitude.Text = "50.937067"; this.tb_Latitude.Value = 50.937067D; this.tb_Latitude.TextChanged += new System.EventHandler(this.tb_Latitude_TextChanged); // // btn_Cancel // this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btn_Cancel.Location = new System.Drawing.Point(806, 685); + this.btn_Cancel.Location = new System.Drawing.Point(804, 665); this.btn_Cancel.Name = "btn_Cancel"; this.btn_Cancel.Size = new System.Drawing.Size(75, 23); this.btn_Cancel.TabIndex = 44; @@ -231,7 +224,7 @@ // btn_OK // this.btn_OK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.btn_OK.Location = new System.Drawing.Point(907, 685); + this.btn_OK.Location = new System.Drawing.Point(907, 665); this.btn_OK.Name = "btn_OK"; this.btn_OK.Size = new System.Drawing.Size(75, 23); this.btn_OK.TabIndex = 45; @@ -271,6 +264,63 @@ this.label2.TabIndex = 49; this.label2.Text = "m asl"; // + // ss_Main + // + this.ss_Main.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tsl_Status}); + this.ss_Main.Location = new System.Drawing.Point(0, 707); + this.ss_Main.Name = "ss_Main"; + this.ss_Main.Size = new System.Drawing.Size(1008, 22); + this.ss_Main.TabIndex = 50; + this.ss_Main.Text = "statusStrip1"; + // + // tsl_Status + // + this.tsl_Status.Name = "tsl_Status"; + this.tsl_Status.Size = new System.Drawing.Size(39, 17); + this.tsl_Status.Text = "Status"; + // + // bw_Elevationgrid + // + this.bw_Elevationgrid.WorkerReportsProgress = true; + this.bw_Elevationgrid.WorkerSupportsCancellation = true; + this.bw_Elevationgrid.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_Elevationgrid_DoWork); + this.bw_Elevationgrid.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_Elevationgrid_ProgressChanged); + this.bw_Elevationgrid.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_Elevationgrid_RunWorkerCompleted); + // + // tb_Locator + // + this.tb_Locator.DataBindings.Add(new System.Windows.Forms.Binding("SmallLettersForSubsquares", global::AirScout.Properties.Settings.Default, "Locator_SmallLettersForSubsquares", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.tb_Locator.ErrorBackColor = System.Drawing.Color.Red; + this.tb_Locator.ErrorForeColor = System.Drawing.Color.White; + this.tb_Locator.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tb_Locator.Location = new System.Drawing.Point(875, 140); + this.tb_Locator.Name = "tb_Locator"; + this.tb_Locator.Size = new System.Drawing.Size(107, 21); + this.tb_Locator.SmallLettersForSubsquares = global::AirScout.Properties.Settings.Default.Locator_SmallLettersForSubsquares; + this.tb_Locator.TabIndex = 35; + this.tb_Locator.TextChanged += new System.EventHandler(this.tb_Locator_TextChanged); + // + // cb_Options_StationsMap_OverlayElevation + // + this.cb_Options_StationsMap_OverlayElevation.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; + this.cb_Options_StationsMap_OverlayElevation.Checked = global::AirScout.Properties.Settings.Default.StationsMap_OverlayElevation; + this.cb_Options_StationsMap_OverlayElevation.Location = new System.Drawing.Point(804, 267); + this.cb_Options_StationsMap_OverlayElevation.Name = "cb_Options_StationsMap_OverlayElevation"; + this.cb_Options_StationsMap_OverlayElevation.Size = new System.Drawing.Size(178, 46); + this.cb_Options_StationsMap_OverlayElevation.TabIndex = 51; + this.cb_Options_StationsMap_OverlayElevation.Text = "Overlay Elevation Grid \r\n(on zom levels >= 17)"; + this.cb_Options_StationsMap_OverlayElevation.UseVisualStyleBackColor = true; + this.cb_Options_StationsMap_OverlayElevation.CheckedChanged += new System.EventHandler(this.cb_Options_StationsMap_OverlayElevation_CheckedChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(813, 434); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(0, 13); + this.label3.TabIndex = 52; + // // MapStationDlg // this.AcceptButton = this.btn_OK; @@ -278,6 +328,9 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btn_Cancel; this.ClientSize = new System.Drawing.Size(1008, 729); + this.Controls.Add(this.label3); + this.Controls.Add(this.cb_Options_StationsMap_OverlayElevation); + this.Controls.Add(this.ss_Main); this.Controls.Add(this.label2); this.Controls.Add(this.tb_Elevation); this.Controls.Add(this.label1); @@ -302,6 +355,9 @@ this.MinimizeBox = false; this.Name = "MapStationDlg"; this.Text = "MapStationDlg"; + this.Load += new System.EventHandler(this.MapStationDlg_Load); + this.ss_Main.ResumeLayout(false); + this.ss_Main.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -328,5 +384,10 @@ private System.Windows.Forms.Label label1; private ScoutBase.Core.DoubleTextBox tb_Elevation; private System.Windows.Forms.Label label2; + private System.Windows.Forms.StatusStrip ss_Main; + private System.Windows.Forms.ToolStripStatusLabel tsl_Status; + private System.ComponentModel.BackgroundWorker bw_Elevationgrid; + private System.Windows.Forms.CheckBox cb_Options_StationsMap_OverlayElevation; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/AirScout/MapStationDlg.cs b/AirScout/MapStationDlg.cs index 4d64b29..a5b837a 100644 --- a/AirScout/MapStationDlg.cs +++ b/AirScout/MapStationDlg.cs @@ -21,6 +21,7 @@ namespace AirScout GMapOverlay Callsignpolygons = new GMapOverlay("Callsignpolygons"); GMapOverlay Callsignspositions = new GMapOverlay("Callsignpositions"); + GMapOverlay Elevationgrid = new GMapOverlay("Elevationgrid"); GMarkerGoogle UserPos = new GMarkerGoogle(new PointLatLng(0.0, 0.0), GMarkerGoogleType.red_dot); @@ -48,6 +49,7 @@ namespace AirScout gm_Callsign.MapScaleInfoEnabled = true; gm_Callsign.Overlays.Add(Callsignpolygons); gm_Callsign.Overlays.Add(Callsignspositions); + gm_Callsign.Overlays.Add(Elevationgrid); Callsignspositions.Markers.Add(UserPos); // initially set textboxes tb_Callsign.SilentText = StationLocation.Call; @@ -56,11 +58,15 @@ namespace AirScout tb_Locator.SilentText = MaidenheadLocator.LocFromLatLon(StationLocation.Lat, StationLocation.Lon, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, Properties.Settings.Default.Locator_AutoLength); tb_Elevation.SilentValue = GetElevation(StationLocation.Lat, StationLocation.Lon); ValidateDetails(); - // show initial zoom level in text box - gm_Callsign_OnMapZoomChanged(); } + private void MapStationDlg_Load(object sender, EventArgs e) + { + // initialen Zoomlevel anzeigen + gm_Callsign_OnMapZoomChanged(); + } + private void btn_Cancel_Click(object sender, EventArgs e) { @@ -264,6 +270,166 @@ namespace AirScout { // maintain zoom level tb_Zoom.Text = gm_Callsign.Zoom.ToString(); + ShowElevationGrid(); + } + + private void ShowElevationGrid() + { + while (bw_Elevationgrid.IsBusy) + { + bw_Elevationgrid.CancelAsync(); + Application.DoEvents(); + } + Elevationgrid.Polygons.Clear(); + if (cb_Options_StationsMap_OverlayElevation.Checked && (gm_Callsign.Zoom >= 17)) + { + bw_Elevationgrid.RunWorkerAsync(); + } + } + + private void bw_Elevationgrid_DoWork(object sender, DoWorkEventArgs e) + { + // fill elevation grid + bw_Elevationgrid.ReportProgress(0, "Calculating elevation grid..."); + Elevationgrid.Polygons.Clear(); + // convert view bounds to the beginning/end of Maidenhead locators + string loc = MaidenheadLocator.LocFromLatLon(gm_Callsign.ViewArea.Lat - gm_Callsign.ViewArea.HeightLat, gm_Callsign.ViewArea.Lng,false,3); + double minlat = MaidenheadLocator.LatFromLoc(loc, PositionInRectangle.BottomLeft); + double minlon = MaidenheadLocator.LonFromLoc(loc, PositionInRectangle.BottomLeft); + loc = MaidenheadLocator.LocFromLatLon(gm_Callsign.ViewArea.Lat, gm_Callsign.ViewArea.Lng + gm_Callsign.ViewArea.WidthLng, false, 3); + double maxlat = MaidenheadLocator.LatFromLoc(loc, PositionInRectangle.TopRight); + double maxlon = MaidenheadLocator.LonFromLoc(loc, PositionInRectangle.TopRight); + double lat = minlat; + double lon = minlon; + double stepwidthlat = 5.5555555555555555555555555555556e-4 / 2; + double stepwidthlon = 5.5555555555555555555555555555556e-4; + List elvs = new List(); + double elvmin = short.MaxValue; + double elvmax = short.MinValue; + while (!bw_Elevationgrid.CancellationPending && (lat < maxlat)) + { + lon = minlon; + while (!bw_Elevationgrid.CancellationPending && (lon < maxlon)) + { + double elv = 0; + if ((lat + stepwidthlat >= gm_Callsign.ViewArea.Lat - gm_Callsign.ViewArea.HeightLat) && + (lat <= gm_Callsign.ViewArea.Lat) && + (lon + stepwidthlon >= gm_Callsign.ViewArea.Lng) && + (lon <= gm_Callsign.ViewArea.Lng + gm_Callsign.ViewArea.WidthLng)) + { + elv = ElevationData.Database[lat, lon, Properties.Settings.Default.ElevationModel]; + ElevationTile t = new ElevationTile(); + t.Lat = lat; + t.Lon = lon; + t.Elv = elv; + elvs.Add(t); + if (elv < elvmin) + elvmin = elv; + if (elv > elvmax) + elvmax = elv; + } + else + { + } + lon += stepwidthlon; + } + lat += stepwidthlat; + } + foreach (ElevationTile t in elvs) + { + List l = new List(); + l.Add(new PointLatLng((decimal)t.Lat, (decimal)t.Lon)); + l.Add(new PointLatLng((decimal)(t.Lat + stepwidthlat), (decimal)t.Lon)); + l.Add(new PointLatLng((decimal)(t.Lat + stepwidthlat), (decimal)(t.Lon + stepwidthlon))); + l.Add(new PointLatLng((decimal)t.Lat, (decimal)(t.Lon + stepwidthlon))); + GMapTextPolygon p = new GMapTextPolygon(l, t.Elv + " m"); + Color c = Color.FromArgb(100, ElevationData.Database.GetElevationColor((t.Elv - elvmin) / (elvmax - elvmin) * 10000.0)); + p.Stroke = new Pen(c); + p.Fill = new SolidBrush(c); + Font f = new Font("Courier New", 8, GraphicsUnit.Pixel); + bw_Elevationgrid.ReportProgress(1, p); + if (bw_Elevationgrid.CancellationPending) + break; + } + bw_Elevationgrid.ReportProgress(100, "Calculating elevation grid finished."); + } + + private void bw_Elevationgrid_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + if (e.ProgressPercentage < 0) + { + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + if (e.ProgressPercentage == 0) + { + Elevationgrid.Polygons.Clear(); + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + else if (e.ProgressPercentage == 1) + { + GMapPolygon p = (GMapPolygon)e.UserState; + Elevationgrid.Polygons.Add(p); + tsl_Status.Text = "Adding elevation tile " + p.Name; + ss_Main.Refresh(); + } + else if (e.ProgressPercentage == 100) + { + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + } + + private void bw_Elevationgrid_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + + } + + private void cb_Options_StationsMap_OverlayElevation_CheckedChanged(object sender, EventArgs e) + { + ShowElevationGrid(); } } + + public class GMapTextPolygon : GMapPolygon + { + public GMapTextPolygon(List points, string name) : base(points, name) + { + } + + public override void OnRender(Graphics g) + { + base.OnRender(g); + StringFormat format = new StringFormat(); + format.LineAlignment = StringAlignment.Center; + format.Alignment = StringAlignment.Center; + long minx = long.MaxValue; + long maxx = long.MinValue; + long miny = long.MaxValue; + long maxy = long.MinValue; + for (int i = 0; i < this.LocalPoints.Count; i++) + { + if (this.LocalPoints[i].X < minx) + minx = this.LocalPoints[i].X; + if (this.LocalPoints[i].X > maxx) + maxx = this.LocalPoints[i].X; + if (this.LocalPoints[i].Y < miny) + miny = this.LocalPoints[i].Y; + if (this.LocalPoints[i].Y > maxy) + maxy = this.LocalPoints[i].Y; + } + RectangleF f = new RectangleF(minx, miny, maxx - minx, maxy - miny); + g.DrawString(this.Name, SystemFonts.DefaultFont, Brushes.Black, f, format); + } + } + + public class ElevationTile + { + public double Lat = 0; + public double Lon = 0; + public double Elv = 0; + } + + } diff --git a/AirScout/MapStationDlg.resx b/AirScout/MapStationDlg.resx index 55bd07d..6dc16e2 100644 --- a/AirScout/MapStationDlg.resx +++ b/AirScout/MapStationDlg.resx @@ -122,4 +122,10 @@ Use the lat/lon textboxes for numeric input or enter a valid Maidenhead Locator. Drag the needle on the map for exact location. Use mouse wheel or +/- buttons to zoom in and out. + + 17, 17 + + + 111, 17 + \ No newline at end of file diff --git a/AirScout/OptionsDlg.Designer.cs b/AirScout/OptionsDlg.Designer.cs index 5c23f23..853bf2f 100644 --- a/AirScout/OptionsDlg.Designer.cs +++ b/AirScout/OptionsDlg.Designer.cs @@ -451,6 +451,7 @@ this.bw_SRTM1_MapUpdater = new System.ComponentModel.BackgroundWorker(); this.bw_GLOBE_MapUpdater = new System.ComponentModel.BackgroundWorker(); this.bw_StationDataUpdater = new System.ComponentModel.BackgroundWorker(); + this.btn_DeleteSingleStation = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pb_Donate)).BeginInit(); this.tab_Options_Planes.SuspendLayout(); this.groupBox48.SuspendLayout(); @@ -3644,6 +3645,7 @@ // // groupBox47 // + this.groupBox47.Controls.Add(this.btn_DeleteSingleStation); this.groupBox47.Controls.Add(this.btn_DeleteAllMapTiles); this.groupBox47.Controls.Add(this.btn_Options_DeleteAllPropagationPaths); this.groupBox47.Controls.Add(this.btn_Options_DeleteAllElevationPaths); @@ -5757,6 +5759,18 @@ this.bw_StationDataUpdater.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_StationDataUpdater_ProgressChanged); this.bw_StationDataUpdater.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_StationDataUpdater_RunWorkerCompleted); // + // btn_DeleteSingleStation + // + this.btn_DeleteSingleStation.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_DeleteSingleStation.Location = new System.Drawing.Point(165, 48); + this.btn_DeleteSingleStation.Name = "btn_DeleteSingleStation"; + this.btn_DeleteSingleStation.Size = new System.Drawing.Size(122, 23); + this.btn_DeleteSingleStation.TabIndex = 3; + this.btn_DeleteSingleStation.Text = "Delete Single Station"; + this.tt_Options.SetToolTip(this.btn_DeleteSingleStation, "Deletes all cached map tiles from database"); + this.btn_DeleteSingleStation.UseVisualStyleBackColor = true; + this.btn_DeleteSingleStation.Click += new System.EventHandler(this.btn_DeleteSingleStation_Click); + // // OptionsDlg // this.AcceptButton = this.btn_Options_OK; @@ -6329,5 +6343,6 @@ private System.Windows.Forms.Label label105; private System.Windows.Forms.Label label145; private System.Windows.Forms.Button btn_Options_Path_Export; + private System.Windows.Forms.Button btn_DeleteSingleStation; } } \ No newline at end of file diff --git a/AirScout/OptionsDlg.cs b/AirScout/OptionsDlg.cs index 2dbdafb..c4ff8bf 100644 --- a/AirScout/OptionsDlg.cs +++ b/AirScout/OptionsDlg.cs @@ -359,6 +359,12 @@ namespace AirScout MapData.Database.TileDeleteAll(); } + private void btn_DeleteSingleStation_Click(object sender, EventArgs e) + { + DeleteSingleStationDlg Dlg = new DeleteSingleStationDlg(); + Dlg.ShowDialog(); + } + private void btn_Options_ScoutBase_Database_Maintenance_Click(object sender, EventArgs e) { DatabaseMaintenanceDlg Dlg = new DatabaseMaintenanceDlg(StationData.Database); diff --git a/AirScout/Properties/AssemblyInfo.cs b/AirScout/Properties/AssemblyInfo.cs index 5913caf..5ca38fb 100644 --- a/AirScout/Properties/AssemblyInfo.cs +++ b/AirScout/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.4")] -[assembly: AssemblyFileVersion("1.3.3.4")] +[assembly: AssemblyVersion("1.3.3.6")] +[assembly: AssemblyFileVersion("1.3.3.6")] diff --git a/AirScout/Properties/Settings.Designer.cs b/AirScout/Properties/Settings.Designer.cs index 0215e6a..552b659 100644 --- a/AirScout/Properties/Settings.Designer.cs +++ b/AirScout/Properties/Settings.Designer.cs @@ -2304,5 +2304,17 @@ Digital data base on the World Wide Web (URL: http://www.ngdc.noaa.gov/mgg/topo/ this["Map_Preloader_MaxZoom"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool StationsMap_OverlayElevation { + get { + return ((bool)(this["StationsMap_OverlayElevation"])); + } + set { + this["StationsMap_OverlayElevation"] = value; + } + } } } diff --git a/AirScout/Properties/Settings.settings b/AirScout/Properties/Settings.settings index 6f73e24..39add42 100644 --- a/AirScout/Properties/Settings.settings +++ b/AirScout/Properties/Settings.settings @@ -604,5 +604,8 @@ MEaSUREs data and products are available at no charge from the LP DAAC.See https 11 + + False + \ No newline at end of file diff --git a/AirScout/Requirements.txt b/AirScout/Requirements.txt new file mode 100644 index 0000000..bfcac3b --- /dev/null +++ b/AirScout/Requirements.txt @@ -0,0 +1,12 @@ +***************** AirScout Requirements ************************** + +- GreatCircle, distance and locator layer on map (DJ5AR) +- Snooze button for alarm on main window, clickable in PLAY mode () +- Calculate Doppler + +* watch list +- Add/remove call sign from Multi View tab over UDP command +- add stations to watchlist based on DXCC, Loc, QTF range from QTF1 to QTF2 + + + diff --git a/AirScout/VersionHistory.txt b/AirScout/VersionHistory.txt index 3322cf8..90d6c33 100644 --- a/AirScout/VersionHistory.txt +++ b/AirScout/VersionHistory.txt @@ -1,4 +1,17 @@ -2020-04-25: V1.3.3.4 +2020-xx-xx: V1.3.3.6 +==================== + +- Feature: Elevation grid overlay on "Optionms/Stations/Map" to better understand elevation resolution issues and local situation (for zoom levels >= 17) +- Bugfix: AirScout crashes when opening Crossing History Dialog window --> fixed (tnx PU34HAG) +- Bugfix: No more planes visible (Exception messages shown in status bar and log file) with some language settings (at least Turkish) --> fixed (tnx TA2NC) + +2020-04-25: V1.3.3.5 +==================== + +- Bugfix: Chunked transport of web content failed while fetching plane feeds (OpenSky, Virtual Radar Server) --> fixed +- Bugfix: Drawing map throws an exception under some circumstances --> fixed, added some error handling (tnx SM7LCB) + +2020-04-25: V1.3.3.4 ==================== - Bugfix: AirScout always reverts to default call signs (DL2ALF <> GB3MHZ) when area of interest is set outside Europe --> fixed (tnx VK3VG) diff --git a/AirScout/app.config b/AirScout/app.config index 0cd43f1..e6d5b26 100644 --- a/AirScout/app.config +++ b/AirScout/app.config @@ -603,6 +603,9 @@ MEaSUREs data and products are available at no charge from the LP DAAC.See https 11 + + False + diff --git a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs index 2b3e71f..a862b73 100644 --- a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs +++ b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs @@ -657,29 +657,36 @@ namespace GMap.NET.WindowsForms { foreach(WindowsFormsImage img in t.Overlays) { - if(img != null && img.Img != null) + try { - if(!found) - found = true; + if (img != null && img.Img != null) + { + if (!found) + found = true; - if(!img.IsParent) - { + if (!img.IsParent) + { #if !PocketPC - g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); #else - g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); + g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); #endif - } + } #if !PocketPC - else - { - // TODO: move calculations to loader thread - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + else + { + // TODO: move calculations to loader thread + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - } + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } #endif + } + } + catch (Exception ex) + { + Console.WriteLine("GMapControl: Error while drwing Image: " + ex.Message); } } } diff --git a/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs b/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs index 17d5975..cb4e42b 100644 --- a/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs +++ b/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs @@ -102,13 +102,13 @@ namespace System.Data.SQLite if (index < 0) index = i; // Console.WriteLine("[" + T.Name + ".FillFromRow] DataColumn not found: " + p.Name); - if (p.PropertyType.Name.ToUpper() == "STRING") - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if ((p.PropertyType.Name.ToUpper() == "FLOAT") || (p.PropertyType.Name.ToUpper() == "DOUBLE")) - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "INT32") - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "DATETIME") + if (p.PropertyType == typeof(string)) + p.SetValue(this, (row[index].GetType() != typeof(DBNull)) ? row[index] : null, null); + else if ((p.PropertyType == typeof(float)) || (p.PropertyType == typeof(double))) + p.SetValue(this, (row[index].GetType() !=typeof(DBNull)) ? row[index] : null, null); + else if (p.PropertyType == typeof(int)) + p.SetValue(this, (row[index].GetType() != typeof(DBNull)) ? row[index] : null, null); + else if (p.PropertyType == typeof(DateTime)) { if ((row[index].GetType() == typeof(int)) || (row[index].GetType() == typeof(long))) @@ -118,7 +118,7 @@ namespace System.Data.SQLite else p.SetValue(this, row[index], null); } - else if (p.PropertyType.BaseType.Name.ToUpper() == "ENUM") + else if (p.PropertyType.BaseType == typeof(Enum)) p.SetValue(this, System.Convert.ToInt32(row[index]), null); else p.SetValue(this, ByteArrayToObject((byte[])row[index]), null); @@ -154,13 +154,13 @@ namespace System.Data.SQLite if (index < 0) index = i; // Console.WriteLine("[" + T.Name + ".FillFromRow] DataColumn not found: " + p.Name); - if (p.PropertyType.Name.ToUpper() == "STRING") - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if ((p.PropertyType.Name.ToUpper() == "FLOAT") || (p.PropertyType.Name.ToUpper() == "DOUBLE")) - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "INT32") - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "DATETIME") + if (p.PropertyType == typeof(string)) + p.SetValue(this, (record[index].GetType() != typeof (DBNull)) ? record[index] : null, null); + else if ((p.PropertyType == typeof(float)) || (p.PropertyType == typeof(double))) + p.SetValue(this, (record[index].GetType() != typeof(DBNull)) ? record[index] : null, null); + else if (p.PropertyType == typeof(int)) + p.SetValue(this, (record[index].GetType() != typeof(DBNull)) ? record[index] : null, null); + else if (p.PropertyType == typeof(DateTime)) { if ((record[index].GetType() == typeof(int)) || (record[index].GetType() == typeof(long))) @@ -170,7 +170,7 @@ namespace System.Data.SQLite else p.SetValue(this, record[index], null); } - else if (p.PropertyType.BaseType.Name.ToUpper() == "ENUM") + else if (p.PropertyType.BaseType == typeof(Enum)) p.SetValue(this, System.Convert.ToInt32(record[index]), null); else p.SetValue(this, ByteArrayToObject((byte[])record[index]), null); diff --git a/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs b/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs index d7b7742..e376005 100644 --- a/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs +++ b/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs @@ -428,6 +428,18 @@ namespace ScoutBase.Elevation } return 0; } + + public Color GetElevationColor(double elv) + { + DEMColorPalette palette = new DEMColorPalette(); + double e = (double)(elv) / 100.0; + if (e < 0) + e = 0; + if (e > 100) + e = 100; + return palette.GetColor(e); + } + public Bitmap DrawElevationBitmap(double minlat, double minlon, double maxlat, double maxlon, int width, int height, ELEVATIONMODEL model) { int minelv = 0; @@ -1714,7 +1726,7 @@ namespace ScoutBase.Elevation for (int j = 0; j < bm.Height; j++) bm.SetPixel(i, j, c); } - bm.Save("DEMPalette.bmp"); + // bm.Save("DEMPalette.bmp"); } public Color GetColor(double percentage) diff --git a/ScoutBase/ScoutBase.Elevation/ElevationTile.cs b/ScoutBase/ScoutBase.Elevation/ElevationTile.cs index e647757..4376c05 100644 --- a/ScoutBase/ScoutBase.Elevation/ElevationTile.cs +++ b/ScoutBase/ScoutBase.Elevation/ElevationTile.cs @@ -162,8 +162,8 @@ namespace ScoutBase.Elevation /// The elevation. ElvMissingFlag if not found. public short GetElevation (double lat, double lon) { - int i = (int)((lat - BaseLat) / StepWidthLat); - int j = (int)((lon - BaseLon) / StepWidthLon); + int i = (int)(((lat - BaseLat) / StepWidthLat)); + int j = (int)(((lon - BaseLon) / StepWidthLon)); try { return Elv[j,i]; diff --git a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs index fe75075..305b3d2 100644 --- a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs +++ b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs @@ -470,17 +470,17 @@ namespace ScoutBase.Propagation double eps1; double eps2; if (dist1 > nf) + { eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); - else - eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, nf, ep.Path[i] + f1c1, radius); - if (eps1 > eps1_min) - eps1_min = eps1; + if (eps1 > eps1_min) + eps1_min = eps1; + } if (dist2 > nf) + { eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); - else - eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, nf, ep.Path[i] + f1c2, radius); - if (eps2 > eps2_min) - eps2_min = eps2; + if (eps2 > eps2_min) + eps2_min = eps2; + } if (caller != null) { // abort calculation if cancellation pending diff --git a/ScoutBase/ScoutBase.Stations/StationDatabase.cs b/ScoutBase/ScoutBase.Stations/StationDatabase.cs index 1850bfc..e6660d7 100644 --- a/ScoutBase/ScoutBase.Stations/StationDatabase.cs +++ b/ScoutBase/ScoutBase.Stations/StationDatabase.cs @@ -211,8 +211,10 @@ namespace ScoutBase.Stations public List LocationFindAll(string call) { - LocationDesignator ld = new LocationDesignator(call); List l = new List(); + if (String.IsNullOrEmpty(call)) + return l; + LocationDesignator ld = new LocationDesignator(call); lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -235,6 +237,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindLastRecent(string call) { LocationDesignator ld = new LocationDesignator(call); + if (String.IsNullOrEmpty(call)) + return null; lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -251,6 +255,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindMostHit(string call) { LocationDesignator ld = new LocationDesignator(call); + if (String.IsNullOrEmpty(call)) + return null; lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -266,11 +272,15 @@ namespace ScoutBase.Stations public LocationDesignator LocationFind(string call) { + if (String.IsNullOrEmpty(call)) + return null; return LocationFindLastRecent(call); } public LocationDesignator LocationFind(string call, string loc) { + if (String.IsNullOrEmpty(call) || String.IsNullOrEmpty(loc)) + return null; LocationDesignator ld = new LocationDesignator(call, loc); return LocationFind(ld); } @@ -300,6 +310,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindOrUpdateOrCreate(string call, double lat, double lon) { + if (String.IsNullOrEmpty(call)) + return null; LocationDesignator ld = new LocationDesignator(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3)); // try to find entry with call & loc matching ld = LocationFind(ld); @@ -326,6 +338,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindOrCreate(string call, string loc) { + if (String.IsNullOrEmpty(call) || String.IsNullOrEmpty(loc)) + return null; LocationDesignator ld = this.LocationFind(call, loc); if (ld == null) { @@ -539,6 +553,18 @@ namespace ScoutBase.Stations } + public List LocationGetAll(string call) + { + List l = new List(); + DataTable Result = db.Select("SELECT * FROM " + LocationDesignator.TableName + " WHERE CALL LIKE '" + call + "' ORDER BY Call ASC"); + if ((Result == null) || (Result.Rows.Count == 0)) + return l; + foreach (DataRow row in Result.Rows) + l.Add(new LocationDesignator(row)); + return l; + + } + public List LocationGetAll(BackgroundWorker caller) { // gets all locations from database From 6fa8277f347349622fbd3eb311e7da4ffda018b5 Mon Sep 17 00:00:00 2001 From: dl2alf Date: Thu, 23 Dec 2021 16:18:53 +0100 Subject: [PATCH 2/4] V1.3.3.6 --- .../Properties/AssemblyInfo.cs | 4 +- AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs | 138 ++++++++++---- .../Properties/AssemblyInfo.cs | 4 +- .../TLS.cs | 138 ++++++++++---- .../VirtualRadarServer.cs | 4 +- AirScout.sln | 4 +- AirScout/AirScout.csproj | 10 ++ AirScout/CrossingHistoryDlg.Designer.cs | 90 +++++----- AirScout/DeleteSingleStationDlg.Designer.cs | 140 +++++++++++++++ AirScout/DeleteSingleStationDlg.cs | 71 ++++++++ AirScout/DeleteSingleStationDlg.resx | 124 +++++++++++++ AirScout/MapStationDlg.Designer.cs | 99 ++++++++-- AirScout/MapStationDlg.cs | 170 +++++++++++++++++- AirScout/MapStationDlg.resx | 6 + AirScout/OptionsDlg.Designer.cs | 15 ++ AirScout/OptionsDlg.cs | 6 + AirScout/Properties/AssemblyInfo.cs | 4 +- AirScout/Properties/Settings.Designer.cs | 12 ++ AirScout/Properties/Settings.settings | 3 + AirScout/Requirements.txt | 12 ++ AirScout/VersionHistory.txt | 16 +- AirScout/app.config | 3 + .../GMap.NET.WindowsForms/GMapControl.cs | 37 ++-- SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs | 32 ++-- .../ScoutBase.Elevation/ElevationDatabase.cs | 14 +- .../ScoutBase.Elevation/ElevationTile.cs | 4 +- .../PropagationDatabase.cs | 16 +- .../ScoutBase.Stations/StationDatabase.cs | 28 ++- 28 files changed, 1014 insertions(+), 190 deletions(-) create mode 100644 AirScout/DeleteSingleStationDlg.Designer.cs create mode 100644 AirScout/DeleteSingleStationDlg.cs create mode 100644 AirScout/DeleteSingleStationDlg.resx create mode 100644 AirScout/Requirements.txt diff --git a/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs index b85de67..0b00288 100644 --- a/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.OpenSky/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.0")] -[assembly: AssemblyFileVersion("1.3.3.0")] +[assembly: AssemblyVersion("1.3.3.1")] +[assembly: AssemblyFileVersion("1.3.3.1")] diff --git a/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs b/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs index 240b510..71d6a93 100644 --- a/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.OpenSky/TLS.cs @@ -43,7 +43,98 @@ namespace System.Net return clientExtensions; } - public static string DownloadFile (string url, int timeout) + private static bool ReadContent(Stream stream, int contentlength, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + int count = 0; + // assign buffer + byte[] buff = new byte[1]; + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return true; + } + + private static bool ReadChunkedContent(Stream stream, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + byte[] buff = new byte[1]; + int count = 0; + string strcontentlength = ""; + int contentlength = 0; + // chunked transfer, first line should contain content length + // read stream bytewise until CRLF is detected + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return false; + } + + public static string DownloadFile(string url, int timeout) { string response = ""; Uri uri = null; @@ -76,13 +167,15 @@ namespace System.Net var dataToSend = Encoding.ASCII.GetBytes(hdr.ToString()); stream.Write(dataToSend, 0, dataToSend.Length); + + byte[] buff; // set stop watch as timout Stopwatch st = new Stopwatch(); st.Start(); //read header bytewise string header = ""; int totalRead = 0; - byte[] buff = new byte[1]; + buff = new byte[1]; do { totalRead = stream.Read(buff, 0, buff.Length); @@ -91,47 +184,20 @@ namespace System.Net throw new TimeoutException("Connection to " + url + " timed out."); } while (!header.Contains("\r\n\r\n")); + Console.Write(header); int contentlength = 0; if (header.Contains("Transfer-Encoding: chunked")) { - // chunked transfer, first line should contain content length - string strcontentlength = ""; - do - { - totalRead = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // chunked transfer, read all chunks until complete + while (!ReadChunkedContent(stream, timeout, ref response)) + { } } else { // get content length from header - Regex strcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); - contentlength = int.Parse(strcontentlength.Match(header).Value); - } - // re-assign buffer - // read response - buff = new byte[1000]; - totalRead = 0; - do - { - int bytesRead = stream.Read(buff, 0, buff.Length); - string part = Encoding.UTF8.GetString(buff, 0, bytesRead); - Console.WriteLine(part); - response += part; - totalRead += bytesRead; - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (totalRead < contentlength); - // cut response at the end - if (response.Contains("\r\n")) - { - response = response.Substring(0, response.IndexOf("\r\n")); + Regex rcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); + contentlength = int.Parse(rcontentlength.Match(header).Value); + ReadContent(stream, contentlength, timeout, ref response); } st.Stop(); } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs index 2166a63..75276f8 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.0")] -[assembly: AssemblyFileVersion("1.3.3.0")] +[assembly: AssemblyVersion("1.3.3.1")] +[assembly: AssemblyFileVersion("1.3.3.1")] diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs index 3881267..b3bf035 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs @@ -4,11 +4,13 @@ using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; +using System.Globalization; using System.IO; using System.Linq; using System.Net.Sockets; using System.Text; using System.Text.RegularExpressions; +using System.Threading; namespace System.Net { @@ -41,6 +43,97 @@ namespace System.Net return clientExtensions; } + private static bool ReadContent(Stream stream, int contentlength, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + int count = 0; + // assign buffer + byte[] buff = new byte[1]; + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return true; + } + + private static bool ReadChunkedContent(Stream stream, int timeout, ref string response) + { + // set stop watch as timout + Stopwatch st = new Stopwatch(); + st.Start(); + string resp = ""; + byte[] buff = new byte[1]; + int count = 0; + string strcontentlength = ""; + int contentlength = 0; + // chunked transfer, first line should contain content length + // read stream bytewise until CRLF is detected + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); + Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + response += resp; + return false; + } + public static string DownloadFile (string url, int timeout, string apikey) { string response = ""; @@ -75,13 +168,15 @@ namespace System.Net var dataToSend = Encoding.ASCII.GetBytes(hdr.ToString()); stream.Write(dataToSend, 0, dataToSend.Length); + + byte[] buff; // set stop watch as timout Stopwatch st = new Stopwatch(); st.Start(); //read header bytewise string header = ""; int totalRead = 0; - byte[] buff = new byte[1]; + buff = new byte[1]; do { totalRead = stream.Read(buff, 0, buff.Length); @@ -90,47 +185,20 @@ namespace System.Net throw new TimeoutException("Connection to " + url + " timed out."); } while (!header.Contains("\r\n\r\n")); + Console.Write(header); int contentlength = 0; if (header.Contains("Transfer-Encoding: chunked")) { - // chunked transfer, first line should contain content length - string strcontentlength = ""; - do - { - totalRead = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // chunked transfer, read all chunks until complete + while (!ReadChunkedContent(stream, timeout, ref response)) + { } } else { // get content length from header - Regex strcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); - contentlength = int.Parse(strcontentlength.Match(header).Value); - } - // re-assign buffer - // read response - buff = new byte[1000]; - totalRead = 0; - do - { - int bytesRead = stream.Read(buff, 0, buff.Length); - string part = Encoding.UTF8.GetString(buff, 0, bytesRead); - Console.WriteLine(part); - response += part; - totalRead += bytesRead; - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection to " + url + " timed out."); - } - while (totalRead < contentlength); - // cut response at the end - if (response.Contains("\r\n")) - { - response = response.Substring(0, response.IndexOf("\r\n")); + Regex rcontentlength = new Regex("(?<=Content-Length:\\s)\\d+", RegexOptions.IgnoreCase); + contentlength = int.Parse(rcontentlength.Match(header).Value); + ReadContent(stream, contentlength, timeout, ref response); } st.Stop(); } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs index e2916dd..afeaffc 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs @@ -368,7 +368,6 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer Console.WriteLine("[" + this.GetType().Name + "]: Analyzing data"); // JavaScriptSerializer js = new JavaScriptSerializer(); // dynamic root = js.Deserialize(json); - dynamic root = JsonConvert.DeserializeObject(json); // 2017-07-23: workaround for "jumping planes" due to incorrect time stamps // try to get the server time to adjust the time stamps in plane positions // --> compare server time with local time and calculate offset @@ -376,6 +375,9 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer long toffset = 0; try { + // deserialize JSON + dynamic root = JsonConvert.DeserializeObject(json); + // get local time of request in milliseconds DateTime lt = DateTime.UtcNow; long ltime = (long)(lt - new DateTime(1970, 1, 1)).TotalMilliseconds; diff --git a/AirScout.sln b/AirScout.sln index 984aec5..94678e8 100644 --- a/AirScout.sln +++ b/AirScout.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29609.76 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AirScout", "AirScout\AirScout.csproj", "{17498590-2CFF-4D24-BFB8-549D14BD2545}" EndProject diff --git a/AirScout/AirScout.csproj b/AirScout/AirScout.csproj index 931e65c..b2adca3 100644 --- a/AirScout/AirScout.csproj +++ b/AirScout/AirScout.csproj @@ -136,6 +136,12 @@ + + Form + + + DeleteSingleStationDlg.cs + Form @@ -314,6 +320,7 @@ + Always @@ -329,6 +336,9 @@ DatabaseMaintenanceDlg.cs + + DeleteSingleStationDlg.cs + ElevationCopyrightDlg.cs diff --git a/AirScout/CrossingHistoryDlg.Designer.cs b/AirScout/CrossingHistoryDlg.Designer.cs index e85bdd9..3e7bf84 100644 --- a/AirScout/CrossingHistoryDlg.Designer.cs +++ b/AirScout/CrossingHistoryDlg.Designer.cs @@ -36,19 +36,19 @@ this.ss_Main = new System.Windows.Forms.StatusStrip(); this.tsl_Main = new System.Windows.Forms.ToolStripStatusLabel(); this.panel1 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.label1 = new System.Windows.Forms.Label(); + this.ud_Analysis_AmbiguousGap = new System.Windows.Forms.NumericUpDown(); + this.cb_Analysis_CrossingHistory_WithSignlaLevel = new System.Windows.Forms.CheckBox(); this.btn_History_Export = new System.Windows.Forms.Button(); this.btn_History_Cancel = new System.Windows.Forms.Button(); this.btn_History_Calculate = new System.Windows.Forms.Button(); this.tt_Crossing_History = new System.Windows.Forms.ToolTip(this.components); this.ch_Crossing_History = new System.Windows.Forms.DataVisualization.Charting.Chart(); - this.cb_Analysis_CrossingHistory_WithSignlaLevel = new System.Windows.Forms.CheckBox(); - this.ud_Analysis_AmbiguousGap = new System.Windows.Forms.NumericUpDown(); - this.label1 = new System.Windows.Forms.Label(); - this.label2 = new System.Windows.Forms.Label(); this.ss_Main.SuspendLayout(); this.panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.ud_Analysis_AmbiguousGap)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).BeginInit(); this.SuspendLayout(); // // bw_History @@ -90,6 +90,45 @@ this.panel1.Size = new System.Drawing.Size(893, 100); this.panel1.TabIndex = 2; // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(393, 51); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(32, 13); + this.label2.TabIndex = 6; + this.label2.Text = "secs."; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(9, 51); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(276, 13); + this.label1.TabIndex = 5; + this.label1.Text = "Timespan within two crossings considered as ambiguous:"; + // + // ud_Analysis_AmbiguousGap + // + this.ud_Analysis_AmbiguousGap.DataBindings.Add(new System.Windows.Forms.Binding("Value", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_AmbigousGap", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.ud_Analysis_AmbiguousGap.Location = new System.Drawing.Point(318, 49); + this.ud_Analysis_AmbiguousGap.Name = "ud_Analysis_AmbiguousGap"; + this.ud_Analysis_AmbiguousGap.Size = new System.Drawing.Size(60, 20); + this.ud_Analysis_AmbiguousGap.TabIndex = 4; + this.ud_Analysis_AmbiguousGap.Value = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_AmbigousGap; + // + // cb_Analysis_CrossingHistory_WithSignlaLevel + // + this.cb_Analysis_CrossingHistory_WithSignlaLevel.AutoSize = true; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Checked = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_WithSignalLevel; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_WithSignalLevel", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Location = new System.Drawing.Point(12, 21); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Name = "cb_Analysis_CrossingHistory_WithSignlaLevel"; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Size = new System.Drawing.Size(258, 17); + this.cb_Analysis_CrossingHistory_WithSignlaLevel.TabIndex = 3; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.Text = "Consider crossings with recorded signal level only"; + this.cb_Analysis_CrossingHistory_WithSignlaLevel.UseVisualStyleBackColor = true; + // // btn_History_Export // this.btn_History_Export.Location = new System.Drawing.Point(697, 41); @@ -151,45 +190,6 @@ this.ch_Crossing_History.TabIndex = 5; this.ch_Crossing_History.Text = "History"; // - // cb_Analysis_CrossingHistory_WithSignlaLevel - // - this.cb_Analysis_CrossingHistory_WithSignlaLevel.AutoSize = true; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Checked = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_WithSignalLevel; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.DataBindings.Add(new System.Windows.Forms.Binding("Checked", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_WithSignalLevel", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Location = new System.Drawing.Point(12, 21); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Name = "cb_Analysis_CrossingHistory_WithSignlaLevel"; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Size = new System.Drawing.Size(258, 17); - this.cb_Analysis_CrossingHistory_WithSignlaLevel.TabIndex = 3; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.Text = "Consider crossings with recorded signal level only"; - this.cb_Analysis_CrossingHistory_WithSignlaLevel.UseVisualStyleBackColor = true; - // - // ud_Analysis_AmbiguousGap - // - this.ud_Analysis_AmbiguousGap.DataBindings.Add(new System.Windows.Forms.Binding("Value", global::AirScout.Properties.Settings.Default, "Analysis_CrossingHistory_AmbiguousGap", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.ud_Analysis_AmbiguousGap.Location = new System.Drawing.Point(318, 49); - this.ud_Analysis_AmbiguousGap.Name = "ud_Analysis_AmbiguousGap"; - this.ud_Analysis_AmbiguousGap.Size = new System.Drawing.Size(60, 20); - this.ud_Analysis_AmbiguousGap.TabIndex = 4; - this.ud_Analysis_AmbiguousGap.Value = global::AirScout.Properties.Settings.Default.Analysis_CrossingHistory_AmbigousGap; - // - // label1 - // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(9, 51); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(276, 13); - this.label1.TabIndex = 5; - this.label1.Text = "Timespan within two crossings considered as ambiguous:"; - // - // label2 - // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(393, 51); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(32, 13); - this.label2.TabIndex = 6; - this.label2.Text = "secs."; - // // CrossingHistoryDlg // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -206,8 +206,8 @@ this.ss_Main.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.ud_Analysis_AmbiguousGap)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.ch_Crossing_History)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); diff --git a/AirScout/DeleteSingleStationDlg.Designer.cs b/AirScout/DeleteSingleStationDlg.Designer.cs new file mode 100644 index 0000000..9f71800 --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.Designer.cs @@ -0,0 +1,140 @@ +namespace AirScout +{ + partial class DeleteSingleStationDlg + { + /// + /// 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() + { + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DeleteSingleStationDlg)); + this.label1 = new System.Windows.Forms.Label(); + this.cb_Call = new System.Windows.Forms.ComboBox(); + this.cb_Locator = new System.Windows.Forms.ComboBox(); + this.label2 = new System.Windows.Forms.Label(); + this.label3 = new System.Windows.Forms.Label(); + this.btn_Delete = new System.Windows.Forms.Button(); + this.btn_Cancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // label1 + // + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(12, 19); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(464, 92); + this.label1.TabIndex = 0; + this.label1.Text = resources.GetString("label1.Text"); + // + // cb_Call + // + this.cb_Call.FormattingEnabled = true; + this.cb_Call.Location = new System.Drawing.Point(55, 132); + this.cb_Call.Name = "cb_Call"; + this.cb_Call.Size = new System.Drawing.Size(121, 21); + this.cb_Call.TabIndex = 1; + this.cb_Call.DropDown += new System.EventHandler(this.cb_Call_DropDown); + this.cb_Call.SelectedIndexChanged += new System.EventHandler(this.cb_Call_SelectedIndexChanged); + this.cb_Call.TextChanged += new System.EventHandler(this.cb_Call_TextChanged); + this.cb_Call.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.cb_Call_KeyPress); + // + // cb_Locator + // + this.cb_Locator.FormattingEnabled = true; + this.cb_Locator.Location = new System.Drawing.Point(279, 132); + this.cb_Locator.Name = "cb_Locator"; + this.cb_Locator.Size = new System.Drawing.Size(121, 21); + this.cb_Locator.TabIndex = 2; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(22, 135); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(27, 13); + this.label2.TabIndex = 3; + this.label2.Text = "Call:"; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(223, 135); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(46, 13); + this.label3.TabIndex = 4; + this.label3.Text = "Locator:"; + // + // btn_Delete + // + this.btn_Delete.BackColor = System.Drawing.Color.Tomato; + this.btn_Delete.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_Delete.ForeColor = System.Drawing.Color.White; + this.btn_Delete.Location = new System.Drawing.Point(55, 173); + this.btn_Delete.Name = "btn_Delete"; + this.btn_Delete.Size = new System.Drawing.Size(121, 35); + this.btn_Delete.TabIndex = 5; + this.btn_Delete.Text = "Delete"; + this.btn_Delete.UseVisualStyleBackColor = false; + // + // btn_Cancel + // + this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.btn_Cancel.Location = new System.Drawing.Point(279, 173); + this.btn_Cancel.Name = "btn_Cancel"; + this.btn_Cancel.Size = new System.Drawing.Size(121, 35); + this.btn_Cancel.TabIndex = 6; + this.btn_Cancel.Text = "Cancel"; + this.btn_Cancel.UseVisualStyleBackColor = true; + // + // DeleteSingleStationDlg + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.CancelButton = this.btn_Cancel; + this.ClientSize = new System.Drawing.Size(485, 220); + this.Controls.Add(this.btn_Cancel); + this.Controls.Add(this.btn_Delete); + this.Controls.Add(this.label3); + this.Controls.Add(this.label2); + this.Controls.Add(this.cb_Locator); + this.Controls.Add(this.cb_Call); + this.Controls.Add(this.label1); + this.Name = "DeleteSingleStationDlg"; + this.Text = "Delete Single Station"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.Label label1; + private System.Windows.Forms.ComboBox cb_Call; + private System.Windows.Forms.ComboBox cb_Locator; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Button btn_Delete; + private System.Windows.Forms.Button btn_Cancel; + } +} \ No newline at end of file diff --git a/AirScout/DeleteSingleStationDlg.cs b/AirScout/DeleteSingleStationDlg.cs new file mode 100644 index 0000000..425f14e --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.cs @@ -0,0 +1,71 @@ +using ScoutBase.Stations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Windows.Forms; + +namespace AirScout +{ + public partial class DeleteSingleStationDlg : Form + { + bool SelectionChanged = false; + + public DeleteSingleStationDlg() + { + InitializeComponent(); + } + + private void cb_Call_TextChanged(object sender, EventArgs e) + { + if (!SelectionChanged) + { + int start = cb_Call.SelectionStart; + int len = cb_Call.SelectionLength; + string text = cb_Call.Text.ToUpper().Trim(); + if (cb_Call.Text != text) + cb_Call.Text = text; + cb_Call.SelectionStart = start; + cb_Call.SelectionLength = len; + } + SelectionChanged = false; + } + + private void cb_Call_SelectedIndexChanged(object sender, EventArgs e) + { + // suppress handling on text input + if (!cb_Call.DroppedDown) + return; + if (cb_Call.SelectedItem != null) + { + SelectionChanged = true; + cb_Call.Text = (string)cb_Call.SelectedItem; + } + } + + private void cb_Call_KeyPress(object sender, KeyPressEventArgs e) + { + } + + private void cb_Call_DropDown(object sender, EventArgs e) + { + if (!cb_Call.DroppedDown && (cb_Call.Text.Length >= 2)) + { + List l = StationData.Database.LocationGetAll("%" + cb_Call.Text + "%"); + if (l != null) + { + cb_Call.Items.Clear(); + cb_Locator.Items.Clear(); + foreach (LocationDesignator ld in l) + { + cb_Call.Items.Add(ld.Call); + cb_Locator.Items.Add(ld.Loc); + } + } + } + } + } +} diff --git a/AirScout/DeleteSingleStationDlg.resx b/AirScout/DeleteSingleStationDlg.resx new file mode 100644 index 0000000..3b49f55 --- /dev/null +++ b/AirScout/DeleteSingleStationDlg.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + Use this dialog to find and remove a single station/locator combination from the local station database. +CAUTION: You can only remove own entries permanently. If a station/locator combination is part of the global database it would be re-inserted on next update. + + \ No newline at end of file diff --git a/AirScout/MapStationDlg.Designer.cs b/AirScout/MapStationDlg.Designer.cs index be4241c..1b9c7b1 100644 --- a/AirScout/MapStationDlg.Designer.cs +++ b/AirScout/MapStationDlg.Designer.cs @@ -40,7 +40,6 @@ this.label8 = new System.Windows.Forms.Label(); this.gm_Callsign = new GMap.NET.WindowsForms.GMapControl(); this.tb_Callsign = new ScoutBase.Core.CallsignTextBox(); - this.tb_Locator = new ScoutBase.Core.LocatorTextBox(); this.tb_Longitude = new ScoutBase.Core.DoubleTextBox(); this.tb_Latitude = new ScoutBase.Core.DoubleTextBox(); this.btn_Cancel = new System.Windows.Forms.Button(); @@ -48,6 +47,13 @@ this.label1 = new System.Windows.Forms.Label(); this.tb_Elevation = new ScoutBase.Core.DoubleTextBox(); this.label2 = new System.Windows.Forms.Label(); + this.ss_Main = new System.Windows.Forms.StatusStrip(); + this.tsl_Status = new System.Windows.Forms.ToolStripStatusLabel(); + this.bw_Elevationgrid = new System.ComponentModel.BackgroundWorker(); + this.tb_Locator = new ScoutBase.Core.LocatorTextBox(); + this.cb_Options_StationsMap_OverlayElevation = new System.Windows.Forms.CheckBox(); + this.label3 = new System.Windows.Forms.Label(); + this.ss_Main.SuspendLayout(); this.SuspendLayout(); // // label19 @@ -153,7 +159,7 @@ this.gm_Callsign.RoutesEnabled = true; this.gm_Callsign.SelectedAreaFillColor = System.Drawing.Color.FromArgb(((int)(((byte)(33)))), ((int)(((byte)(65)))), ((int)(((byte)(105)))), ((int)(((byte)(225))))); this.gm_Callsign.ShowTileGridLines = false; - this.gm_Callsign.Size = new System.Drawing.Size(760, 621); + this.gm_Callsign.Size = new System.Drawing.Size(760, 617); this.gm_Callsign.TabIndex = 29; this.gm_Callsign.Zoom = 0D; this.gm_Callsign.OnMarkerEnter += new GMap.NET.WindowsForms.MarkerEnter(this.gm_Callsign_OnMarkerEnter); @@ -176,19 +182,6 @@ this.tb_Callsign.Size = new System.Drawing.Size(107, 21); this.tb_Callsign.TabIndex = 30; // - // tb_Locator - // - this.tb_Locator.DataBindings.Add(new System.Windows.Forms.Binding("SmallLettersForSubsquares", global::AirScout.Properties.Settings.Default, "Locator_SmallLettersForSubsquares", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); - this.tb_Locator.ErrorBackColor = System.Drawing.Color.Red; - this.tb_Locator.ErrorForeColor = System.Drawing.Color.White; - this.tb_Locator.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.tb_Locator.Location = new System.Drawing.Point(875, 140); - this.tb_Locator.Name = "tb_Locator"; - this.tb_Locator.Size = new System.Drawing.Size(107, 21); - this.tb_Locator.SmallLettersForSubsquares = global::AirScout.Properties.Settings.Default.Locator_SmallLettersForSubsquares; - this.tb_Locator.TabIndex = 35; - this.tb_Locator.TextChanged += new System.EventHandler(this.tb_Locator_TextChanged); - // // tb_Longitude // this.tb_Longitude.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); @@ -199,7 +192,7 @@ this.tb_Longitude.Name = "tb_Longitude"; this.tb_Longitude.Size = new System.Drawing.Size(107, 21); this.tb_Longitude.TabIndex = 33; - this.tb_Longitude.Text = "10.68327000"; + this.tb_Longitude.Text = "10.68327"; this.tb_Longitude.Value = 10.68327D; this.tb_Longitude.TextChanged += new System.EventHandler(this.tb_Longitude_TextChanged); // @@ -213,14 +206,14 @@ this.tb_Latitude.Name = "tb_Latitude"; this.tb_Latitude.Size = new System.Drawing.Size(107, 21); this.tb_Latitude.TabIndex = 32; - this.tb_Latitude.Text = "50.93706700"; + this.tb_Latitude.Text = "50.937067"; this.tb_Latitude.Value = 50.937067D; this.tb_Latitude.TextChanged += new System.EventHandler(this.tb_Latitude_TextChanged); // // btn_Cancel // this.btn_Cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.btn_Cancel.Location = new System.Drawing.Point(806, 685); + this.btn_Cancel.Location = new System.Drawing.Point(804, 665); this.btn_Cancel.Name = "btn_Cancel"; this.btn_Cancel.Size = new System.Drawing.Size(75, 23); this.btn_Cancel.TabIndex = 44; @@ -231,7 +224,7 @@ // btn_OK // this.btn_OK.DialogResult = System.Windows.Forms.DialogResult.OK; - this.btn_OK.Location = new System.Drawing.Point(907, 685); + this.btn_OK.Location = new System.Drawing.Point(907, 665); this.btn_OK.Name = "btn_OK"; this.btn_OK.Size = new System.Drawing.Size(75, 23); this.btn_OK.TabIndex = 45; @@ -271,6 +264,63 @@ this.label2.TabIndex = 49; this.label2.Text = "m asl"; // + // ss_Main + // + this.ss_Main.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.tsl_Status}); + this.ss_Main.Location = new System.Drawing.Point(0, 707); + this.ss_Main.Name = "ss_Main"; + this.ss_Main.Size = new System.Drawing.Size(1008, 22); + this.ss_Main.TabIndex = 50; + this.ss_Main.Text = "statusStrip1"; + // + // tsl_Status + // + this.tsl_Status.Name = "tsl_Status"; + this.tsl_Status.Size = new System.Drawing.Size(39, 17); + this.tsl_Status.Text = "Status"; + // + // bw_Elevationgrid + // + this.bw_Elevationgrid.WorkerReportsProgress = true; + this.bw_Elevationgrid.WorkerSupportsCancellation = true; + this.bw_Elevationgrid.DoWork += new System.ComponentModel.DoWorkEventHandler(this.bw_Elevationgrid_DoWork); + this.bw_Elevationgrid.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_Elevationgrid_ProgressChanged); + this.bw_Elevationgrid.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_Elevationgrid_RunWorkerCompleted); + // + // tb_Locator + // + this.tb_Locator.DataBindings.Add(new System.Windows.Forms.Binding("SmallLettersForSubsquares", global::AirScout.Properties.Settings.Default, "Locator_SmallLettersForSubsquares", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged)); + this.tb_Locator.ErrorBackColor = System.Drawing.Color.Red; + this.tb_Locator.ErrorForeColor = System.Drawing.Color.White; + this.tb_Locator.Font = new System.Drawing.Font("Courier New", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.tb_Locator.Location = new System.Drawing.Point(875, 140); + this.tb_Locator.Name = "tb_Locator"; + this.tb_Locator.Size = new System.Drawing.Size(107, 21); + this.tb_Locator.SmallLettersForSubsquares = global::AirScout.Properties.Settings.Default.Locator_SmallLettersForSubsquares; + this.tb_Locator.TabIndex = 35; + this.tb_Locator.TextChanged += new System.EventHandler(this.tb_Locator_TextChanged); + // + // cb_Options_StationsMap_OverlayElevation + // + this.cb_Options_StationsMap_OverlayElevation.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; + this.cb_Options_StationsMap_OverlayElevation.Checked = global::AirScout.Properties.Settings.Default.StationsMap_OverlayElevation; + this.cb_Options_StationsMap_OverlayElevation.Location = new System.Drawing.Point(804, 267); + this.cb_Options_StationsMap_OverlayElevation.Name = "cb_Options_StationsMap_OverlayElevation"; + this.cb_Options_StationsMap_OverlayElevation.Size = new System.Drawing.Size(178, 46); + this.cb_Options_StationsMap_OverlayElevation.TabIndex = 51; + this.cb_Options_StationsMap_OverlayElevation.Text = "Overlay Elevation Grid \r\n(on zom levels >= 17)"; + this.cb_Options_StationsMap_OverlayElevation.UseVisualStyleBackColor = true; + this.cb_Options_StationsMap_OverlayElevation.CheckedChanged += new System.EventHandler(this.cb_Options_StationsMap_OverlayElevation_CheckedChanged); + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(813, 434); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(0, 13); + this.label3.TabIndex = 52; + // // MapStationDlg // this.AcceptButton = this.btn_OK; @@ -278,6 +328,9 @@ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.btn_Cancel; this.ClientSize = new System.Drawing.Size(1008, 729); + this.Controls.Add(this.label3); + this.Controls.Add(this.cb_Options_StationsMap_OverlayElevation); + this.Controls.Add(this.ss_Main); this.Controls.Add(this.label2); this.Controls.Add(this.tb_Elevation); this.Controls.Add(this.label1); @@ -302,6 +355,9 @@ this.MinimizeBox = false; this.Name = "MapStationDlg"; this.Text = "MapStationDlg"; + this.Load += new System.EventHandler(this.MapStationDlg_Load); + this.ss_Main.ResumeLayout(false); + this.ss_Main.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -328,5 +384,10 @@ private System.Windows.Forms.Label label1; private ScoutBase.Core.DoubleTextBox tb_Elevation; private System.Windows.Forms.Label label2; + private System.Windows.Forms.StatusStrip ss_Main; + private System.Windows.Forms.ToolStripStatusLabel tsl_Status; + private System.ComponentModel.BackgroundWorker bw_Elevationgrid; + private System.Windows.Forms.CheckBox cb_Options_StationsMap_OverlayElevation; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/AirScout/MapStationDlg.cs b/AirScout/MapStationDlg.cs index 4d64b29..a5b837a 100644 --- a/AirScout/MapStationDlg.cs +++ b/AirScout/MapStationDlg.cs @@ -21,6 +21,7 @@ namespace AirScout GMapOverlay Callsignpolygons = new GMapOverlay("Callsignpolygons"); GMapOverlay Callsignspositions = new GMapOverlay("Callsignpositions"); + GMapOverlay Elevationgrid = new GMapOverlay("Elevationgrid"); GMarkerGoogle UserPos = new GMarkerGoogle(new PointLatLng(0.0, 0.0), GMarkerGoogleType.red_dot); @@ -48,6 +49,7 @@ namespace AirScout gm_Callsign.MapScaleInfoEnabled = true; gm_Callsign.Overlays.Add(Callsignpolygons); gm_Callsign.Overlays.Add(Callsignspositions); + gm_Callsign.Overlays.Add(Elevationgrid); Callsignspositions.Markers.Add(UserPos); // initially set textboxes tb_Callsign.SilentText = StationLocation.Call; @@ -56,11 +58,15 @@ namespace AirScout tb_Locator.SilentText = MaidenheadLocator.LocFromLatLon(StationLocation.Lat, StationLocation.Lon, Properties.Settings.Default.Locator_SmallLettersForSubsquares, (int)Properties.Settings.Default.Locator_MaxLength / 2, Properties.Settings.Default.Locator_AutoLength); tb_Elevation.SilentValue = GetElevation(StationLocation.Lat, StationLocation.Lon); ValidateDetails(); - // show initial zoom level in text box - gm_Callsign_OnMapZoomChanged(); } + private void MapStationDlg_Load(object sender, EventArgs e) + { + // initialen Zoomlevel anzeigen + gm_Callsign_OnMapZoomChanged(); + } + private void btn_Cancel_Click(object sender, EventArgs e) { @@ -264,6 +270,166 @@ namespace AirScout { // maintain zoom level tb_Zoom.Text = gm_Callsign.Zoom.ToString(); + ShowElevationGrid(); + } + + private void ShowElevationGrid() + { + while (bw_Elevationgrid.IsBusy) + { + bw_Elevationgrid.CancelAsync(); + Application.DoEvents(); + } + Elevationgrid.Polygons.Clear(); + if (cb_Options_StationsMap_OverlayElevation.Checked && (gm_Callsign.Zoom >= 17)) + { + bw_Elevationgrid.RunWorkerAsync(); + } + } + + private void bw_Elevationgrid_DoWork(object sender, DoWorkEventArgs e) + { + // fill elevation grid + bw_Elevationgrid.ReportProgress(0, "Calculating elevation grid..."); + Elevationgrid.Polygons.Clear(); + // convert view bounds to the beginning/end of Maidenhead locators + string loc = MaidenheadLocator.LocFromLatLon(gm_Callsign.ViewArea.Lat - gm_Callsign.ViewArea.HeightLat, gm_Callsign.ViewArea.Lng,false,3); + double minlat = MaidenheadLocator.LatFromLoc(loc, PositionInRectangle.BottomLeft); + double minlon = MaidenheadLocator.LonFromLoc(loc, PositionInRectangle.BottomLeft); + loc = MaidenheadLocator.LocFromLatLon(gm_Callsign.ViewArea.Lat, gm_Callsign.ViewArea.Lng + gm_Callsign.ViewArea.WidthLng, false, 3); + double maxlat = MaidenheadLocator.LatFromLoc(loc, PositionInRectangle.TopRight); + double maxlon = MaidenheadLocator.LonFromLoc(loc, PositionInRectangle.TopRight); + double lat = minlat; + double lon = minlon; + double stepwidthlat = 5.5555555555555555555555555555556e-4 / 2; + double stepwidthlon = 5.5555555555555555555555555555556e-4; + List elvs = new List(); + double elvmin = short.MaxValue; + double elvmax = short.MinValue; + while (!bw_Elevationgrid.CancellationPending && (lat < maxlat)) + { + lon = minlon; + while (!bw_Elevationgrid.CancellationPending && (lon < maxlon)) + { + double elv = 0; + if ((lat + stepwidthlat >= gm_Callsign.ViewArea.Lat - gm_Callsign.ViewArea.HeightLat) && + (lat <= gm_Callsign.ViewArea.Lat) && + (lon + stepwidthlon >= gm_Callsign.ViewArea.Lng) && + (lon <= gm_Callsign.ViewArea.Lng + gm_Callsign.ViewArea.WidthLng)) + { + elv = ElevationData.Database[lat, lon, Properties.Settings.Default.ElevationModel]; + ElevationTile t = new ElevationTile(); + t.Lat = lat; + t.Lon = lon; + t.Elv = elv; + elvs.Add(t); + if (elv < elvmin) + elvmin = elv; + if (elv > elvmax) + elvmax = elv; + } + else + { + } + lon += stepwidthlon; + } + lat += stepwidthlat; + } + foreach (ElevationTile t in elvs) + { + List l = new List(); + l.Add(new PointLatLng((decimal)t.Lat, (decimal)t.Lon)); + l.Add(new PointLatLng((decimal)(t.Lat + stepwidthlat), (decimal)t.Lon)); + l.Add(new PointLatLng((decimal)(t.Lat + stepwidthlat), (decimal)(t.Lon + stepwidthlon))); + l.Add(new PointLatLng((decimal)t.Lat, (decimal)(t.Lon + stepwidthlon))); + GMapTextPolygon p = new GMapTextPolygon(l, t.Elv + " m"); + Color c = Color.FromArgb(100, ElevationData.Database.GetElevationColor((t.Elv - elvmin) / (elvmax - elvmin) * 10000.0)); + p.Stroke = new Pen(c); + p.Fill = new SolidBrush(c); + Font f = new Font("Courier New", 8, GraphicsUnit.Pixel); + bw_Elevationgrid.ReportProgress(1, p); + if (bw_Elevationgrid.CancellationPending) + break; + } + bw_Elevationgrid.ReportProgress(100, "Calculating elevation grid finished."); + } + + private void bw_Elevationgrid_ProgressChanged(object sender, ProgressChangedEventArgs e) + { + if (e.ProgressPercentage < 0) + { + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + if (e.ProgressPercentage == 0) + { + Elevationgrid.Polygons.Clear(); + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + else if (e.ProgressPercentage == 1) + { + GMapPolygon p = (GMapPolygon)e.UserState; + Elevationgrid.Polygons.Add(p); + tsl_Status.Text = "Adding elevation tile " + p.Name; + ss_Main.Refresh(); + } + else if (e.ProgressPercentage == 100) + { + tsl_Status.Text = (string)e.UserState; + ss_Main.Refresh(); + } + } + + private void bw_Elevationgrid_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) + { + + } + + private void cb_Options_StationsMap_OverlayElevation_CheckedChanged(object sender, EventArgs e) + { + ShowElevationGrid(); } } + + public class GMapTextPolygon : GMapPolygon + { + public GMapTextPolygon(List points, string name) : base(points, name) + { + } + + public override void OnRender(Graphics g) + { + base.OnRender(g); + StringFormat format = new StringFormat(); + format.LineAlignment = StringAlignment.Center; + format.Alignment = StringAlignment.Center; + long minx = long.MaxValue; + long maxx = long.MinValue; + long miny = long.MaxValue; + long maxy = long.MinValue; + for (int i = 0; i < this.LocalPoints.Count; i++) + { + if (this.LocalPoints[i].X < minx) + minx = this.LocalPoints[i].X; + if (this.LocalPoints[i].X > maxx) + maxx = this.LocalPoints[i].X; + if (this.LocalPoints[i].Y < miny) + miny = this.LocalPoints[i].Y; + if (this.LocalPoints[i].Y > maxy) + maxy = this.LocalPoints[i].Y; + } + RectangleF f = new RectangleF(minx, miny, maxx - minx, maxy - miny); + g.DrawString(this.Name, SystemFonts.DefaultFont, Brushes.Black, f, format); + } + } + + public class ElevationTile + { + public double Lat = 0; + public double Lon = 0; + public double Elv = 0; + } + + } diff --git a/AirScout/MapStationDlg.resx b/AirScout/MapStationDlg.resx index 55bd07d..6dc16e2 100644 --- a/AirScout/MapStationDlg.resx +++ b/AirScout/MapStationDlg.resx @@ -122,4 +122,10 @@ Use the lat/lon textboxes for numeric input or enter a valid Maidenhead Locator. Drag the needle on the map for exact location. Use mouse wheel or +/- buttons to zoom in and out. + + 17, 17 + + + 111, 17 + \ No newline at end of file diff --git a/AirScout/OptionsDlg.Designer.cs b/AirScout/OptionsDlg.Designer.cs index 5c23f23..853bf2f 100644 --- a/AirScout/OptionsDlg.Designer.cs +++ b/AirScout/OptionsDlg.Designer.cs @@ -451,6 +451,7 @@ this.bw_SRTM1_MapUpdater = new System.ComponentModel.BackgroundWorker(); this.bw_GLOBE_MapUpdater = new System.ComponentModel.BackgroundWorker(); this.bw_StationDataUpdater = new System.ComponentModel.BackgroundWorker(); + this.btn_DeleteSingleStation = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.pb_Donate)).BeginInit(); this.tab_Options_Planes.SuspendLayout(); this.groupBox48.SuspendLayout(); @@ -3644,6 +3645,7 @@ // // groupBox47 // + this.groupBox47.Controls.Add(this.btn_DeleteSingleStation); this.groupBox47.Controls.Add(this.btn_DeleteAllMapTiles); this.groupBox47.Controls.Add(this.btn_Options_DeleteAllPropagationPaths); this.groupBox47.Controls.Add(this.btn_Options_DeleteAllElevationPaths); @@ -5757,6 +5759,18 @@ this.bw_StationDataUpdater.ProgressChanged += new System.ComponentModel.ProgressChangedEventHandler(this.bw_StationDataUpdater_ProgressChanged); this.bw_StationDataUpdater.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.bw_StationDataUpdater_RunWorkerCompleted); // + // btn_DeleteSingleStation + // + this.btn_DeleteSingleStation.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.btn_DeleteSingleStation.Location = new System.Drawing.Point(165, 48); + this.btn_DeleteSingleStation.Name = "btn_DeleteSingleStation"; + this.btn_DeleteSingleStation.Size = new System.Drawing.Size(122, 23); + this.btn_DeleteSingleStation.TabIndex = 3; + this.btn_DeleteSingleStation.Text = "Delete Single Station"; + this.tt_Options.SetToolTip(this.btn_DeleteSingleStation, "Deletes all cached map tiles from database"); + this.btn_DeleteSingleStation.UseVisualStyleBackColor = true; + this.btn_DeleteSingleStation.Click += new System.EventHandler(this.btn_DeleteSingleStation_Click); + // // OptionsDlg // this.AcceptButton = this.btn_Options_OK; @@ -6329,5 +6343,6 @@ private System.Windows.Forms.Label label105; private System.Windows.Forms.Label label145; private System.Windows.Forms.Button btn_Options_Path_Export; + private System.Windows.Forms.Button btn_DeleteSingleStation; } } \ No newline at end of file diff --git a/AirScout/OptionsDlg.cs b/AirScout/OptionsDlg.cs index 2dbdafb..c4ff8bf 100644 --- a/AirScout/OptionsDlg.cs +++ b/AirScout/OptionsDlg.cs @@ -359,6 +359,12 @@ namespace AirScout MapData.Database.TileDeleteAll(); } + private void btn_DeleteSingleStation_Click(object sender, EventArgs e) + { + DeleteSingleStationDlg Dlg = new DeleteSingleStationDlg(); + Dlg.ShowDialog(); + } + private void btn_Options_ScoutBase_Database_Maintenance_Click(object sender, EventArgs e) { DatabaseMaintenanceDlg Dlg = new DatabaseMaintenanceDlg(StationData.Database); diff --git a/AirScout/Properties/AssemblyInfo.cs b/AirScout/Properties/AssemblyInfo.cs index 5913caf..5ca38fb 100644 --- a/AirScout/Properties/AssemblyInfo.cs +++ b/AirScout/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.4")] -[assembly: AssemblyFileVersion("1.3.3.4")] +[assembly: AssemblyVersion("1.3.3.6")] +[assembly: AssemblyFileVersion("1.3.3.6")] diff --git a/AirScout/Properties/Settings.Designer.cs b/AirScout/Properties/Settings.Designer.cs index 0215e6a..552b659 100644 --- a/AirScout/Properties/Settings.Designer.cs +++ b/AirScout/Properties/Settings.Designer.cs @@ -2304,5 +2304,17 @@ Digital data base on the World Wide Web (URL: http://www.ngdc.noaa.gov/mgg/topo/ this["Map_Preloader_MaxZoom"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool StationsMap_OverlayElevation { + get { + return ((bool)(this["StationsMap_OverlayElevation"])); + } + set { + this["StationsMap_OverlayElevation"] = value; + } + } } } diff --git a/AirScout/Properties/Settings.settings b/AirScout/Properties/Settings.settings index 6f73e24..39add42 100644 --- a/AirScout/Properties/Settings.settings +++ b/AirScout/Properties/Settings.settings @@ -604,5 +604,8 @@ MEaSUREs data and products are available at no charge from the LP DAAC.See https 11 + + False + \ No newline at end of file diff --git a/AirScout/Requirements.txt b/AirScout/Requirements.txt new file mode 100644 index 0000000..bfcac3b --- /dev/null +++ b/AirScout/Requirements.txt @@ -0,0 +1,12 @@ +***************** AirScout Requirements ************************** + +- GreatCircle, distance and locator layer on map (DJ5AR) +- Snooze button for alarm on main window, clickable in PLAY mode () +- Calculate Doppler + +* watch list +- Add/remove call sign from Multi View tab over UDP command +- add stations to watchlist based on DXCC, Loc, QTF range from QTF1 to QTF2 + + + diff --git a/AirScout/VersionHistory.txt b/AirScout/VersionHistory.txt index 3322cf8..de2b5a3 100644 --- a/AirScout/VersionHistory.txt +++ b/AirScout/VersionHistory.txt @@ -1,4 +1,18 @@ -2020-04-25: V1.3.3.4 +2021-12-23: V1.3.3.6 +==================== + +- Feature: Elevation grid overlay on "Optionms/Stations/Map" to better understand elevation resolution issues and local situation (for zoom levels >= 17) +- Bugfix: AirScout crashes when opening Crossing History Dialog window --> fixed (tnx PU34HAG) +- Bugfix: Near field suppression did not work correctly, showing strange local obstructions under some circumstances --> fixed +- Bugfix: No more planes visible (Exception messages shown in status bar and log file) with some language settings (at least Turkish) --> fixed (tnx TA2NC) + +2020-04-25: V1.3.3.5 +==================== + +- Bugfix: Chunked transport of web content failed while fetching plane feeds (OpenSky, Virtual Radar Server) --> fixed +- Bugfix: Drawing map throws an exception under some circumstances --> fixed, added some error handling (tnx SM7LCB) + +2020-04-25: V1.3.3.4 ==================== - Bugfix: AirScout always reverts to default call signs (DL2ALF <> GB3MHZ) when area of interest is set outside Europe --> fixed (tnx VK3VG) diff --git a/AirScout/app.config b/AirScout/app.config index 0cd43f1..e6d5b26 100644 --- a/AirScout/app.config +++ b/AirScout/app.config @@ -603,6 +603,9 @@ MEaSUREs data and products are available at no charge from the LP DAAC.See https 11 + + False + diff --git a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs index 2b3e71f..a862b73 100644 --- a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs +++ b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs @@ -657,29 +657,36 @@ namespace GMap.NET.WindowsForms { foreach(WindowsFormsImage img in t.Overlays) { - if(img != null && img.Img != null) + try { - if(!found) - found = true; + if (img != null && img.Img != null) + { + if (!found) + found = true; - if(!img.IsParent) - { + if (!img.IsParent) + { #if !PocketPC - g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); #else - g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); + g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); #endif - } + } #if !PocketPC - else - { - // TODO: move calculations to loader thread - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + else + { + // TODO: move calculations to loader thread + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - } + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } #endif + } + } + catch (Exception ex) + { + Console.WriteLine("GMapControl: Error while drwing Image: " + ex.Message); } } } diff --git a/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs b/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs index 17d5975..cb4e42b 100644 --- a/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs +++ b/SQLiteDatabase/SQLiteDatabase/SQLiteEntry.cs @@ -102,13 +102,13 @@ namespace System.Data.SQLite if (index < 0) index = i; // Console.WriteLine("[" + T.Name + ".FillFromRow] DataColumn not found: " + p.Name); - if (p.PropertyType.Name.ToUpper() == "STRING") - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if ((p.PropertyType.Name.ToUpper() == "FLOAT") || (p.PropertyType.Name.ToUpper() == "DOUBLE")) - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "INT32") - p.SetValue(this, (row[index].GetType().Name != "DBNull") ? row[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "DATETIME") + if (p.PropertyType == typeof(string)) + p.SetValue(this, (row[index].GetType() != typeof(DBNull)) ? row[index] : null, null); + else if ((p.PropertyType == typeof(float)) || (p.PropertyType == typeof(double))) + p.SetValue(this, (row[index].GetType() !=typeof(DBNull)) ? row[index] : null, null); + else if (p.PropertyType == typeof(int)) + p.SetValue(this, (row[index].GetType() != typeof(DBNull)) ? row[index] : null, null); + else if (p.PropertyType == typeof(DateTime)) { if ((row[index].GetType() == typeof(int)) || (row[index].GetType() == typeof(long))) @@ -118,7 +118,7 @@ namespace System.Data.SQLite else p.SetValue(this, row[index], null); } - else if (p.PropertyType.BaseType.Name.ToUpper() == "ENUM") + else if (p.PropertyType.BaseType == typeof(Enum)) p.SetValue(this, System.Convert.ToInt32(row[index]), null); else p.SetValue(this, ByteArrayToObject((byte[])row[index]), null); @@ -154,13 +154,13 @@ namespace System.Data.SQLite if (index < 0) index = i; // Console.WriteLine("[" + T.Name + ".FillFromRow] DataColumn not found: " + p.Name); - if (p.PropertyType.Name.ToUpper() == "STRING") - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if ((p.PropertyType.Name.ToUpper() == "FLOAT") || (p.PropertyType.Name.ToUpper() == "DOUBLE")) - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "INT32") - p.SetValue(this, (record[index].GetType().Name != "DBNull") ? record[index] : null, null); - else if (p.PropertyType.Name.ToUpper() == "DATETIME") + if (p.PropertyType == typeof(string)) + p.SetValue(this, (record[index].GetType() != typeof (DBNull)) ? record[index] : null, null); + else if ((p.PropertyType == typeof(float)) || (p.PropertyType == typeof(double))) + p.SetValue(this, (record[index].GetType() != typeof(DBNull)) ? record[index] : null, null); + else if (p.PropertyType == typeof(int)) + p.SetValue(this, (record[index].GetType() != typeof(DBNull)) ? record[index] : null, null); + else if (p.PropertyType == typeof(DateTime)) { if ((record[index].GetType() == typeof(int)) || (record[index].GetType() == typeof(long))) @@ -170,7 +170,7 @@ namespace System.Data.SQLite else p.SetValue(this, record[index], null); } - else if (p.PropertyType.BaseType.Name.ToUpper() == "ENUM") + else if (p.PropertyType.BaseType == typeof(Enum)) p.SetValue(this, System.Convert.ToInt32(record[index]), null); else p.SetValue(this, ByteArrayToObject((byte[])record[index]), null); diff --git a/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs b/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs index d7b7742..e376005 100644 --- a/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs +++ b/ScoutBase/ScoutBase.Elevation/ElevationDatabase.cs @@ -428,6 +428,18 @@ namespace ScoutBase.Elevation } return 0; } + + public Color GetElevationColor(double elv) + { + DEMColorPalette palette = new DEMColorPalette(); + double e = (double)(elv) / 100.0; + if (e < 0) + e = 0; + if (e > 100) + e = 100; + return palette.GetColor(e); + } + public Bitmap DrawElevationBitmap(double minlat, double minlon, double maxlat, double maxlon, int width, int height, ELEVATIONMODEL model) { int minelv = 0; @@ -1714,7 +1726,7 @@ namespace ScoutBase.Elevation for (int j = 0; j < bm.Height; j++) bm.SetPixel(i, j, c); } - bm.Save("DEMPalette.bmp"); + // bm.Save("DEMPalette.bmp"); } public Color GetColor(double percentage) diff --git a/ScoutBase/ScoutBase.Elevation/ElevationTile.cs b/ScoutBase/ScoutBase.Elevation/ElevationTile.cs index e647757..4376c05 100644 --- a/ScoutBase/ScoutBase.Elevation/ElevationTile.cs +++ b/ScoutBase/ScoutBase.Elevation/ElevationTile.cs @@ -162,8 +162,8 @@ namespace ScoutBase.Elevation /// The elevation. ElvMissingFlag if not found. public short GetElevation (double lat, double lon) { - int i = (int)((lat - BaseLat) / StepWidthLat); - int j = (int)((lon - BaseLon) / StepWidthLon); + int i = (int)(((lat - BaseLat) / StepWidthLat)); + int j = (int)(((lon - BaseLon) / StepWidthLon)); try { return Elv[j,i]; diff --git a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs index fe75075..305b3d2 100644 --- a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs +++ b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs @@ -470,17 +470,17 @@ namespace ScoutBase.Propagation double eps1; double eps2; if (dist1 > nf) + { eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); - else - eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, nf, ep.Path[i] + f1c1, radius); - if (eps1 > eps1_min) - eps1_min = eps1; + if (eps1 > eps1_min) + eps1_min = eps1; + } if (dist2 > nf) + { eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); - else - eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, nf, ep.Path[i] + f1c2, radius); - if (eps2 > eps2_min) - eps2_min = eps2; + if (eps2 > eps2_min) + eps2_min = eps2; + } if (caller != null) { // abort calculation if cancellation pending diff --git a/ScoutBase/ScoutBase.Stations/StationDatabase.cs b/ScoutBase/ScoutBase.Stations/StationDatabase.cs index 1850bfc..e6660d7 100644 --- a/ScoutBase/ScoutBase.Stations/StationDatabase.cs +++ b/ScoutBase/ScoutBase.Stations/StationDatabase.cs @@ -211,8 +211,10 @@ namespace ScoutBase.Stations public List LocationFindAll(string call) { - LocationDesignator ld = new LocationDesignator(call); List l = new List(); + if (String.IsNullOrEmpty(call)) + return l; + LocationDesignator ld = new LocationDesignator(call); lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -235,6 +237,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindLastRecent(string call) { LocationDesignator ld = new LocationDesignator(call); + if (String.IsNullOrEmpty(call)) + return null; lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -251,6 +255,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindMostHit(string call) { LocationDesignator ld = new LocationDesignator(call); + if (String.IsNullOrEmpty(call)) + return null; lock (db.DBCommand) { // Loc is empty --> search for last recent location for this call @@ -266,11 +272,15 @@ namespace ScoutBase.Stations public LocationDesignator LocationFind(string call) { + if (String.IsNullOrEmpty(call)) + return null; return LocationFindLastRecent(call); } public LocationDesignator LocationFind(string call, string loc) { + if (String.IsNullOrEmpty(call) || String.IsNullOrEmpty(loc)) + return null; LocationDesignator ld = new LocationDesignator(call, loc); return LocationFind(ld); } @@ -300,6 +310,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindOrUpdateOrCreate(string call, double lat, double lon) { + if (String.IsNullOrEmpty(call)) + return null; LocationDesignator ld = new LocationDesignator(call, MaidenheadLocator.LocFromLatLon(lat, lon, false, 3)); // try to find entry with call & loc matching ld = LocationFind(ld); @@ -326,6 +338,8 @@ namespace ScoutBase.Stations public LocationDesignator LocationFindOrCreate(string call, string loc) { + if (String.IsNullOrEmpty(call) || String.IsNullOrEmpty(loc)) + return null; LocationDesignator ld = this.LocationFind(call, loc); if (ld == null) { @@ -539,6 +553,18 @@ namespace ScoutBase.Stations } + public List LocationGetAll(string call) + { + List l = new List(); + DataTable Result = db.Select("SELECT * FROM " + LocationDesignator.TableName + " WHERE CALL LIKE '" + call + "' ORDER BY Call ASC"); + if ((Result == null) || (Result.Rows.Count == 0)) + return l; + foreach (DataRow row in Result.Rows) + l.Add(new LocationDesignator(row)); + return l; + + } + public List LocationGetAll(BackgroundWorker caller) { // gets all locations from database From 8653f6f95e7d098e043a357c1beb5c3f93dbdcf9 Mon Sep 17 00:00:00 2001 From: dl2alf Date: Sun, 2 Jan 2022 09:22:23 +0100 Subject: [PATCH 3/4] V1.3.3.6 Merge with V1.4.x --- .../Properties/AssemblyInfo.cs | 4 +- .../TLS.cs | 91 +- .../VirtualRadarServer.cs | 9 +- AirScout/Properties/AssemblyInfo.cs | 4 +- .../GMap.NET.WindowsForms/GMapControl.cs | 5502 +++++++++-------- .../PropagationDatabase.cs | 58 +- 6 files changed, 2881 insertions(+), 2787 deletions(-) diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs index 75276f8..0259f8c 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.1")] -[assembly: AssemblyFileVersion("1.3.3.1")] +[assembly: AssemblyVersion("1.3.3.4")] +[assembly: AssemblyFileVersion("1.3.3.4")] diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs index b3bf035..e3bb157 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs @@ -74,7 +74,7 @@ namespace System.Net throw new TimeoutException("Connection timed out."); } while (!trailer.Contains("\r\n")); - Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + // Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); response += resp; return true; } @@ -91,50 +91,57 @@ namespace System.Net int contentlength = 0; // chunked transfer, first line should contain content length // read stream bytewise until CRLF is detected - do + try { - count = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); - // finished reading all chunks - if (contentlength == 0) + catch (Exception ex) { - Console.WriteLine("Reading chunked content finished"); - return true; + Console.WriteLine("Error while reading chunked content: " + ex.Message); } - int bytesread = 0; - // read content bytewise - while (bytesread < contentlength) - { - bytesread += stream.Read(buff, 0, buff.Length); - // add it to response - resp += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); - } - string trailer = ""; - // reassign buffer - buff = new byte[1]; - // read stream bytewise until CRLFCRLF is detected, should be the next two bytes - do - { - count = stream.Read(buff, 0, buff.Length); - trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); - } - while (!trailer.Contains("\r\n")); - Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + // Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); response += resp; return false; } - public static string DownloadFile (string url, int timeout, string apikey) + public static string DownloadFile(string url, int timeout, string apikey) { string response = ""; Uri uri = null; @@ -209,13 +216,13 @@ namespace System.Net class MyTlsAuthentication : TlsAuthentication { - public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) - { - return null; + public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) + { + return null; } - public void NotifyServerCertificate(Certificate serverCertificate) - { + public void NotifyServerCertificate(Certificate serverCertificate) + { } } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs index afeaffc..79d64c4 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs @@ -178,7 +178,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer } -[Export(typeof(IPlaneFeedPlugin))] + [Export(typeof(IPlaneFeedPlugin))] [ExportMetadata("Name", "PlaneFeedPlugin")] public class VirtualRadarServerPlugin : IPlaneFeedPlugin { @@ -297,7 +297,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer APIKey = Settings.APIKey; return; } - + // get AirScout internal key try { @@ -377,7 +377,6 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer { // deserialize JSON dynamic root = JsonConvert.DeserializeObject(json); - // get local time of request in milliseconds DateTime lt = DateTime.UtcNow; long ltime = (long)(lt - new DateTime(1970, 1, 1)).TotalMilliseconds; @@ -410,7 +409,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer { PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first - plane.Hex = ReadPropertyString(ac, "Icao").Trim().Replace("\"",""); + plane.Hex = ReadPropertyString(ac, "Icao").Trim().Replace("\"", ""); // get position plane.Lat = ReadPropertyDouble(ac, "Lat"); plane.Lon = ReadPropertyDouble(ac, "Long"); @@ -549,7 +548,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer return decrypted; } - [System.Diagnostics.DebuggerNonUserCode] + [System.Diagnostics.DebuggerNonUserCode] private string ReadPropertyString(dynamic o, string propertyname) { string s = null; diff --git a/AirScout/Properties/AssemblyInfo.cs b/AirScout/Properties/AssemblyInfo.cs index 5ca38fb..1df1696 100644 --- a/AirScout/Properties/AssemblyInfo.cs +++ b/AirScout/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.6")] -[assembly: AssemblyFileVersion("1.3.3.6")] +[assembly: AssemblyVersion("1.3.3.7")] +[assembly: AssemblyFileVersion("1.3.3.7")] diff --git a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs index a862b73..37e5c83 100644 --- a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs +++ b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs @@ -1,287 +1,287 @@  namespace GMap.NET.WindowsForms { - using System; - using System.ComponentModel; - using System.Drawing; - using System.Drawing.Drawing2D; - using System.Drawing.Imaging; - using System.IO; - using System.Threading; - using System.Windows.Forms; - using GMap.NET; - using GMap.NET.Internals; - using GMap.NET.ObjectModel; - using System.Diagnostics; - using System.Drawing.Text; - using GMap.NET.MapProviders; + using System; + using System.ComponentModel; + using System.Drawing; + using System.Drawing.Drawing2D; + using System.Drawing.Imaging; + using System.IO; + using System.Threading; + using System.Windows.Forms; + using GMap.NET; + using GMap.NET.Internals; + using GMap.NET.ObjectModel; + using System.Diagnostics; + using System.Drawing.Text; + using GMap.NET.MapProviders; #if !PocketPC - using System.Runtime.Serialization.Formatters.Binary; - using System.Collections.Generic; - using GMap.NET.Projections; + using System.Runtime.Serialization.Formatters.Binary; + using System.Collections.Generic; + using GMap.NET.Projections; #else using OpenNETCF.ComponentModel; #endif - /// - /// GMap.NET control for Windows Forms - /// - public partial class GMapControl : UserControl, Interface - { + /// + /// GMap.NET control for Windows Forms + /// + public partial class GMapControl : UserControl, Interface + { #if !PocketPC - /// - /// occurs when clicked on marker - /// - public event MarkerClick OnMarkerClick; + /// + /// occurs when clicked on marker + /// + public event MarkerClick OnMarkerClick; - /// - /// occurs when clicked on polygon - /// - public event PolygonClick OnPolygonClick; + /// + /// occurs when clicked on polygon + /// + public event PolygonClick OnPolygonClick; - /// - /// occurs when clicked on route - /// - public event RouteClick OnRouteClick; + /// + /// occurs when clicked on route + /// + public event RouteClick OnRouteClick; - /// - /// occurs on mouse enters route area - /// - public event RouteEnter OnRouteEnter; + /// + /// occurs on mouse enters route area + /// + public event RouteEnter OnRouteEnter; - /// - /// occurs on mouse leaves route area - /// - public event RouteLeave OnRouteLeave; + /// + /// occurs on mouse leaves route area + /// + public event RouteLeave OnRouteLeave; - /// - /// occurs when mouse selection is changed - /// - public event SelectionChange OnSelectionChange; + /// + /// occurs when mouse selection is changed + /// + public event SelectionChange OnSelectionChange; #endif - /// - /// occurs on mouse enters marker area - /// - public event MarkerEnter OnMarkerEnter; + /// + /// occurs on mouse enters marker area + /// + public event MarkerEnter OnMarkerEnter; - /// - /// occurs on mouse leaves marker area - /// - public event MarkerLeave OnMarkerLeave; + /// + /// occurs on mouse leaves marker area + /// + public event MarkerLeave OnMarkerLeave; - /// - /// occurs on mouse enters Polygon area - /// - public event PolygonEnter OnPolygonEnter; + /// + /// occurs on mouse enters Polygon area + /// + public event PolygonEnter OnPolygonEnter; - /// - /// occurs on mouse leaves Polygon area - /// - public event PolygonLeave OnPolygonLeave; + /// + /// occurs on mouse leaves Polygon area + /// + public event PolygonLeave OnPolygonLeave; - /// - /// list of overlays, should be thread safe - /// - public readonly ObservableCollectionThreadSafe Overlays = new ObservableCollectionThreadSafe(); + /// + /// list of overlays, should be thread safe + /// + public readonly ObservableCollectionThreadSafe Overlays = new ObservableCollectionThreadSafe(); - /// - /// max zoom - /// - [Category("GMap.NET")] - [Description("maximum zoom level of map")] - public int MaxZoom - { - get - { - return Core.maxZoom; - } - set - { - Core.maxZoom = value; - } - } + /// + /// max zoom + /// + [Category("GMap.NET")] + [Description("maximum zoom level of map")] + public int MaxZoom + { + get + { + return Core.maxZoom; + } + set + { + Core.maxZoom = value; + } + } - /// - /// min zoom - /// - [Category("GMap.NET")] - [Description("minimum zoom level of map")] - public int MinZoom - { - get - { - return Core.minZoom; - } - set - { - Core.minZoom = value; - } - } + /// + /// min zoom + /// + [Category("GMap.NET")] + [Description("minimum zoom level of map")] + public int MinZoom + { + get + { + return Core.minZoom; + } + set + { + Core.minZoom = value; + } + } - /// - /// map zooming type for mouse wheel - /// - [Category("GMap.NET")] - [Description("map zooming type for mouse wheel")] - public MouseWheelZoomType MouseWheelZoomType - { - get - { - return Core.MouseWheelZoomType; - } - set - { - Core.MouseWheelZoomType = value; - } - } + /// + /// map zooming type for mouse wheel + /// + [Category("GMap.NET")] + [Description("map zooming type for mouse wheel")] + public MouseWheelZoomType MouseWheelZoomType + { + get + { + return Core.MouseWheelZoomType; + } + set + { + Core.MouseWheelZoomType = value; + } + } - /// - /// text on empty tiles - /// - public string EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region."; + /// + /// text on empty tiles + /// + public string EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region."; - /// - /// pen for empty tile borders - /// + /// + /// pen for empty tile borders + /// #if !PocketPC - public Pen EmptyTileBorders = new Pen(Brushes.White, 1); + public Pen EmptyTileBorders = new Pen(Brushes.White, 1); #else public Pen EmptyTileBorders = new Pen(Color.White, 1); #endif - public bool ShowCenter = true; + public bool ShowCenter = true; - /// - /// pen for scale info - /// + /// + /// pen for scale info + /// #if !PocketPC - public Pen ScalePen = new Pen(Brushes.Blue, 1); - public Pen CenterPen = new Pen(Brushes.Red, 1); + public Pen ScalePen = new Pen(Brushes.Blue, 1); + public Pen CenterPen = new Pen(Brushes.Red, 1); #else public Pen ScalePen = new Pen(Color.Blue, 1); public Pen CenterPen = new Pen(Color.Red, 1); #endif #if !PocketPC - /// - /// area selection pen - /// - public Pen SelectionPen = new Pen(Brushes.Blue, 2); + /// + /// area selection pen + /// + public Pen SelectionPen = new Pen(Brushes.Blue, 2); - Brush SelectedAreaFill = new SolidBrush(Color.FromArgb(33, Color.RoyalBlue)); - Color selectedAreaFillColor = Color.FromArgb(33, Color.RoyalBlue); + Brush SelectedAreaFill = new SolidBrush(Color.FromArgb(33, Color.RoyalBlue)); + Color selectedAreaFillColor = Color.FromArgb(33, Color.RoyalBlue); - /// - /// background of selected area - /// - [Category("GMap.NET")] - [Description("background color od the selected area")] - public Color SelectedAreaFillColor - { - get - { - return selectedAreaFillColor; - } - set - { - if(selectedAreaFillColor != value) + /// + /// background of selected area + /// + [Category("GMap.NET")] + [Description("background color od the selected area")] + public Color SelectedAreaFillColor + { + get { - selectedAreaFillColor = value; - - if(SelectedAreaFill != null) - { - SelectedAreaFill.Dispose(); - SelectedAreaFill = null; - } - SelectedAreaFill = new SolidBrush(selectedAreaFillColor); + return selectedAreaFillColor; } - } - } - - HelperLineOptions helperLineOption = HelperLineOptions.DontShow; - - /// - /// draw lines at the mouse pointer position - /// - [Browsable(false)] - public HelperLineOptions HelperLineOption - { - get - { - return helperLineOption; - } - set - { - helperLineOption = value; - renderHelperLine = (helperLineOption == HelperLineOptions.ShowAlways); - if(Core.IsStarted) + set { - Invalidate(); + if (selectedAreaFillColor != value) + { + selectedAreaFillColor = value; + + if (SelectedAreaFill != null) + { + SelectedAreaFill.Dispose(); + SelectedAreaFill = null; + } + SelectedAreaFill = new SolidBrush(selectedAreaFillColor); + } } - } - } + } - public Pen HelperLinePen = new Pen(Color.Blue, 1); - bool renderHelperLine = false; + HelperLineOptions helperLineOption = HelperLineOptions.DontShow; - protected override void OnKeyDown(KeyEventArgs e) - { - if(HelperLineOption == HelperLineOptions.ShowOnModifierKey) - { - renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); - if(renderHelperLine) + /// + /// draw lines at the mouse pointer position + /// + [Browsable(false)] + public HelperLineOptions HelperLineOption + { + get { - Invalidate(); + return helperLineOption; } - } - base.OnKeyDown(e); - } - - protected override void OnKeyUp(KeyEventArgs e) - { - if(HelperLineOption == HelperLineOptions.ShowOnModifierKey) - { - renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); - if(!renderHelperLine) + set { - Invalidate(); + helperLineOption = value; + renderHelperLine = (helperLineOption == HelperLineOptions.ShowAlways); + if (Core.IsStarted) + { + Invalidate(); + } } - } - base.OnKeyUp(e); - } + } + + public Pen HelperLinePen = new Pen(Color.Blue, 1); + bool renderHelperLine = false; + + protected override void OnKeyDown(KeyEventArgs e) + { + if (HelperLineOption == HelperLineOptions.ShowOnModifierKey) + { + renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); + if (renderHelperLine) + { + Invalidate(); + } + } + base.OnKeyDown(e); + } + + protected override void OnKeyUp(KeyEventArgs e) + { + if (HelperLineOption == HelperLineOptions.ShowOnModifierKey) + { + renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); + if (!renderHelperLine) + { + Invalidate(); + } + } + base.OnKeyUp(e); + } #endif - Brush EmptytileBrush = new SolidBrush(Color.Navy); - Color emptyTileColor = Color.Navy; + Brush EmptytileBrush = new SolidBrush(Color.Navy); + Color emptyTileColor = Color.Navy; - /// - /// color of empty tile background - /// - [Category("GMap.NET")] - [Description("background color of the empty tile")] - public Color EmptyTileColor - { - get - { - return emptyTileColor; - } - set - { - if(emptyTileColor != value) + /// + /// color of empty tile background + /// + [Category("GMap.NET")] + [Description("background color of the empty tile")] + public Color EmptyTileColor + { + get { - emptyTileColor = value; - - if(EmptytileBrush != null) - { - EmptytileBrush.Dispose(); - EmptytileBrush = null; - } - EmptytileBrush = new SolidBrush(emptyTileColor); + return emptyTileColor; } - } - } + set + { + if (emptyTileColor != value) + { + emptyTileColor = value; + + if (EmptytileBrush != null) + { + EmptytileBrush.Dispose(); + EmptytileBrush = null; + } + EmptytileBrush = new SolidBrush(emptyTileColor); + } + } + } #if PocketPC readonly Brush TileGridLinesTextBrush = new SolidBrush(Color.Red); @@ -289,463 +289,533 @@ namespace GMap.NET.WindowsForms readonly Brush CopyrightBrush = new SolidBrush(Color.Navy); #endif - /// - /// show map scale info - /// - public bool MapScaleInfoEnabled = false; + /// + /// show map scale info + /// + public bool MapScaleInfoEnabled = false; - /// - /// enables filling empty tiles using lower level images - /// - public bool FillEmptyTiles = true; + /// + /// enables filling empty tiles using lower level images + /// + public bool FillEmptyTiles = true; - /// - /// if true, selects area just by holding mouse and moving - /// - public bool DisableAltForSelection = false; + /// + /// if true, selects area just by holding mouse and moving + /// + public bool DisableAltForSelection = false; - /// - /// retry count to get tile - /// - [Browsable(false)] - public int RetryLoadTile - { - get - { - return Core.RetryLoadTile; - } - set - { - Core.RetryLoadTile = value; - } - } - - /// - /// how many levels of tiles are staying decompresed in memory - /// - [Browsable(true)] - public int LevelsKeepInMemmory - { - get - { - return Core.LevelsKeepInMemmory; - } - - set - { - Core.LevelsKeepInMemmory = value; - } - } - - /// - /// map dragg button - /// - [Category("GMap.NET")] - public MouseButtons DragButton = MouseButtons.Right; - - private bool showTileGridLines = false; - - /// - /// shows tile gridlines - /// - [Category("GMap.NET")] - [Description("shows tile gridlines")] - public bool ShowTileGridLines - { - get - { - return showTileGridLines; - } - set - { - showTileGridLines = value; - Invalidate(); - } - } - - /// - /// current selected area in map - /// - private RectLatLng selectedArea; - - [Browsable(false)] - public RectLatLng SelectedArea - { - get - { - return selectedArea; - } - set - { - selectedArea = value; - - if(Core.IsStarted) + /// + /// retry count to get tile + /// + [Browsable(false)] + public int RetryLoadTile + { + get { - Invalidate(); + return Core.RetryLoadTile; } - } - } + set + { + Core.RetryLoadTile = value; + } + } - /// - /// map boundaries - /// - public RectLatLng? BoundsOfMap = null; + /// + /// how many levels of tiles are staying decompresed in memory + /// + [Browsable(true)] + public int LevelsKeepInMemmory + { + get + { + return Core.LevelsKeepInMemmory; + } - /// - /// enables integrated DoubleBuffer for running on windows mobile - /// + set + { + Core.LevelsKeepInMemmory = value; + } + } + + /// + /// map dragg button + /// + [Category("GMap.NET")] + public MouseButtons DragButton = MouseButtons.Right; + + private bool showTileGridLines = false; + + /// + /// shows tile gridlines + /// + [Category("GMap.NET")] + [Description("shows tile gridlines")] + public bool ShowTileGridLines + { + get + { + return showTileGridLines; + } + set + { + showTileGridLines = value; + Invalidate(); + } + } + + /// + /// current selected area in map + /// + private RectLatLng selectedArea; + + [Browsable(false)] + public RectLatLng SelectedArea + { + get + { + return selectedArea; + } + set + { + selectedArea = value; + + if (Core.IsStarted) + { + Invalidate(); + } + } + } + + /// + /// map boundaries + /// + public RectLatLng? BoundsOfMap = null; + + /// + /// enables integrated DoubleBuffer for running on windows mobile + /// #if !PocketPC - public bool ForceDoubleBuffer = false; - readonly bool MobileMode = false; + public bool ForceDoubleBuffer = false; + readonly bool MobileMode = false; #else readonly bool ForceDoubleBuffer = true; #endif - /// - /// stops immediate marker/route/polygon invalidations; - /// call Refresh to perform single refresh and reset invalidation state - /// - public bool HoldInvalidation = false; + /// + /// stops immediate marker/route/polygon invalidations; + /// call Refresh to perform single refresh and reset invalidation state + /// + public bool HoldInvalidation = false; - /// - /// call this to stop HoldInvalidation and perform single forced instant refresh - /// - public override void Refresh() - { - HoldInvalidation = false; + /// + /// call this to stop HoldInvalidation and perform single forced instant refresh + /// + public override void Refresh() + { + HoldInvalidation = false; - lock(Core.invalidationLock) - { - Core.lastInvalidation = DateTime.Now; - } + lock (Core.invalidationLock) + { + Core.lastInvalidation = DateTime.Now; + } - base.Refresh(); - } + base.Refresh(); + } #if !DESIGN - /// - /// enque built-in thread safe invalidation - /// - public new void Invalidate() - { - if(Core.Refresh != null) - { - Core.Refresh.Set(); - } - } -#endif - -#if !PocketPC - private bool _GrayScale = false; - - [Category("GMap.NET")] - public bool GrayScaleMode - { - get - { - return _GrayScale; - } - set - { - _GrayScale = value; - ColorMatrix = (value == true ? ColorMatrixs.GrayScale : null); - } - } - - private bool _Negative = false; - - [Category("GMap.NET")] - public bool NegativeMode - { - get - { - return _Negative; - } - set - { - _Negative = value; - ColorMatrix = (value == true ? ColorMatrixs.Negative : null); - } - } - - ColorMatrix colorMatrix; - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public ColorMatrix ColorMatrix - { - get - { - return colorMatrix; - } - set - { - colorMatrix = value; - if(GMapProvider.TileImageProxy != null && GMapProvider.TileImageProxy is WindowsFormsImageProxy) + /// + /// enque built-in thread safe invalidation + /// + public new void Invalidate() + { + if (Core.Refresh != null) { - (GMapProvider.TileImageProxy as WindowsFormsImageProxy).ColorMatrix = value; - if(Core.IsStarted) - { - ReloadMap(); - } + Core.Refresh.Set(); } - } - } + } #endif - // internal stuff - internal readonly Core Core = new Core(); - - internal readonly Font CopyrightFont = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Regular); #if !PocketPC - internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold); + private bool _GrayScale = false; + + [Category("GMap.NET")] + public bool GrayScaleMode + { + get + { + return _GrayScale; + } + set + { + _GrayScale = value; + ColorMatrix = (value == true ? ColorMatrixs.GrayScale : null); + } + } + + private bool _Negative = false; + + [Category("GMap.NET")] + public bool NegativeMode + { + get + { + return _Negative; + } + set + { + _Negative = value; + ColorMatrix = (value == true ? ColorMatrixs.Negative : null); + } + } + + ColorMatrix colorMatrix; + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public ColorMatrix ColorMatrix + { + get + { + return colorMatrix; + } + set + { + colorMatrix = value; + if (GMapProvider.TileImageProxy != null && GMapProvider.TileImageProxy is WindowsFormsImageProxy) + { + (GMapProvider.TileImageProxy as WindowsFormsImageProxy).ColorMatrix = value; + if (Core.IsStarted) + { + ReloadMap(); + } + } + } + } +#endif + + private double _Opacity = 1.0; + public double Opacity + { + get + { + return _Opacity; + } + set + { + _Opacity = value; + if (Core.IsStarted) + { + ReloadMap(); + } + } + } + + // internal stuff + internal readonly Core Core = new Core(); + + internal readonly Font CopyrightFont = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Regular); +#if !PocketPC + internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold); #else internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular); #endif - // geändert 29.11.2012 DL2ALF - Font ScaleFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold); -// Font ScaleFont = new Font(FontFamily.GenericSansSerif, 5, FontStyle.Italic); - internal readonly StringFormat CenterFormat = new StringFormat(); - internal readonly StringFormat BottomFormat = new StringFormat(); + // geändert 29.11.2012 DL2ALF + Font ScaleFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold); + // Font ScaleFont = new Font(FontFamily.GenericSansSerif, 5, FontStyle.Italic); + internal readonly StringFormat CenterFormat = new StringFormat(); + internal readonly StringFormat BottomFormat = new StringFormat(); #if !PocketPC - readonly ImageAttributes TileFlipXYAttributes = new ImageAttributes(); + readonly ImageAttributes TileFlipXYAttributes = new ImageAttributes(); #endif - double zoomReal; - Bitmap backBuffer; - Graphics gxOff; + double zoomReal; + Bitmap backBuffer; + Graphics gxOff; #if !DESIGN - /// - /// construct - /// - public GMapControl() - { + /// + /// construct + /// + public GMapControl() + { #if !PocketPC - if(!DesignModeInConstruct && !IsDesignerHosted) + if (!DesignModeInConstruct && !IsDesignerHosted) #endif - { + { #if !PocketPC - Manager.SQLitePing(); + Manager.SQLitePing(); - this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); - this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); - this.SetStyle(ControlStyles.UserPaint, true); - this.SetStyle(ControlStyles.Opaque, true); - ResizeRedraw = true; + this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); + this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); + this.SetStyle(ControlStyles.UserPaint, true); + // this.SetStyle(ControlStyles.Opaque, true); + this.SetStyle(ControlStyles.Opaque, false); + ResizeRedraw = true; - TileFlipXYAttributes.SetWrapMode(WrapMode.TileFlipXY); + TileFlipXYAttributes.SetWrapMode(WrapMode.TileFlipXY); - // only one mode will be active, to get mixed mode create new ColorMatrix - GrayScaleMode = GrayScaleMode; - NegativeMode = NegativeMode; + // only one mode will be active, to get mixed mode create new ColorMatrix + GrayScaleMode = GrayScaleMode; + NegativeMode = NegativeMode; #endif - GMapProvider.TileImageProxy = WindowsFormsImageProxy.Instance; + GMapProvider.TileImageProxy = WindowsFormsImageProxy.Instance; - Core.SystemType = "WindowsForms"; + Core.SystemType = "WindowsForms"; - RenderMode = RenderMode.GDI_PLUS; + RenderMode = RenderMode.GDI_PLUS; - CenterFormat.Alignment = StringAlignment.Center; - CenterFormat.LineAlignment = StringAlignment.Center; + CenterFormat.Alignment = StringAlignment.Center; + CenterFormat.LineAlignment = StringAlignment.Center; - BottomFormat.Alignment = StringAlignment.Center; + BottomFormat.Alignment = StringAlignment.Center; #if !PocketPC - BottomFormat.LineAlignment = StringAlignment.Far; + BottomFormat.LineAlignment = StringAlignment.Far; #endif - if(GMaps.Instance.IsRunningOnMono) - { - // no imports to move pointer - MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter; - } + if (GMaps.Instance.IsRunningOnMono) + { + // no imports to move pointer + MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter; + } - Overlays.CollectionChanged += new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); - } - } - - void Overlays_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - if(e.NewItems != null) - { - foreach(GMapOverlay obj in e.NewItems) - { - if(obj != null) - { - obj.Control = this; - } + Overlays.CollectionChanged += new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); } + } - if(Core.IsStarted && !HoldInvalidation) + void Overlays_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.NewItems != null) { - Invalidate(); + foreach (GMapOverlay obj in e.NewItems) + { + if (obj != null) + { + obj.Control = this; + } + } + + if (Core.IsStarted && !HoldInvalidation) + { + Invalidate(); + } } - } - } + } #endif - void invalidatorEngage(object sender, ProgressChangedEventArgs e) - { - base.Invalidate(); - } + void invalidatorEngage(object sender, ProgressChangedEventArgs e) + { + base.Invalidate(); + } - /// - /// update objects when map is draged/zoomed - /// - internal void ForceUpdateOverlays() - { - try - { - HoldInvalidation = true; - - foreach(GMapOverlay o in Overlays) + /// + /// update objects when map is draged/zoomed + /// + internal void ForceUpdateOverlays() + { + try { - if(o.IsVisibile) - { - o.ForceUpdate(); - } + HoldInvalidation = true; + + foreach (GMapOverlay o in Overlays) + { + if (o.IsVisibile) + { + o.ForceUpdate(); + } + } } - } - finally - { - Refresh(); - } - } - - /// - /// render map in GDI+ - /// - /// - void DrawMap(Graphics g) - { - if(Core.updatingBounds || MapProvider == EmptyProvider.Instance || MapProvider == null) - { - Debug.WriteLine("Core.updatingBounds"); - return; - } - - Core.tileDrawingListLock.AcquireReaderLock(); - Core.Matrix.EnterReadLock(); - try - { - foreach(var tilePoint in Core.tileDrawingList) + finally { - { - Core.tileRect.Location = tilePoint.PosPixel; - if(ForceDoubleBuffer) - { + Refresh(); + } + } + + private const int bytesPerPixel = 4; + + /// + /// method for changing the opacity of an image + /// + /// image to set opacity on + /// percentage of opacity + /// + public Image SetImageOpacity(Image image, double opacity) + { + try + { + //create a Bitmap the size of the image provided + Bitmap bmp = new Bitmap(image.Width, image.Height); + + //create a graphics object from the image + using (Graphics gfx = Graphics.FromImage(bmp)) + { + + //create a color matrix object + ColorMatrix matrix = new ColorMatrix(); + + //set the opacity + matrix.Matrix33 = (float)opacity; + + //create image attributes + ImageAttributes attributes = new ImageAttributes(); + + //set the color(opacity) of the image + attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + + //now draw the image + gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); + } + return bmp; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return null; + } + } + /// + /// render map in GDI+ + /// + /// + void DrawMap(Graphics g) + { + if (Core.updatingBounds || MapProvider == EmptyProvider.Instance || MapProvider == null) + { + Debug.WriteLine("Core.updatingBounds"); + return; + } + + Core.tileDrawingListLock.AcquireReaderLock(); + Core.Matrix.EnterReadLock(); + try + { + foreach (var tilePoint in Core.tileDrawingList) + { + { + Core.tileRect.Location = tilePoint.PosPixel; + if (ForceDoubleBuffer) + { #if !PocketPC - if(MobileMode) - { - Core.tileRect.Offset(Core.renderOffset); - } + if (MobileMode) + { + Core.tileRect.Offset(Core.renderOffset); + } #else Core.tileRect.Offset(Core.renderOffset); #endif - } - Core.tileRect.OffsetNegative(Core.compensationOffset); + } + Core.tileRect.OffsetNegative(Core.compensationOffset); - //if(Core.currentRegion.IntersectsWith(Core.tileRect) || IsRotated) - { - bool found = false; - - Tile t = Core.Matrix.GetTileWithNoLock(Core.Zoom, tilePoint.PosXY); - if(t.NotEmpty) - { - // render tile + //if(Core.currentRegion.IntersectsWith(Core.tileRect) || IsRotated) { - foreach(WindowsFormsImage img in t.Overlays) - { - try - { - if (img != null && img.Img != null) + bool found = false; + + Tile t = Core.Matrix.GetTileWithNoLock(Core.Zoom, tilePoint.PosXY); + if (t.NotEmpty) + { + // render tile + { + foreach (WindowsFormsImage img in t.Overlays) { - if (!found) - found = true; - - if (!img.IsParent) + if (img != null && img.Img != null) { + if (!found) + found = true; + + if (!img.IsParent) + { #if !PocketPC - g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + // change opacity if < 1.0 + if (Opacity < 1) + { + Image im = SetImageOpacity(img.Img, Opacity); + g.DrawImage(im, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + } + else + { + g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + } #else - g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); + g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); #endif - } + } #if !PocketPC - else - { - // TODO: move calculations to loader thread - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - } + else + { + // TODO: move calculations to loader thread + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + // change opacity if < 1.0 + if (Opacity < 1) + { + Image im = SetImageOpacity(img.Img, Opacity); + g.DrawImage(im, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } + else + { + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } + } #endif + } } - } - catch (Exception ex) - { - Console.WriteLine("GMapControl: Error while drwing Image: " + ex.Message); - } - } - } - } + } + } #if !PocketPC - else if(FillEmptyTiles && MapProvider.Projection is MercatorProjection) - { - #region -- fill empty lines -- - int zoomOffset = 1; - Tile parentTile = Tile.Empty; - long Ix = 0; + else if (FillEmptyTiles && MapProvider.Projection is MercatorProjection) + { + #region -- fill empty lines -- + int zoomOffset = 1; + Tile parentTile = Tile.Empty; + long Ix = 0; - while(!parentTile.NotEmpty && zoomOffset < Core.Zoom && zoomOffset <= LevelsKeepInMemmory) - { - Ix = (long)Math.Pow(2, zoomOffset); - parentTile = Core.Matrix.GetTileWithNoLock(Core.Zoom - zoomOffset++, new GPoint((int)(tilePoint.PosXY.X / Ix), (int)(tilePoint.PosXY.Y / Ix))); - } + while (!parentTile.NotEmpty && zoomOffset < Core.Zoom && zoomOffset <= LevelsKeepInMemmory) + { + Ix = (long)Math.Pow(2, zoomOffset); + parentTile = Core.Matrix.GetTileWithNoLock(Core.Zoom - zoomOffset++, new GPoint((int)(tilePoint.PosXY.X / Ix), (int)(tilePoint.PosXY.Y / Ix))); + } - if(parentTile.NotEmpty) - { - long Xoff = Math.Abs(tilePoint.PosXY.X - (parentTile.Pos.X * Ix)); - long Yoff = Math.Abs(tilePoint.PosXY.Y - (parentTile.Pos.Y * Ix)); + if (parentTile.NotEmpty) + { + long Xoff = Math.Abs(tilePoint.PosXY.X - (parentTile.Pos.X * Ix)); + long Yoff = Math.Abs(tilePoint.PosXY.Y - (parentTile.Pos.Y * Ix)); - // render tile - { - foreach(WindowsFormsImage img in parentTile.Overlays) - { - if(img != null && img.Img != null && !img.IsParent) - { - if(!found) - found = true; + // render tile + { + foreach (WindowsFormsImage img in parentTile.Overlays) + { + if (img != null && img.Img != null && !img.IsParent) + { + if (!found) + found = true; - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - g.FillRectangle(SelectedAreaFill, dst); - } - } - } - } - #endregion - } + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + g.FillRectangle(SelectedAreaFill, dst); + } + } + } + } + #endregion + } #endif - // add text if tile is missing - if(!found) - { - lock(Core.FailedLoads) - { - var lt = new LoadTask(tilePoint.PosXY, Core.Zoom); - if(Core.FailedLoads.ContainsKey(lt)) - { - var ex = Core.FailedLoads[lt]; + // add text if tile is missing + if (!found) + { + lock (Core.FailedLoads) + { + var lt = new LoadTask(tilePoint.PosXY, Core.Zoom); + if (Core.FailedLoads.ContainsKey(lt)) + { + var ex = Core.FailedLoads[lt]; #if !PocketPC - g.FillRectangle(EmptytileBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height)); + g.FillRectangle(EmptytileBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height)); - g.DrawString("Exception: " + ex.Message, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X + 11, Core.tileRect.Y + 11, Core.tileRect.Width - 11, Core.tileRect.Height - 11)); + g.DrawString("Exception: " + ex.Message, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X + 11, Core.tileRect.Y + 11, Core.tileRect.Width - 11, Core.tileRect.Height - 11)); - g.DrawString(EmptyTileText, MissingDataFont, Brushes.Blue, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); + g.DrawString(EmptyTileText, MissingDataFont, Brushes.Blue, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #else g.FillRectangle(EmptytileBrush, new System.Drawing.Rectangle((int) Core.tileRect.X, (int) Core.tileRect.Y, (int) Core.tileRect.Width, (int) Core.tileRect.Height)); @@ -755,526 +825,526 @@ namespace GMap.NET.WindowsForms g.DrawString(EmptyTileText, MissingDataFont, TileGridMissingTextBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y + Core.tileRect.Width / 2 + (ShowTileGridLines ? 11 : -22), Core.tileRect.Width, Core.tileRect.Height), BottomFormat); #endif - g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - } - } - } + g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + } + } + } - if(ShowTileGridLines) - { - g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - { + if (ShowTileGridLines) + { + g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + { #if !PocketPC - g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "CENTER: " : "TILE: ") + tilePoint, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); + g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "CENTER: " : "TILE: ") + tilePoint, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #else g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "" : "TILE: ") + tilePoint, MissingDataFont, TileGridLinesTextBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #endif + } + } } - } - } - } + } + } } - } - finally - { - Core.Matrix.LeaveReadLock(); - Core.tileDrawingListLock.ReleaseReaderLock(); - } - } - - /// - /// updates markers local position - /// - /// - public void UpdateMarkerLocalPosition(GMapMarker marker) - { - GPoint p = FromLatLngToLocal(marker.Position); - { -#if !PocketPC - if(!MobileMode) + finally { - p.OffsetNegative(Core.renderOffset); + Core.Matrix.LeaveReadLock(); + Core.tileDrawingListLock.ReleaseReaderLock(); } + } + + /// + /// updates markers local position + /// + /// + public void UpdateMarkerLocalPosition(GMapMarker marker) + { + GPoint p = FromLatLngToLocal(marker.Position); + { +#if !PocketPC + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - var f = new System.Drawing.Point((int)(p.X + marker.Offset.X), (int)(p.Y + marker.Offset.Y)); - marker.LocalPosition = f; - } - } + var f = new System.Drawing.Point((int)(p.X + marker.Offset.X), (int)(p.Y + marker.Offset.Y)); + marker.LocalPosition = f; + } + } - /// - /// updates routes local position - /// - /// - public void UpdateRouteLocalPosition(GMapRoute route) - { - route.LocalPoints.Clear(); + /// + /// updates routes local position + /// + /// + public void UpdateRouteLocalPosition(GMapRoute route) + { + route.LocalPoints.Clear(); - foreach(GMap.NET.PointLatLng pg in route.Points) - { - GPoint p = FromLatLngToLocal(pg); + foreach (GMap.NET.PointLatLng pg in route.Points) + { + GPoint p = FromLatLngToLocal(pg); #if !PocketPC - if(!MobileMode) - { - p.OffsetNegative(Core.renderOffset); - } + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - // if(IsRotated) - // { - //#if !PocketPC - // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; - // rotationMatrix.TransformPoints(tt); - // var f = tt[0]; + // if(IsRotated) + // { + //#if !PocketPC + // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; + // rotationMatrix.TransformPoints(tt); + // var f = tt[0]; - // p.X = f.X; - // p.Y = f.Y; - //#endif - // } + // p.X = f.X; + // p.Y = f.Y; + //#endif + // } - route.LocalPoints.Add(p); - } -#if !PocketPC - route.UpdateGraphicsPath(); -#endif - } - - /// - /// updates polygons local position - /// - /// - public void UpdatePolygonLocalPosition(GMapPolygon polygon) - { - polygon.LocalPoints.Clear(); - - foreach(GMap.NET.PointLatLng pg in polygon.Points) - { - GPoint p = FromLatLngToLocal(pg); - -#if !PocketPC - if(!MobileMode) - { - p.OffsetNegative(Core.renderOffset); + route.LocalPoints.Add(p); } +#if !PocketPC + route.UpdateGraphicsPath(); +#endif + } + + /// + /// updates polygons local position + /// + /// + public void UpdatePolygonLocalPosition(GMapPolygon polygon) + { + polygon.LocalPoints.Clear(); + + foreach (GMap.NET.PointLatLng pg in polygon.Points) + { + GPoint p = FromLatLngToLocal(pg); + +#if !PocketPC + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - // if(IsRotated) - // { - //#if !PocketPC - // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; - // rotationMatrix.TransformPoints(tt); - // var f = tt[0]; + // if(IsRotated) + // { + //#if !PocketPC + // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; + // rotationMatrix.TransformPoints(tt); + // var f = tt[0]; - // p.X = f.X; - // p.Y = f.Y; - //#endif - // } + // p.X = f.X; + // p.Y = f.Y; + //#endif + // } - polygon.LocalPoints.Add(p); - } - } - - /// - /// sets zoom to max to fit rect - /// - /// - /// - public bool SetZoomToFitRect(RectLatLng rect) - { - if(lazyEvents) - { - lazySetZoomToFitRect = rect; - } - else - { - int maxZoom = Core.GetMaxZoomToFitRect(rect); - if(maxZoom > 0) - { - PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2)); - Position = center; - - if(maxZoom > MaxZoom) - { - maxZoom = MaxZoom; - } - - if((int)Zoom != maxZoom) - { - Zoom = maxZoom; - } - - return true; + polygon.LocalPoints.Add(p); } - } + } - return false; - } - - RectLatLng? lazySetZoomToFitRect = null; - bool lazyEvents = true; - - /// - /// sets to max zoom to fit all markers and centers them in map - /// - /// overlay id or null to check all - /// - public bool ZoomAndCenterMarkers(string overlayId) - { - RectLatLng? rect = GetRectOfAllMarkers(overlayId); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// zooms and centers all route - /// - /// overlay id or null to check all - /// - public bool ZoomAndCenterRoutes(string overlayId) - { - RectLatLng? rect = GetRectOfAllRoutes(overlayId); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// zooms and centers route - /// - /// - /// - public bool ZoomAndCenterRoute(MapRoute route) - { - RectLatLng? rect = GetRectOfRoute(route); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// gets rectangle with all objects inside - /// - /// overlay id or null to check all - /// - public RectLatLng? GetRectOfAllMarkers(string overlayId) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - foreach(GMapOverlay o in Overlays) - { - if(overlayId == null || o.Id == overlayId) + /// + /// sets zoom to max to fit rect + /// + /// + /// + public bool SetZoomToFitRect(RectLatLng rect) + { + if (lazyEvents) { - if(o.IsVisibile && o.Markers.Count > 0) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible) - { - // left - if(m.Position.Lng < left) - { - left = m.Position.Lng; - } - - // top - if(m.Position.Lat > top) - { - top = m.Position.Lat; - } - - // right - if(m.Position.Lng > right) - { - right = m.Position.Lng; - } - - // bottom - if(m.Position.Lat < bottom) - { - bottom = m.Position.Lat; - } - } - } - } - } - } - - if(left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) - { - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - - return ret; - } - - /// - /// gets rectangle with all objects inside - /// - /// overlay id or null to check all - /// - public RectLatLng? GetRectOfAllRoutes(string overlayId) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - foreach(GMapOverlay o in Overlays) - { - if(overlayId == null || o.Id == overlayId) - { - if(o.IsVisibile && o.Routes.Count > 0) - { - foreach(GMapRoute route in o.Routes) - { - if(route.IsVisible && route.From.HasValue && route.To.HasValue) - { - foreach(PointLatLng p in route.Points) - { - // left - if(p.Lng < left) - { - left = p.Lng; - } - - // top - if(p.Lat > top) - { - top = p.Lat; - } - - // right - if(p.Lng > right) - { - right = p.Lng; - } - - // bottom - if(p.Lat < bottom) - { - bottom = p.Lat; - } - } - } - } - } - } - } - - if(left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) - { - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - - return ret; - } - - /// - /// gets rect of route - /// - /// - /// - public RectLatLng? GetRectOfRoute(MapRoute route) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - if(route.From.HasValue && route.To.HasValue) - { - foreach(PointLatLng p in route.Points) - { - // left - if(p.Lng < left) - { - left = p.Lng; - } - - // top - if(p.Lat > top) - { - top = p.Lat; - } - - // right - if(p.Lng > right) - { - right = p.Lng; - } - - // bottom - if(p.Lat < bottom) - { - bottom = p.Lat; - } - } - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - return ret; - } - -#if !PocketPC - /// - /// gets image of the current view - /// - /// - public Image ToImage() - { - Image ret = null; - try - { - using(Bitmap bitmap = new Bitmap(Width, Height)) - { - using(Graphics g = Graphics.FromImage(bitmap)) - { - using(Graphics gg = this.CreateGraphics()) - { -#if !PocketPC - g.CopyFromScreen(PointToScreen(new System.Drawing.Point()).X, PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(Width, Height)); -#else - throw new NotImplementedException("Not implemeted for PocketPC"); -#endif - } - } - - // Convert the Image to a png - using(MemoryStream ms = new MemoryStream()) - { - bitmap.Save(ms, ImageFormat.Png); -#if !PocketPC - ret = Image.FromStream(ms); -#else - throw new NotImplementedException("Not implemeted for PocketPC"); -#endif - } - } - } - catch - { - ret = null; - } - return ret; - } -#endif - - /// - /// offset position in pixels - /// - /// - /// - public void Offset(int x, int y) - { - if(IsHandleCreated) - { - // need to fix in rotated mode usinf rotationMatrix - // ... - Core.DragOffset(new GPoint(x, y)); - - ForceUpdateOverlays(); - } - } - - #region UserControl Events - -#if !PocketPC - protected bool DesignModeInConstruct - { - get - { - return (LicenseManager.UsageMode == LicenseUsageMode.Designtime); - } - } - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsDesignerHosted - { - get - { - return IsControlDesignerHosted(this); - } - } - - public bool IsControlDesignerHosted(Control ctrl) - { - if(ctrl != null) - { - if(ctrl.Site != null) - { - - if(ctrl.Site.DesignMode == true) - return true; - - else - { - if(IsControlDesignerHosted(ctrl.Parent)) - return true; - - else - return false; - } + lazySetZoomToFitRect = rect; } else { - if(IsControlDesignerHosted(ctrl.Parent)) - return true; - else - return false; + int maxZoom = Core.GetMaxZoomToFitRect(rect); + if (maxZoom > 0) + { + PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2)); + Position = center; + + if (maxZoom > MaxZoom) + { + maxZoom = MaxZoom; + } + + if ((int)Zoom != maxZoom) + { + Zoom = maxZoom; + } + + return true; + } } - } - else + return false; - } + } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); + RectLatLng? lazySetZoomToFitRect = null; + bool lazyEvents = true; - if(!IsDesignerHosted) - { - //MethodInvoker m = delegate - //{ - // Thread.Sleep(444); - - //OnSizeChanged(null); - - if(lazyEvents) + /// + /// sets to max zoom to fit all markers and centers them in map + /// + /// overlay id or null to check all + /// + public bool ZoomAndCenterMarkers(string overlayId) + { + RectLatLng? rect = GetRectOfAllMarkers(overlayId); + if (rect.HasValue) { - lazyEvents = false; - - if(lazySetZoomToFitRect.HasValue) - { - SetZoomToFitRect(lazySetZoomToFitRect.Value); - lazySetZoomToFitRect = null; - } + return SetZoomToFitRect(rect.Value); } - Core.OnMapOpen().ProgressChanged += new ProgressChangedEventHandler(invalidatorEngage); - ForceUpdateOverlays(); - //}; - //this.BeginInvoke(m); - } - } + + return false; + } + + /// + /// zooms and centers all route + /// + /// overlay id or null to check all + /// + public bool ZoomAndCenterRoutes(string overlayId) + { + RectLatLng? rect = GetRectOfAllRoutes(overlayId); + if (rect.HasValue) + { + return SetZoomToFitRect(rect.Value); + } + + return false; + } + + /// + /// zooms and centers route + /// + /// + /// + public bool ZoomAndCenterRoute(MapRoute route) + { + RectLatLng? rect = GetRectOfRoute(route); + if (rect.HasValue) + { + return SetZoomToFitRect(rect.Value); + } + + return false; + } + + /// + /// gets rectangle with all objects inside + /// + /// overlay id or null to check all + /// + public RectLatLng? GetRectOfAllMarkers(string overlayId) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + foreach (GMapOverlay o in Overlays) + { + if (overlayId == null || o.Id == overlayId) + { + if (o.IsVisibile && o.Markers.Count > 0) + { + foreach (GMapMarker m in o.Markers) + { + if (m.IsVisible) + { + // left + if (m.Position.Lng < left) + { + left = m.Position.Lng; + } + + // top + if (m.Position.Lat > top) + { + top = m.Position.Lat; + } + + // right + if (m.Position.Lng > right) + { + right = m.Position.Lng; + } + + // bottom + if (m.Position.Lat < bottom) + { + bottom = m.Position.Lat; + } + } + } + } + } + } + + if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) + { + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + + return ret; + } + + /// + /// gets rectangle with all objects inside + /// + /// overlay id or null to check all + /// + public RectLatLng? GetRectOfAllRoutes(string overlayId) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + foreach (GMapOverlay o in Overlays) + { + if (overlayId == null || o.Id == overlayId) + { + if (o.IsVisibile && o.Routes.Count > 0) + { + foreach (GMapRoute route in o.Routes) + { + if (route.IsVisible && route.From.HasValue && route.To.HasValue) + { + foreach (PointLatLng p in route.Points) + { + // left + if (p.Lng < left) + { + left = p.Lng; + } + + // top + if (p.Lat > top) + { + top = p.Lat; + } + + // right + if (p.Lng > right) + { + right = p.Lng; + } + + // bottom + if (p.Lat < bottom) + { + bottom = p.Lat; + } + } + } + } + } + } + } + + if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) + { + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + + return ret; + } + + /// + /// gets rect of route + /// + /// + /// + public RectLatLng? GetRectOfRoute(MapRoute route) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + if (route.From.HasValue && route.To.HasValue) + { + foreach (PointLatLng p in route.Points) + { + // left + if (p.Lng < left) + { + left = p.Lng; + } + + // top + if (p.Lat > top) + { + top = p.Lat; + } + + // right + if (p.Lng > right) + { + right = p.Lng; + } + + // bottom + if (p.Lat < bottom) + { + bottom = p.Lat; + } + } + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + return ret; + } + +#if !PocketPC + /// + /// gets image of the current view + /// + /// + public Image ToImage() + { + Image ret = null; + try + { + using (Bitmap bitmap = new Bitmap(Width, Height)) + { + using (Graphics g = Graphics.FromImage(bitmap)) + { + using (Graphics gg = this.CreateGraphics()) + { +#if !PocketPC + g.CopyFromScreen(PointToScreen(new System.Drawing.Point()).X, PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(Width, Height)); +#else + throw new NotImplementedException("Not implemeted for PocketPC"); +#endif + } + } + + // Convert the Image to a png + using (MemoryStream ms = new MemoryStream()) + { + bitmap.Save(ms, ImageFormat.Png); +#if !PocketPC + ret = Image.FromStream(ms); +#else + throw new NotImplementedException("Not implemeted for PocketPC"); +#endif + } + } + } + catch + { + ret = null; + } + return ret; + } +#endif + + /// + /// offset position in pixels + /// + /// + /// + public void Offset(int x, int y) + { + if (IsHandleCreated) + { + // need to fix in rotated mode usinf rotationMatrix + // ... + Core.DragOffset(new GPoint(x, y)); + + ForceUpdateOverlays(); + } + } + + #region UserControl Events + +#if !PocketPC + protected bool DesignModeInConstruct + { + get + { + return (LicenseManager.UsageMode == LicenseUsageMode.Designtime); + } + } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsDesignerHosted + { + get + { + return IsControlDesignerHosted(this); + } + } + + public bool IsControlDesignerHosted(Control ctrl) + { + if (ctrl != null) + { + if (ctrl.Site != null) + { + + if (ctrl.Site.DesignMode == true) + return true; + + else + { + if (IsControlDesignerHosted(ctrl.Parent)) + return true; + + else + return false; + } + } + else + { + if (IsControlDesignerHosted(ctrl.Parent)) + return true; + else + return false; + } + } + else + return false; + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + if (!IsDesignerHosted) + { + //MethodInvoker m = delegate + //{ + // Thread.Sleep(444); + + //OnSizeChanged(null); + + if (lazyEvents) + { + lazyEvents = false; + + if (lazySetZoomToFitRect.HasValue) + { + SetZoomToFitRect(lazySetZoomToFitRect.Value); + lazySetZoomToFitRect = null; + } + } + Core.OnMapOpen().ProgressChanged += new ProgressChangedEventHandler(invalidatorEngage); + ForceUpdateOverlays(); + //}; + //this.BeginInvoke(m); + } + } #else //delegate void MethodInvoker(); bool IsHandleCreated = false; @@ -1303,1852 +1373,1852 @@ namespace GMap.NET.WindowsForms #endif #if !PocketPC - protected override void OnCreateControl() - { - base.OnCreateControl(); + protected override void OnCreateControl() + { + base.OnCreateControl(); - var f = ParentForm; - if(f != null) - { - while(f.ParentForm != null) + var f = ParentForm; + if (f != null) { - f = f.ParentForm; - } + while (f.ParentForm != null) + { + f = f.ParentForm; + } - if(f != null) + if (f != null) + { + f.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); + } + } + } + + void ParentForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) { - f.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); + Manager.CancelTileCaching(); } - } - } - - void ParentForm_FormClosing(object sender, FormClosingEventArgs e) - { - if(e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) - { - Manager.CancelTileCaching(); - } - } + } #endif - protected override void Dispose(bool disposing) - { - if(disposing) - { - Core.OnMapClose(); - - Overlays.CollectionChanged -= new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); - - foreach(var o in Overlays) + protected override void Dispose(bool disposing) + { + if (disposing) { - o.Dispose(); - } - Overlays.Clear(); + Core.OnMapClose(); - if (ScaleFont != null) - ScaleFont.Dispose(); - if (ScalePen != null) - ScalePen.Dispose(); - CenterFormat.Dispose(); - CenterPen.Dispose(); - BottomFormat.Dispose(); - CopyrightFont.Dispose(); - EmptyTileBorders.Dispose(); - EmptytileBrush.Dispose(); + Overlays.CollectionChanged -= new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); + + foreach (var o in Overlays) + { + o.Dispose(); + } + Overlays.Clear(); + + if (ScaleFont != null) + ScaleFont.Dispose(); + if (ScalePen != null) + ScalePen.Dispose(); + CenterFormat.Dispose(); + CenterPen.Dispose(); + BottomFormat.Dispose(); + CopyrightFont.Dispose(); + EmptyTileBorders.Dispose(); + EmptytileBrush.Dispose(); #if !PocketPC - SelectedAreaFill.Dispose(); - if (SelectionPen != null) - SelectionPen.Dispose(); + SelectedAreaFill.Dispose(); + if (SelectionPen != null) + SelectionPen.Dispose(); #endif - if(backBuffer != null) - { - backBuffer.Dispose(); - backBuffer = null; - } + if (backBuffer != null) + { + backBuffer.Dispose(); + backBuffer = null; + } - if(gxOff != null) - { - gxOff.Dispose(); - gxOff = null; + if (gxOff != null) + { + gxOff.Dispose(); + gxOff = null; + } } - } - base.Dispose(disposing); - } + base.Dispose(disposing); + } - PointLatLng selectionStart; - PointLatLng selectionEnd; + PointLatLng selectionStart; + PointLatLng selectionEnd; #if !PocketPC - float? MapRenderTransform = null; + float? MapRenderTransform = null; #endif - public Color EmptyMapBackground = Color.WhiteSmoke; + public Color EmptyMapBackground = Color.WhiteSmoke; #if !DESIGN - protected override void OnPaint(PaintEventArgs e) - { - if(ForceDoubleBuffer) - { - #region -- manual buffer -- - if(gxOff != null && backBuffer != null) + protected override void OnPaint(PaintEventArgs e) + { + if (ForceDoubleBuffer) { - // render white background - gxOff.Clear(EmptyMapBackground); + #region -- manual buffer -- + if (gxOff != null && backBuffer != null) + { + // render white background + gxOff.Clear(EmptyMapBackground); #if !PocketPC - if(MapRenderTransform.HasValue) - { - gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - gxOff.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value); - { - DrawMap(gxOff); - OnPaintOverlays(gxOff); - } - } - else + if (MapRenderTransform.HasValue) + { + gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + gxOff.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value); + { + DrawMap(gxOff); + OnPaintOverlays(gxOff); + } + } + else #endif - { + { #if !PocketPC - if(!MobileMode) - { - gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - } + if (!MobileMode) + { + gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + } #endif - DrawMap(gxOff); - } + DrawMap(gxOff); + } - OnPaintOverlays(gxOff); + OnPaintOverlays(gxOff); - e.Graphics.DrawImage(backBuffer, 0, 0); - } - #endregion - } - else - { - e.Graphics.Clear(EmptyMapBackground); - -#if !PocketPC - if(MapRenderTransform.HasValue) - { - if(!MobileMode) - { - var pc = new GPoint(Width / 2, Height / 2); - var pc2 = pc; - pc.OffsetNegative(Core.renderOffset); - pc2.OffsetNegative(pc); - - e.Graphics.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value, MatrixOrder.Append); - - e.Graphics.TranslateTransform(pc2.X, pc2.Y, MatrixOrder.Append); - } - - { - DrawMap(e.Graphics); - - e.Graphics.ResetTransform(); - if(!MobileMode) - { - var pc = Core.renderOffset; - pc.OffsetNegative(new GPoint(Width / 2, Height / 2)); - e.Graphics.TranslateTransform(Core.renderOffset.X + -pc.X, Core.renderOffset.Y + -pc.Y); - } - - OnPaintOverlays(e.Graphics); - } + e.Graphics.DrawImage(backBuffer, 0, 0); + } + #endregion } else -#endif { + e.Graphics.Clear(EmptyMapBackground); + #if !PocketPC - if(IsRotated) - { - #region -- rotation -- + if (MapRenderTransform.HasValue) + { + if (!MobileMode) + { + var pc = new GPoint(Width / 2, Height / 2); + var pc2 = pc; + pc.OffsetNegative(Core.renderOffset); + pc2.OffsetNegative(pc); - e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value, MatrixOrder.Append); - e.Graphics.TranslateTransform((float)(Core.Width / 2.0), (float)(Core.Height / 2.0)); - e.Graphics.RotateTransform(-Bearing); - e.Graphics.TranslateTransform((float)(-Core.Width / 2.0), (float)(-Core.Height / 2.0)); + e.Graphics.TranslateTransform(pc2.X, pc2.Y, MatrixOrder.Append); + } - e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + { + DrawMap(e.Graphics); - DrawMap(e.Graphics); - OnPaintOverlays(e.Graphics); + e.Graphics.ResetTransform(); + if (!MobileMode) + { + var pc = Core.renderOffset; + pc.OffsetNegative(new GPoint(Width / 2, Height / 2)); + e.Graphics.TranslateTransform(Core.renderOffset.X + -pc.X, Core.renderOffset.Y + -pc.Y); + } - #endregion - } - else + OnPaintOverlays(e.Graphics); + } + } + else #endif - { + { #if !PocketPC - if(!MobileMode) - { - e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - } + if (IsRotated) + { + #region -- rotation -- + + e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + + e.Graphics.TranslateTransform((float)(Core.Width / 2.0), (float)(Core.Height / 2.0)); + e.Graphics.RotateTransform(-Bearing); + e.Graphics.TranslateTransform((float)(-Core.Width / 2.0), (float)(-Core.Height / 2.0)); + + e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + + DrawMap(e.Graphics); + OnPaintOverlays(e.Graphics); + + #endregion + } + else #endif - DrawMap(e.Graphics); - OnPaintOverlays(e.Graphics); - } + { +#if !PocketPC + if (!MobileMode) + { + e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + } +#endif + DrawMap(e.Graphics); + OnPaintOverlays(e.Graphics); + } + } } - } - base.OnPaint(e); - } + base.OnPaint(e); + } #endif #if !PocketPC - readonly Matrix rotationMatrix = new Matrix(); - readonly Matrix rotationMatrixInvert = new Matrix(); + readonly Matrix rotationMatrix = new Matrix(); + readonly Matrix rotationMatrixInvert = new Matrix(); - /// - /// updates rotation matrix - /// - void UpdateRotationMatrix() - { - PointF center = new PointF(Core.Width / 2, Core.Height / 2); + /// + /// updates rotation matrix + /// + void UpdateRotationMatrix() + { + PointF center = new PointF(Core.Width / 2, Core.Height / 2); - rotationMatrix.Reset(); - rotationMatrix.RotateAt(-Bearing, center); + rotationMatrix.Reset(); + rotationMatrix.RotateAt(-Bearing, center); - rotationMatrixInvert.Reset(); - rotationMatrixInvert.RotateAt(-Bearing, center); - rotationMatrixInvert.Invert(); - } + rotationMatrixInvert.Reset(); + rotationMatrixInvert.RotateAt(-Bearing, center); + rotationMatrixInvert.Invert(); + } - /// - /// returs true if map bearing is not zero - /// - [Browsable(false)] - public bool IsRotated - { - get - { - return Core.IsRotated; - } - } - - /// - /// bearing for rotation of the map - /// - [Category("GMap.NET")] - public float Bearing - { - get - { - return Core.bearing; - } - set - { - //if(Core.bearing != value) - //{ - // bool resize = Core.bearing == 0; - // Core.bearing = value; - - // //if(VirtualSizeEnabled) - // //{ - // // c.X += (Width - Core.vWidth) / 2; - // // c.Y += (Height - Core.vHeight) / 2; - // //} - - // UpdateRotationMatrix(); - - // if(value != 0 && value % 360 != 0) - // { - // Core.IsRotated = true; - - // if(Core.tileRectBearing.Size == Core.tileRect.Size) - // { - // Core.tileRectBearing = Core.tileRect; - // Core.tileRectBearing.Inflate(1, 1); - // } - // } - // else - // { - // Core.IsRotated = false; - // Core.tileRectBearing = Core.tileRect; - // } - - // if(resize) - // { - // Core.OnMapSizeChanged(Width, Height); - // } - - // if(!HoldInvalidation && Core.IsStarted) - // { - // ForceUpdateOverlays(); - // } - //} - } - } -#endif - - /// - /// override, to render something more - /// - /// - protected virtual void OnPaintOverlays(Graphics g) - { -#if !PocketPC - g.SmoothingMode = SmoothingMode.HighQuality; -#endif - foreach(GMapOverlay o in Overlays) - { - if(o.IsVisibile) + /// + /// returs true if map bearing is not zero + /// + [Browsable(false)] + public bool IsRotated + { + get { - o.OnRender(g); + return Core.IsRotated; } - } + } - // center in virtual spcace... + /// + /// bearing for rotation of the map + /// + [Category("GMap.NET")] + public float Bearing + { + get + { + return Core.bearing; + } + set + { + //if(Core.bearing != value) + //{ + // bool resize = Core.bearing == 0; + // Core.bearing = value; + + // //if(VirtualSizeEnabled) + // //{ + // // c.X += (Width - Core.vWidth) / 2; + // // c.Y += (Height - Core.vHeight) / 2; + // //} + + // UpdateRotationMatrix(); + + // if(value != 0 && value % 360 != 0) + // { + // Core.IsRotated = true; + + // if(Core.tileRectBearing.Size == Core.tileRect.Size) + // { + // Core.tileRectBearing = Core.tileRect; + // Core.tileRectBearing.Inflate(1, 1); + // } + // } + // else + // { + // Core.IsRotated = false; + // Core.tileRectBearing = Core.tileRect; + // } + + // if(resize) + // { + // Core.OnMapSizeChanged(Width, Height); + // } + + // if(!HoldInvalidation && Core.IsStarted) + // { + // ForceUpdateOverlays(); + // } + //} + } + } +#endif + + /// + /// override, to render something more + /// + /// + protected virtual void OnPaintOverlays(Graphics g) + { +#if !PocketPC + g.SmoothingMode = SmoothingMode.HighQuality; +#endif + foreach (GMapOverlay o in Overlays) + { + if (o.IsVisibile) + { + o.OnRender(g); + } + } + + // center in virtual spcace... #if DEBUG - g.DrawLine(ScalePen, -20, 0, 20, 0); - g.DrawLine(ScalePen, 0, -20, 0, 20); + g.DrawLine(ScalePen, -20, 0, 20, 0); + g.DrawLine(ScalePen, 0, -20, 0, 20); #if PocketPC g.DrawString("debug build", CopyrightFont, CopyrightBrush, 2, CopyrightFont.Size); #else -// g.DrawString("debug build", CopyrightFont, Brushes.Blue, 2, CopyrightFont.Height); + // g.DrawString("debug build", CopyrightFont, Brushes.Blue, 2, CopyrightFont.Height); #endif #endif #if !PocketPC - if(!MobileMode) - { - g.ResetTransform(); - } + if (!MobileMode) + { + g.ResetTransform(); + } - if(!SelectedArea.IsEmpty) - { - GPoint p1 = FromLatLngToLocal(SelectedArea.LocationTopLeft); - GPoint p2 = FromLatLngToLocal(SelectedArea.LocationRightBottom); + if (!SelectedArea.IsEmpty) + { + GPoint p1 = FromLatLngToLocal(SelectedArea.LocationTopLeft); + GPoint p2 = FromLatLngToLocal(SelectedArea.LocationRightBottom); - long x1 = p1.X; - long y1 = p1.Y; - long x2 = p2.X; - long y2 = p2.Y; + long x1 = p1.X; + long y1 = p1.Y; + long x2 = p2.X; + long y2 = p2.Y; - g.DrawRectangle(SelectionPen, x1, y1, x2 - x1, y2 - y1); - g.FillRectangle(SelectedAreaFill, x1, y1, x2 - x1, y2 - y1); - } + g.DrawRectangle(SelectionPen, x1, y1, x2 - x1, y2 - y1); + g.FillRectangle(SelectedAreaFill, x1, y1, x2 - x1, y2 - y1); + } #endif - if(ShowCenter) - { - g.DrawLine(CenterPen, Width / 2 - 5, Height / 2, Width / 2 + 5, Height / 2); - g.DrawLine(CenterPen, Width / 2, Height / 2 - 5, Width / 2, Height / 2 + 5); - } + if (ShowCenter) + { + g.DrawLine(CenterPen, Width / 2 - 5, Height / 2, Width / 2 + 5, Height / 2); + g.DrawLine(CenterPen, Width / 2, Height / 2 - 5, Width / 2, Height / 2 + 5); + } - if(renderHelperLine) - { - var p = PointToClient(Form.MousePosition); + if (renderHelperLine) + { + var p = PointToClient(Form.MousePosition); - g.DrawLine(HelperLinePen, p.X, 0, p.X, Height); - g.DrawLine(HelperLinePen, 0, p.Y, Width, p.Y); - } + g.DrawLine(HelperLinePen, p.X, 0, p.X, Height); + g.DrawLine(HelperLinePen, 0, p.Y, Width, p.Y); + } - #region -- copyright -- + #region -- copyright -- - if(!string.IsNullOrEmpty(Core.provider.Copyright)) - { + if (!string.IsNullOrEmpty(Core.provider.Copyright)) + { #if !PocketPC - g.DrawString(Core.provider.Copyright, CopyrightFont, Brushes.Navy, 3, Height - CopyrightFont.Height - 5); + g.DrawString(Core.provider.Copyright, CopyrightFont, Brushes.Navy, 3, Height - CopyrightFont.Height - 5); #else g.DrawString(Core.provider.Copyright, CopyrightFont, CopyrightBrush, 3, Height - CopyrightFont.Size - 15); #endif - } + } - #endregion + #endregion - #region -- draw scale -- + #region -- draw scale -- #if !PocketPC - if(MapScaleInfoEnabled) - { - /* - if(Width > Core.pxRes5000km) + if (MapScaleInfoEnabled) { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes5000km, 10); - g.DrawString("5000Km", ScaleFont, Brushes.Blue, Core.pxRes5000km + 10, 11); + /* + if(Width > Core.pxRes5000km) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes5000km, 10); + g.DrawString("5000Km", ScaleFont, Brushes.Blue, Core.pxRes5000km + 10, 11); + } + if(Width > Core.pxRes1000km) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000km, 10); + g.DrawString("1000Km", ScaleFont, Brushes.Blue, Core.pxRes1000km + 10, 11); + } + if(Width > Core.pxRes100km && Zoom > 2) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100km, 10); + g.DrawString("100Km", ScaleFont, Brushes.Blue, Core.pxRes100km + 10, 11); + } + if(Width > Core.pxRes10km && Zoom > 5) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes10km, 10); + g.DrawString("10Km", ScaleFont, Brushes.Blue, Core.pxRes10km + 10, 11); + } + if(Width > Core.pxRes1000m && Zoom >= 10) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000m, 10); + g.DrawString("1000m", ScaleFont, Brushes.Blue, Core.pxRes1000m + 10, 11); + } + if(Width > Core.pxRes100m && Zoom > 11) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100m, 10); + g.DrawString("100m", ScaleFont, Brushes.Blue, Core.pxRes100m + 9, 11); + } + */ + // Darstellung ScaleInfo geändert 21.11.2012 + if ((Core.pxRes5000km > 0) && (Width > Core.pxRes5000km)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes5000km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes5000km + 10, 10, Core.pxRes5000km + 10, 20); + g.DrawString("5000Km", ScaleFont, Brushes.Black, Core.pxRes5000km - 40, 13); + } + if ((Core.pxRes1000km > 0) && (Width > Core.pxRes1000km)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes1000km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes1000km + 10, 10, Core.pxRes1000km + 10, 20); + g.DrawString("1000Km", ScaleFont, Brushes.Black, Core.pxRes1000km - 40, 13); + } + if ((Core.pxRes100km > 0) && (Width > Core.pxRes100km) && (Zoom > 5)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes100km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes100km + 10, 10, Core.pxRes100km + 10, 20); + g.DrawString("100Km", ScaleFont, Brushes.Black, Core.pxRes100km - 35, 13); + } + if ((Core.pxRes10km > 0) && (Width > Core.pxRes10km) && (Zoom > 8)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes10km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes10km + 10, 10, Core.pxRes10km + 10, 20); + g.DrawString("10Km", ScaleFont, Brushes.Black, Core.pxRes10km - 30, 13); + } + if ((Core.pxRes1000m > 0) && (Width > Core.pxRes1000m) && (Zoom >= 12)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes1000m + 10, 10); + g.DrawLine(ScalePen, Core.pxRes1000m + 10, 10, Core.pxRes1000m + 10, 20); + g.DrawString("1km", ScaleFont, Brushes.Black, Core.pxRes1000m - 25, 13); + } + if ((Core.pxRes100m > 0) && (Width > Core.pxRes100m) && (Zoom > 14)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes100m + 10, 10); + g.DrawLine(ScalePen, Core.pxRes100m + 10, 10, Core.pxRes100m + 10, 20); + g.DrawString("100m", ScaleFont, Brushes.Black, Core.pxRes100m - 30, 13); + } } - if(Width > Core.pxRes1000km) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000km, 10); - g.DrawString("1000Km", ScaleFont, Brushes.Blue, Core.pxRes1000km + 10, 11); - } - if(Width > Core.pxRes100km && Zoom > 2) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100km, 10); - g.DrawString("100Km", ScaleFont, Brushes.Blue, Core.pxRes100km + 10, 11); - } - if(Width > Core.pxRes10km && Zoom > 5) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes10km, 10); - g.DrawString("10Km", ScaleFont, Brushes.Blue, Core.pxRes10km + 10, 11); - } - if(Width > Core.pxRes1000m && Zoom >= 10) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000m, 10); - g.DrawString("1000m", ScaleFont, Brushes.Blue, Core.pxRes1000m + 10, 11); - } - if(Width > Core.pxRes100m && Zoom > 11) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100m, 10); - g.DrawString("100m", ScaleFont, Brushes.Blue, Core.pxRes100m + 9, 11); - } - */ - // Darstellung ScaleInfo geändert 21.11.2012 - if((Core.pxRes5000km > 0) && (Width > Core.pxRes5000km)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes5000km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes5000km + 10, 10, Core.pxRes5000km + 10, 20); - g.DrawString("5000Km", ScaleFont, Brushes.Black, Core.pxRes5000km - 40, 13); - } - if((Core.pxRes1000km > 0) && (Width > Core.pxRes1000km)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes1000km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes1000km + 10, 10, Core.pxRes1000km + 10, 20); - g.DrawString("1000Km", ScaleFont, Brushes.Black, Core.pxRes1000km - 40, 13); - } - if((Core.pxRes100km > 0) && (Width > Core.pxRes100km) && (Zoom > 5)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes100km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes100km + 10, 10, Core.pxRes100km + 10, 20); - g.DrawString("100Km", ScaleFont, Brushes.Black, Core.pxRes100km - 35, 13); - } - if((Core.pxRes10km > 0) && (Width > Core.pxRes10km) && (Zoom > 8)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes10km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes10km + 10, 10, Core.pxRes10km + 10, 20); - g.DrawString("10Km", ScaleFont, Brushes.Black, Core.pxRes10km - 30, 13); - } - if((Core.pxRes1000m > 0) && (Width > Core.pxRes1000m) && (Zoom >= 12)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes1000m + 10, 10); - g.DrawLine(ScalePen, Core.pxRes1000m + 10, 10, Core.pxRes1000m + 10, 20); - g.DrawString("1km", ScaleFont, Brushes.Black, Core.pxRes1000m - 25, 13); - } - if((Core.pxRes100m > 0) && (Width > Core.pxRes100m) && (Zoom > 14) ) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes100m+10, 10); - g.DrawLine(ScalePen, Core.pxRes100m + 10, 10, Core.pxRes100m + 10, 20); - g.DrawString("100m", ScaleFont, Brushes.Black, Core.pxRes100m -30, 13); - } - } #endif - #endregion - } + #endregion + } #if !PocketPC - /// - /// shrinks map area, useful just for testing - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool VirtualSizeEnabled - { - get - { - return Core.VirtualSizeEnabled; - } - set - { - Core.VirtualSizeEnabled = value; - } - } + /// + /// shrinks map area, useful just for testing + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool VirtualSizeEnabled + { + get + { + return Core.VirtualSizeEnabled; + } + set + { + Core.VirtualSizeEnabled = value; + } + } - protected override void OnSizeChanged(EventArgs e) - { - base.OnSizeChanged(e); + protected override void OnSizeChanged(EventArgs e) + { + base.OnSizeChanged(e); #else protected override void OnResize(EventArgs e) { base.OnResize(e); #endif - if(Width == 0 || Height == 0) - { - Debug.WriteLine("minimized"); - return; - } - - if(Width == Core.Width && Height == Core.Height) - { - Debug.WriteLine("maximized"); - return; - } - -#if !PocketPC - if(!IsDesignerHosted && !DesignModeInConstruct) -#endif - { - if(ForceDoubleBuffer) + if (Width == 0 || Height == 0) { - if(backBuffer != null) - { - backBuffer.Dispose(); - backBuffer = null; - } - if(gxOff != null) - { - gxOff.Dispose(); - gxOff = null; - } + Debug.WriteLine("minimized"); + return; + } - backBuffer = new Bitmap(Width, Height); - gxOff = Graphics.FromImage(backBuffer); + if (Width == Core.Width && Height == Core.Height) + { + Debug.WriteLine("maximized"); + return; } #if !PocketPC - if(VirtualSizeEnabled) - { - Core.OnMapSizeChanged(Core.vWidth, Core.vHeight); - } - else + if (!IsDesignerHosted && !DesignModeInConstruct) #endif { - Core.OnMapSizeChanged(Width, Height); - } - //Core.currentRegion = new GRect(-50, -50, Core.Width + 50, Core.Height + 50); + if (ForceDoubleBuffer) + { + if (backBuffer != null) + { + backBuffer.Dispose(); + backBuffer = null; + } + if (gxOff != null) + { + gxOff.Dispose(); + gxOff = null; + } - if(Visible && IsHandleCreated && Core.IsStarted) + backBuffer = new Bitmap(Width, Height); + gxOff = Graphics.FromImage(backBuffer); + } + +#if !PocketPC + if (VirtualSizeEnabled) + { + Core.OnMapSizeChanged(Core.vWidth, Core.vHeight); + } + else +#endif + { + Core.OnMapSizeChanged(Width, Height); + } + //Core.currentRegion = new GRect(-50, -50, Core.Width + 50, Core.Height + 50); + + if (Visible && IsHandleCreated && Core.IsStarted) + { +#if !PocketPC + if (IsRotated) + { + UpdateRotationMatrix(); + } +#endif + ForceUpdateOverlays(); + } + } + } + + bool isSelected = false; + protected override void OnMouseDown(MouseEventArgs e) + { + if (!IsMouseOverMarker) { #if !PocketPC - if(IsRotated) - { - UpdateRotationMatrix(); - } -#endif - ForceUpdateOverlays(); - } - } - } - - bool isSelected = false; - protected override void OnMouseDown(MouseEventArgs e) - { - if(!IsMouseOverMarker) - { -#if !PocketPC - if(e.Button == DragButton && CanDragMap) + if (e.Button == DragButton && CanDragMap) #else if(CanDragMap) #endif - { + { #if !PocketPC - Core.mouseDown = ApplyRotationInversion(e.X, e.Y); + Core.mouseDown = ApplyRotationInversion(e.X, e.Y); #else Core.mouseDown = new GPoint(e.X, e.Y); #endif - this.Invalidate(); + this.Invalidate(); + } + else if (!isSelected) + { + isSelected = true; + SelectedArea = RectLatLng.Empty; + selectionEnd = PointLatLng.Empty; + selectionStart = FromLocalToLatLng(e.X, e.Y); + } } - else if(!isSelected) + + base.OnMouseDown(e); + } + + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + + if (isSelected) { - isSelected = true; - SelectedArea = RectLatLng.Empty; - selectionEnd = PointLatLng.Empty; - selectionStart = FromLocalToLatLng(e.X, e.Y); + isSelected = false; } - } - base.OnMouseDown(e); - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - - if(isSelected) - { - isSelected = false; - } - - if(Core.IsDragging) - { - if(isDragging) + if (Core.IsDragging) { - isDragging = false; - Debug.WriteLine("IsDragging = " + isDragging); + if (isDragging) + { + isDragging = false; + Debug.WriteLine("IsDragging = " + isDragging); #if !PocketPC - this.Cursor = cursorBefore; - cursorBefore = null; + this.Cursor = cursorBefore; + cursorBefore = null; #endif - } - Core.EndDrag(); + } + Core.EndDrag(); - if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) - { - if(Core.LastLocationInBounds.HasValue) - { - Position = Core.LastLocationInBounds.Value; - } - } - } - else - { -#if !PocketPC - if(e.Button == DragButton) - { - Core.mouseDown = GPoint.Empty; - } - - if(!selectionEnd.IsEmpty && !selectionStart.IsEmpty) - { - bool zoomtofit = false; - - if(!SelectedArea.IsEmpty && Form.ModifierKeys == Keys.Shift) - { - zoomtofit = SetZoomToFitRect(SelectedArea); - } - - if(OnSelectionChange != null) - { - OnSelectionChange(SelectedArea, zoomtofit); - } + if (BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) + { + if (Core.LastLocationInBounds.HasValue) + { + Position = Core.LastLocationInBounds.Value; + } + } } else { - Invalidate(); - } +#if !PocketPC + if (e.Button == DragButton) + { + Core.mouseDown = GPoint.Empty; + } + + if (!selectionEnd.IsEmpty && !selectionStart.IsEmpty) + { + bool zoomtofit = false; + + if (!SelectedArea.IsEmpty && Form.ModifierKeys == Keys.Shift) + { + zoomtofit = SetZoomToFitRect(SelectedArea); + } + + if (OnSelectionChange != null) + { + OnSelectionChange(SelectedArea, zoomtofit); + } + } + else + { + Invalidate(); + } #endif - } - } + } + } #if !PocketPC - protected override void OnMouseClick(MouseEventArgs e) - { - if(!Core.IsDragging) - { - for(int i = Overlays.Count - 1; i >= 0; i--) + protected override void OnMouseClick(MouseEventArgs e) + { + if (!Core.IsDragging) { - GMapOverlay o = Overlays[i]; - if(o != null && o.IsVisibile) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - if((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + for (int i = Overlays.Count - 1; i >= 0; i--) + { + GMapOverlay o = Overlays[i]; + if (o != null && o.IsVisibile) + { + foreach (GMapMarker m in o.Markers) { - if(OnMarkerClick != null) - { - OnMarkerClick(m, e); - } - break; + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + + if ((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + { + if (OnMarkerClick != null) + { + OnMarkerClick(m, e); + } + break; + } + + #endregion + } } - #endregion - } - } + foreach (GMapRoute m in o.Routes) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- - foreach(GMapRoute m in o.Routes) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - GPoint rp = new GPoint(e.X, e.Y); + GPoint rp = new GPoint(e.X, e.Y); #if !PocketPC - if(!MobileMode) - { - rp.OffsetNegative(Core.renderOffset); - } + if (!MobileMode) + { + rp.OffsetNegative(Core.renderOffset); + } #endif - if(m.IsInside((int)rp.X, (int)rp.Y)) - { - if(OnRouteClick != null) - { - OnRouteClick(m, e); - } - break; + if (m.IsInside((int)rp.X, (int)rp.Y)) + { + if (OnRouteClick != null) + { + OnRouteClick(m, e); + } + break; + } + #endregion + } } - #endregion - } - } - foreach(GMapPolygon m in o.Polygons) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - if(m.IsInside(FromLocalToLatLng(e.X, e.Y))) + foreach (GMapPolygon m in o.Polygons) { - if(OnPolygonClick != null) - { - OnPolygonClick(m, e); - } - break; + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + if (m.IsInside(FromLocalToLatLng(e.X, e.Y))) + { + if (OnPolygonClick != null) + { + OnPolygonClick(m, e); + } + break; + } + #endregion + } } - #endregion - } - } - } + } + } } - } - //m_mousepos = e.Location; - //if(HelperLineOption == HelperLineOptions.ShowAlways) - //{ - // base.Invalidate(); - //} + //m_mousepos = e.Location; + //if(HelperLineOption == HelperLineOptions.ShowAlways) + //{ + // base.Invalidate(); + //} - base.OnMouseClick(e); - } + base.OnMouseClick(e); + } #endif #if !PocketPC - /// - /// apply transformation if in rotation mode - /// - GPoint ApplyRotationInversion(int x, int y) - { - GPoint ret = new GPoint(x, y); + /// + /// apply transformation if in rotation mode + /// + GPoint ApplyRotationInversion(int x, int y) + { + GPoint ret = new GPoint(x, y); - if(IsRotated) - { + if (IsRotated) + { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrixInvert.TransformPoints(tt); - var f = tt[0]; + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrixInvert.TransformPoints(tt); + var f = tt[0]; - ret.X = f.X; - ret.Y = f.Y; - } + ret.X = f.X; + ret.Y = f.Y; + } - return ret; - } + return ret; + } - /// - /// apply transformation if in rotation mode - /// - GPoint ApplyRotation(int x, int y) - { - GPoint ret = new GPoint(x, y); + /// + /// apply transformation if in rotation mode + /// + GPoint ApplyRotation(int x, int y) + { + GPoint ret = new GPoint(x, y); - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrix.TransformPoints(tt); - var f = tt[0]; + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrix.TransformPoints(tt); + var f = tt[0]; - ret.X = f.X; - ret.Y = f.Y; - } + ret.X = f.X; + ret.Y = f.Y; + } - return ret; - } + return ret; + } - Cursor cursorBefore = Cursors.Default; + Cursor cursorBefore = Cursors.Default; #endif - /// - /// Gets the width and height of a rectangle centered on the point the mouse - /// button was pressed, within which a drag operation will not begin. - /// + /// + /// Gets the width and height of a rectangle centered on the point the mouse + /// button was pressed, within which a drag operation will not begin. + /// #if !PocketPC - public Size DragSize = SystemInformation.DragSize; + public Size DragSize = SystemInformation.DragSize; #else public Size DragSize = new Size(4, 4); #endif - protected override void OnMouseMove(MouseEventArgs e) - { - if(!Core.IsDragging && !Core.mouseDown.IsEmpty) - { + protected override void OnMouseMove(MouseEventArgs e) + { + if (!Core.IsDragging && !Core.mouseDown.IsEmpty) + { #if PocketPC GPoint p = new GPoint(e.X, e.Y); #else - GPoint p = ApplyRotationInversion(e.X, e.Y); + GPoint p = ApplyRotationInversion(e.X, e.Y); #endif - if(Math.Abs(p.X - Core.mouseDown.X) * 2 >= DragSize.Width || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= DragSize.Height) - { - Core.BeginDrag(Core.mouseDown); + if (Math.Abs(p.X - Core.mouseDown.X) * 2 >= DragSize.Width || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= DragSize.Height) + { + Core.BeginDrag(Core.mouseDown); + } } - } - if(Core.IsDragging) - { - if(!isDragging) + if (Core.IsDragging) { - isDragging = true; - Debug.WriteLine("IsDragging = " + isDragging); + if (!isDragging) + { + isDragging = true; + Debug.WriteLine("IsDragging = " + isDragging); #if !PocketPC - cursorBefore = this.Cursor; - this.Cursor = Cursors.SizeAll; + cursorBefore = this.Cursor; + this.Cursor = Cursors.SizeAll; #endif - } + } - if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) - { - // ... - } - else - { + if (BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) + { + // ... + } + else + { #if !PocketPC - Core.mouseCurrent = ApplyRotationInversion(e.X, e.Y); + Core.mouseCurrent = ApplyRotationInversion(e.X, e.Y); #else Core.mouseCurrent = new GPoint(e.X, e.Y); #endif - Core.Drag(Core.mouseCurrent); + Core.Drag(Core.mouseCurrent); #if !PocketPC - if(MobileMode) - { - ForceUpdateOverlays(); - } + if (MobileMode) + { + ForceUpdateOverlays(); + } #else ForceUpdateOverlays(); #endif - base.Invalidate(); - } - } - else - { -#if !PocketPC - if(isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift || DisableAltForSelection)) - { - selectionEnd = FromLocalToLatLng(e.X, e.Y); - { - GMap.NET.PointLatLng p1 = selectionStart; - GMap.NET.PointLatLng p2 = selectionEnd; - - double x1 = Math.Min(p1.Lng, p2.Lng); - double y1 = Math.Max(p1.Lat, p2.Lat); - double x2 = Math.Max(p1.Lng, p2.Lng); - double y2 = Math.Min(p1.Lat, p2.Lat); - - SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2); - } + base.Invalidate(); + } } else -#endif - if(Core.mouseDown.IsEmpty) - { - for(int i = Overlays.Count - 1; i >= 0; i--) - { - GMapOverlay o = Overlays[i]; - if(o != null && o.IsVisibile) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- + { #if !PocketPC - if((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + if (isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift || DisableAltForSelection)) + { + selectionEnd = FromLocalToLatLng(e.X, e.Y); + { + GMap.NET.PointLatLng p1 = selectionStart; + GMap.NET.PointLatLng p2 = selectionEnd; + + double x1 = Math.Min(p1.Lng, p2.Lng); + double y1 = Math.Max(p1.Lat, p2.Lat); + double x2 = Math.Max(p1.Lng, p2.Lng); + double y2 = Math.Min(p1.Lat, p2.Lat); + + SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2); + } + } + else +#endif + if (Core.mouseDown.IsEmpty) + { + for (int i = Overlays.Count - 1; i >= 0; i--) + { + GMapOverlay o = Overlays[i]; + if (o != null && o.IsVisibile) + { + foreach (GMapMarker m in o.Markers) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- +#if !PocketPC + if ((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) #else if(m.LocalArea.Contains(e.X, e.Y)) #endif - { - if(!m.IsMouseOver) - { -#if !PocketPC - SetCursorHandOnEnter(); -#endif - m.IsMouseOver = true; - IsMouseOverMarker = true; - - if(OnMarkerEnter != null) { - OnMarkerEnter(m); - } - - Invalidate(); - } - } - else if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverMarker = false; + if (!m.IsMouseOver) + { #if !PocketPC - RestoreCursorOnLeave(); + SetCursorHandOnEnter(); #endif - if(OnMarkerLeave != null) - { - OnMarkerLeave(m); - } + m.IsMouseOver = true; + IsMouseOverMarker = true; - Invalidate(); - } - #endregion - } - } + if (OnMarkerEnter != null) + { + OnMarkerEnter(m); + } + + Invalidate(); + } + } + else if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverMarker = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnMarkerLeave != null) + { + OnMarkerLeave(m); + } + + Invalidate(); + } + #endregion + } + } #if !PocketPC - foreach(GMapRoute m in o.Routes) + foreach (GMapRoute m in o.Routes) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + + GPoint rp = new GPoint(e.X, e.Y); +#if !PocketPC + if (!MobileMode) + { + rp.OffsetNegative(Core.renderOffset); + } +#endif + if (m.IsInside((int)rp.X, (int)rp.Y)) + { + if (!m.IsMouseOver) + { +#if !PocketPC + SetCursorHandOnEnter(); +#endif + m.IsMouseOver = true; + IsMouseOverRoute = true; + + if (OnRouteEnter != null) + { + OnRouteEnter(m); + } + + Invalidate(); + } + } + else + { + if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverRoute = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnRouteLeave != null) + { + OnRouteLeave(m); + } + + Invalidate(); + } + } + #endregion + } + } +#endif + + foreach (GMapPolygon m in o.Polygons) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + if (m.IsInside(FromLocalToLatLng(e.X, e.Y))) + { + if (!m.IsMouseOver) + { +#if !PocketPC + SetCursorHandOnEnter(); +#endif + m.IsMouseOver = true; + IsMouseOverPolygon = true; + + if (OnPolygonEnter != null) + { + OnPolygonEnter(m); + } + + Invalidate(); + } + } + else + { + if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverPolygon = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnPolygonLeave != null) + { + OnPolygonLeave(m); + } + + Invalidate(); + } + } + #endregion + } + } + } + } + } + + if (renderHelperLine) + { + base.Invalidate(); + } + } + + base.OnMouseMove(e); + } + +#if !PocketPC + + internal void RestoreCursorOnLeave() + { + if (overObjectCount == 0 && cursorBefore != null) + { + this.Cursor = this.cursorBefore; + cursorBefore = null; + } + } + + internal void SetCursorHandOnEnter() + { + if (overObjectCount == 0 && Cursor != Cursors.Hand) + { + cursorBefore = this.Cursor; + this.Cursor = Cursors.Hand; + } + } + + /// + /// prevents focusing map if mouse enters it's area + /// + public bool DisableFocusOnMouseEnter = false; + + protected override void OnMouseEnter(EventArgs e) + { + base.OnMouseEnter(e); + + if (!DisableFocusOnMouseEnter) + { + Focus(); + } + } + + /// + /// reverses MouseWheel zooming direction + /// + public bool InvertedMouseWheelZooming = false; + + /// + /// lets you zoom by MouseWheel even when pointer is in area of marker + /// + public bool IgnoreMarkerOnMouseWheel = false; + + protected override void OnMouseWheel(MouseEventArgs e) + { + base.OnMouseWheel(e); + + if ((!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging) + { + if (Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y) + { + if (MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter) + { + Core.position = FromLocalToLatLng(e.X, e.Y); + } + else if (MouseWheelZoomType == MouseWheelZoomType.ViewCenter) + { + Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2); + } + else if (MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter) + { + Core.position = FromLocalToLatLng(e.X, e.Y); + } + + Core.mouseLastZoom.X = e.X; + Core.mouseLastZoom.Y = e.Y; + } + + // set mouse position to map center + if (MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter) + { + if (!GMaps.Instance.IsRunningOnMono) + { + System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2)); + Stuff.SetCursorPos((int)p.X, (int)p.Y); + } + } + + Core.MouseWheelZooming = true; + + if (e.Delta > 0) + { + if (!InvertedMouseWheelZooming) + { + Zoom++; + } + else + { + Zoom--; + } + } + else if (e.Delta < 0) + { + if (!InvertedMouseWheelZooming) + { + Zoom--; + } + else + { + Zoom++; + } + } + + Core.MouseWheelZooming = false; + } + } +#endif + #endregion + + #region IGControl Members + + /// + /// Call it to empty tile cache & reload tiles + /// + public void ReloadMap() + { + Core.ReloadMap(); + } + + /// + /// set current position using keywords + /// + /// + /// true if successfull + public GeoCoderStatusCode SetCurrentPositionByKeywords(string keys) + { + GeoCoderStatusCode status = GeoCoderStatusCode.Unknow; + + GeocodingProvider gp = MapProvider as GeocodingProvider; + if (gp == null) + { + gp = GMapProviders.OpenStreetMap as GeocodingProvider; + } + + if (gp != null) + { + var pt = gp.GetPoint(keys, out status); + if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue) + { + Position = pt.Value; + } + } + + return status; + } + + /// + /// gets world coordinate from local control coordinate + /// + /// + /// + /// + public PointLatLng FromLocalToLatLng(int x, int y) + { +#if !PocketPC + if (MapRenderTransform.HasValue) + { + //var xx = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); + //var yy = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); + + //PointF center = new PointF(Core.Width / 2, Core.Height / 2); + + //Matrix m = new Matrix(); + //m.Translate(-Core.renderOffset.X, -Core.renderOffset.Y); + //m.Scale(MapRenderTransform.Value, MapRenderTransform.Value); + + //System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + //m.TransformPoints(tt); + //var z = tt[0]; + + // + + x = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); + y = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); + } + + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrixInvert.TransformPoints(tt); + var f = tt[0]; + + if (VirtualSizeEnabled) + { + f.X += (Width - Core.vWidth) / 2; + f.Y += (Height - Core.vHeight) / 2; + } + + x = f.X; + y = f.Y; + } +#endif + return Core.FromLocalToLatLng(x, y); + } + + /// + /// gets local coordinate from world coordinate + /// + /// + /// + public GPoint FromLatLngToLocal(PointLatLng point) + { + GPoint ret = Core.FromLatLngToLocal(point); + +#if !PocketPC + if (MapRenderTransform.HasValue) + { + ret.X = (int)(Core.renderOffset.X + ((Core.renderOffset.X - ret.X) * -MapRenderTransform.Value)); + ret.Y = (int)(Core.renderOffset.Y + ((Core.renderOffset.Y - ret.Y) * -MapRenderTransform.Value)); + } + + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point((int)ret.X, (int)ret.Y) }; + rotationMatrix.TransformPoints(tt); + var f = tt[0]; + + if (VirtualSizeEnabled) + { + f.X += (Width - Core.vWidth) / 2; + f.Y += (Height - Core.vHeight) / 2; + } + + ret.X = f.X; + ret.Y = f.Y; + } + +#endif + return ret; + } + +#if !PocketPC + + /// + /// shows map db export dialog + /// + /// + public bool ShowExportDialog() + { + using (FileDialog dlg = new SaveFileDialog()) + { + dlg.CheckPathExists = true; + dlg.CheckFileExists = false; + dlg.AddExtension = true; + dlg.DefaultExt = "gmdb"; + dlg.ValidateNames = true; + dlg.Title = "GMap.NET: Export map to db, if file exsist only new data will be added"; + dlg.FileName = "DataExp"; + dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; + dlg.FilterIndex = 1; + dlg.RestoreDirectory = true; + + if (dlg.ShowDialog() == DialogResult.OK) + { + bool ok = GMaps.Instance.ExportToGMDB(dlg.FileName); + if (ok) + { + MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + return ok; + } + } + + return false; + } + + /// + /// shows map dbimport dialog + /// + /// + public bool ShowImportDialog() + { + using (FileDialog dlg = new OpenFileDialog()) + { + dlg.CheckPathExists = true; + dlg.CheckFileExists = false; + dlg.AddExtension = true; + dlg.DefaultExt = "gmdb"; + dlg.ValidateNames = true; + dlg.Title = "GMap.NET: Import to db, only new data will be added"; + dlg.FileName = "DataImport"; + dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; + dlg.FilterIndex = 1; + dlg.RestoreDirectory = true; + + if (dlg.ShowDialog() == DialogResult.OK) + { + bool ok = GMaps.Instance.ImportFromGMDB(dlg.FileName); + if (ok) + { + MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMap(); + } + else + { + MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + return ok; + } + } + + return false; + } +#endif + + [Category("GMap.NET"), DefaultValue(0)] + public double Zoom + { + get + { + return zoomReal; + } + set + { + if (zoomReal != value) + { + Debug.WriteLine("ZoomPropertyChanged: " + zoomReal + " -> " + value); + + if (value > MaxZoom) + { + zoomReal = MaxZoom; + } + else if (value < MinZoom) + { + zoomReal = MinZoom; + } + else + { + zoomReal = value; + } + + double remainder = value % 1; + if (remainder != 0) + { + float scaleValue = (float)Math.Pow(2d, remainder); { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - GPoint rp = new GPoint(e.X, e.Y); #if !PocketPC - if(!MobileMode) - { - rp.OffsetNegative(Core.renderOffset); - } + MapRenderTransform = scaleValue; #endif - if(m.IsInside((int)rp.X, (int)rp.Y)) - { - if(!m.IsMouseOver) - { -#if !PocketPC - SetCursorHandOnEnter(); -#endif - m.IsMouseOver = true; - IsMouseOverRoute = true; - - if(OnRouteEnter != null) - { - OnRouteEnter(m); - } - - Invalidate(); - } - } - else - { - if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverRoute = false; -#if !PocketPC - RestoreCursorOnLeave(); -#endif - if(OnRouteLeave != null) - { - OnRouteLeave(m); - } - - Invalidate(); - } - } - #endregion - } } -#endif - foreach(GMapPolygon m in o.Polygons) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - if(m.IsInside(FromLocalToLatLng(e.X, e.Y))) - { - if(!m.IsMouseOver) - { + ZoomStep = Convert.ToInt32(value - remainder); + } + else + { #if !PocketPC - SetCursorHandOnEnter(); + MapRenderTransform = null; #endif - m.IsMouseOver = true; - IsMouseOverPolygon = true; + ZoomStep = Convert.ToInt32(value); + zoomReal = ZoomStep; + } - if(OnPolygonEnter != null) - { - OnPolygonEnter(m); - } - - Invalidate(); - } - } - else - { - if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverPolygon = false; -#if !PocketPC - RestoreCursorOnLeave(); -#endif - if(OnPolygonLeave != null) - { - OnPolygonLeave(m); - } - - Invalidate(); - } - } - #endregion - } - } - } - } - } - - if(renderHelperLine) - { - base.Invalidate(); + if (Core.IsStarted && !IsDragging) + { + ForceUpdateOverlays(); + } + } } - } + } - base.OnMouseMove(e); - } - -#if !PocketPC - - internal void RestoreCursorOnLeave() - { - if(overObjectCount == 0 && cursorBefore != null) - { - this.Cursor = this.cursorBefore; - cursorBefore = null; - } - } - - internal void SetCursorHandOnEnter() - { - if(overObjectCount == 0 && Cursor != Cursors.Hand) - { - cursorBefore = this.Cursor; - this.Cursor = Cursors.Hand; - } - } - - /// - /// prevents focusing map if mouse enters it's area - /// - public bool DisableFocusOnMouseEnter = false; - - protected override void OnMouseEnter(EventArgs e) - { - base.OnMouseEnter(e); - - if(!DisableFocusOnMouseEnter) - { - Focus(); - } - } - - /// - /// reverses MouseWheel zooming direction - /// - public bool InvertedMouseWheelZooming = false; - - /// - /// lets you zoom by MouseWheel even when pointer is in area of marker - /// - public bool IgnoreMarkerOnMouseWheel = false; - - protected override void OnMouseWheel(MouseEventArgs e) - { - base.OnMouseWheel(e); - - if((!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging) - { - if(Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y) + /// + /// map zoom level + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + internal int ZoomStep + { + get { - if(MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter) - { - Core.position = FromLocalToLatLng(e.X, e.Y); - } - else if(MouseWheelZoomType == MouseWheelZoomType.ViewCenter) - { - Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2); - } - else if(MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter) - { - Core.position = FromLocalToLatLng(e.X, e.Y); - } - - Core.mouseLastZoom.X = e.X; - Core.mouseLastZoom.Y = e.Y; + return Core.Zoom; } - - // set mouse position to map center - if(MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter) + set { - if(!GMaps.Instance.IsRunningOnMono) - { - System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2)); - Stuff.SetCursorPos((int)p.X, (int)p.Y); - } + if (value > MaxZoom) + { + Core.Zoom = MaxZoom; + } + else if (value < MinZoom) + { + Core.Zoom = MinZoom; + } + else + { + Core.Zoom = value; + } } + } - Core.MouseWheelZooming = true; - - if(e.Delta > 0) + /// + /// current map center position + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public PointLatLng Position + { + get { - if(!InvertedMouseWheelZooming) - { - Zoom++; - } - else - { - Zoom--; - } + return Core.Position; } - else if(e.Delta < 0) + set { - if(!InvertedMouseWheelZooming) - { - Zoom--; - } - else - { - Zoom++; - } + Core.Position = value; + + if (Core.IsStarted) + { + ForceUpdateOverlays(); + } } + } - Core.MouseWheelZooming = false; - } - } -#endif - #endregion - - #region IGControl Members - - /// - /// Call it to empty tile cache & reload tiles - /// - public void ReloadMap() - { - Core.ReloadMap(); - } - - /// - /// set current position using keywords - /// - /// - /// true if successfull - public GeoCoderStatusCode SetCurrentPositionByKeywords(string keys) - { - GeoCoderStatusCode status = GeoCoderStatusCode.Unknow; - - GeocodingProvider gp = MapProvider as GeocodingProvider; - if(gp == null) - { - gp = GMapProviders.OpenStreetMap as GeocodingProvider; - } - - if(gp != null) - { - var pt = gp.GetPoint(keys, out status); - if(status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue) + /// + /// current position in pixel coordinates + /// + [Browsable(false)] + public GPoint PositionPixel + { + get { - Position = pt.Value; + return Core.PositionPixel; } - } + } - return status; - } - - /// - /// gets world coordinate from local control coordinate - /// - /// - /// - /// - public PointLatLng FromLocalToLatLng(int x, int y) - { -#if !PocketPC - if(MapRenderTransform.HasValue) - { - //var xx = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); - //var yy = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); - - //PointF center = new PointF(Core.Width / 2, Core.Height / 2); - - //Matrix m = new Matrix(); - //m.Translate(-Core.renderOffset.X, -Core.renderOffset.Y); - //m.Scale(MapRenderTransform.Value, MapRenderTransform.Value); - - //System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - //m.TransformPoints(tt); - //var z = tt[0]; - - // - - x = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); - y = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); - } - - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrixInvert.TransformPoints(tt); - var f = tt[0]; - - if(VirtualSizeEnabled) + /// + /// location of cache + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public string CacheLocation + { + get { - f.X += (Width - Core.vWidth) / 2; - f.Y += (Height - Core.vHeight) / 2; - } - - x = f.X; - y = f.Y; - } -#endif - return Core.FromLocalToLatLng(x, y); - } - - /// - /// gets local coordinate from world coordinate - /// - /// - /// - public GPoint FromLatLngToLocal(PointLatLng point) - { - GPoint ret = Core.FromLatLngToLocal(point); - -#if !PocketPC - if(MapRenderTransform.HasValue) - { - ret.X = (int)(Core.renderOffset.X + ((Core.renderOffset.X - ret.X) * -MapRenderTransform.Value)); - ret.Y = (int)(Core.renderOffset.Y + ((Core.renderOffset.Y - ret.Y) * -MapRenderTransform.Value)); - } - - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point((int)ret.X, (int)ret.Y) }; - rotationMatrix.TransformPoints(tt); - var f = tt[0]; - - if(VirtualSizeEnabled) - { - f.X += (Width - Core.vWidth) / 2; - f.Y += (Height - Core.vHeight) / 2; - } - - ret.X = f.X; - ret.Y = f.Y; - } - -#endif - return ret; - } - -#if !PocketPC - - /// - /// shows map db export dialog - /// - /// - public bool ShowExportDialog() - { - using(FileDialog dlg = new SaveFileDialog()) - { - dlg.CheckPathExists = true; - dlg.CheckFileExists = false; - dlg.AddExtension = true; - dlg.DefaultExt = "gmdb"; - dlg.ValidateNames = true; - dlg.Title = "GMap.NET: Export map to db, if file exsist only new data will be added"; - dlg.FileName = "DataExp"; - dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; - dlg.FilterIndex = 1; - dlg.RestoreDirectory = true; - - if(dlg.ShowDialog() == DialogResult.OK) - { - bool ok = GMaps.Instance.ExportToGMDB(dlg.FileName); - if(ok) - { - MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - return ok; - } - } - - return false; - } - - /// - /// shows map dbimport dialog - /// - /// - public bool ShowImportDialog() - { - using(FileDialog dlg = new OpenFileDialog()) - { - dlg.CheckPathExists = true; - dlg.CheckFileExists = false; - dlg.AddExtension = true; - dlg.DefaultExt = "gmdb"; - dlg.ValidateNames = true; - dlg.Title = "GMap.NET: Import to db, only new data will be added"; - dlg.FileName = "DataImport"; - dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; - dlg.FilterIndex = 1; - dlg.RestoreDirectory = true; - - if(dlg.ShowDialog() == DialogResult.OK) - { - bool ok = GMaps.Instance.ImportFromGMDB(dlg.FileName); - if(ok) - { - MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); - ReloadMap(); - } - else - { - MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - return ok; - } - } - - return false; - } -#endif - - [Category("GMap.NET"), DefaultValue(0)] - public double Zoom - { - get - { - return zoomReal; - } - set - { - if(zoomReal != value) - { - Debug.WriteLine("ZoomPropertyChanged: " + zoomReal + " -> " + value); - - if(value > MaxZoom) - { - zoomReal = MaxZoom; - } - else if(value < MinZoom) - { - zoomReal = MinZoom; - } - else - { - zoomReal = value; - } - - double remainder = value % 1; - if(remainder != 0) - { - float scaleValue = (float)Math.Pow(2d, remainder); - { -#if !PocketPC - MapRenderTransform = scaleValue; -#endif - } - - ZoomStep = Convert.ToInt32(value - remainder); - } - else - { -#if !PocketPC - MapRenderTransform = null; -#endif - ZoomStep = Convert.ToInt32(value); - zoomReal = ZoomStep; - } - - if(Core.IsStarted && !IsDragging) - { - ForceUpdateOverlays(); - } - } - } - } - - /// - /// map zoom level - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - internal int ZoomStep - { - get - { - return Core.Zoom; - } - set - { - if(value > MaxZoom) - { - Core.Zoom = MaxZoom; - } - else if(value < MinZoom) - { - Core.Zoom = MinZoom; - } - else - { - Core.Zoom = value; - } - } - } - - /// - /// current map center position - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public PointLatLng Position - { - get - { - return Core.Position; - } - set - { - Core.Position = value; - - if(Core.IsStarted) - { - ForceUpdateOverlays(); - } - } - } - - /// - /// current position in pixel coordinates - /// - [Browsable(false)] - public GPoint PositionPixel - { - get - { - return Core.PositionPixel; - } - } - - /// - /// location of cache - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public string CacheLocation - { - get - { #if !DESIGN - return CacheLocator.Location; + return CacheLocator.Location; #else return string.Empty; #endif - } - set - { -#if !DESIGN - CacheLocator.Location = value; -#endif - } - } - - bool isDragging = false; - - /// - /// is user dragging map - /// - [Browsable(false)] - public bool IsDragging - { - get - { - return isDragging; - } - } - - bool isMouseOverMarker; - internal int overObjectCount = 0; - - /// - /// is mouse over marker - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverMarker - { - get - { - return isMouseOverMarker; - } - internal set - { - isMouseOverMarker = value; - overObjectCount += value ? 1 : -1; - } - } - - bool isMouseOverRoute; - - /// - /// is mouse over route - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverRoute - { - get - { - return isMouseOverRoute; - } - internal set - { - isMouseOverRoute = value; - overObjectCount += value ? 1 : -1; - } - } - - bool isMouseOverPolygon; - - /// - /// is mouse over polygon - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverPolygon - { - get - { - return isMouseOverPolygon; - } - internal set - { - isMouseOverPolygon = value; - overObjectCount += value ? 1 : -1; - } - } - - /// - /// gets current map view top/left coordinate, width in Lng, height in Lat - /// - [Browsable(false)] - public RectLatLng ViewArea - { - get - { - return Core.ViewArea; - } - } - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public GMapProvider MapProvider - { - get - { - return Core.Provider; - } - set - { - if(Core.Provider == null || !Core.Provider.Equals(value)) - { - Debug.WriteLine("MapType: " + Core.Provider.Name + " -> " + value.Name); - - RectLatLng viewarea = SelectedArea; - if(viewarea != RectLatLng.Empty) - { - Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2); - } - else - { - viewarea = ViewArea; - } - - Core.Provider = value; - - if(Core.IsStarted) - { - if(Core.zoomToArea) - { - // restore zoomrect as close as possible - if(viewarea != RectLatLng.Empty && viewarea != ViewArea) - { - int bestZoom = Core.GetMaxZoomToFitRect(viewarea); - if(bestZoom > 0 && Zoom != bestZoom) - { - Zoom = bestZoom; - } - } - } - else - { - ForceUpdateOverlays(); - } - } } - } - } - - /// - /// is routes enabled - /// - [Category("GMap.NET")] - public bool RoutesEnabled - { - get - { - return Core.RoutesEnabled; - } - set - { - Core.RoutesEnabled = value; - } - } - - /// - /// is polygons enabled - /// - [Category("GMap.NET")] - public bool PolygonsEnabled - { - get - { - return Core.PolygonsEnabled; - } - set - { - Core.PolygonsEnabled = value; - } - } - - /// - /// is markers enabled - /// - [Category("GMap.NET")] - public bool MarkersEnabled - { - get - { - return Core.MarkersEnabled; - } - set - { - Core.MarkersEnabled = value; - } - } - - /// - /// can user drag map - /// - [Category("GMap.NET")] - public bool CanDragMap - { - get - { - return Core.CanDragMap; - } - set - { - Core.CanDragMap = value; - } - } - - /// - /// map render mode - /// - [Browsable(false)] - public RenderMode RenderMode - { - get - { - return Core.RenderMode; - } - internal set - { - Core.RenderMode = value; - } - } - - /// - /// gets map manager - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public GMaps Manager - { - get - { - return GMaps.Instance; - } - } - - #endregion - - #region IGControl event Members - - /// - /// occurs when current position is changed - /// - public event PositionChanged OnPositionChanged - { - add - { - Core.OnCurrentPositionChanged += value; - } - remove - { - Core.OnCurrentPositionChanged -= value; - } - } - - /// - /// occurs when tile set load is complete - /// - public event TileLoadComplete OnTileLoadComplete - { - add - { - Core.OnTileLoadComplete += value; - } - remove - { - Core.OnTileLoadComplete -= value; - } - } - - /// - /// occurs when tile set is starting to load - /// - public event TileLoadStart OnTileLoadStart - { - add - { - Core.OnTileLoadStart += value; - } - remove - { - Core.OnTileLoadStart -= value; - } - } - - /// - /// occurs on map drag - /// - public event MapDrag OnMapDrag - { - add - { - Core.OnMapDrag += value; - } - remove - { - Core.OnMapDrag -= value; - } - } - - /// - /// occurs on map zoom changed - /// - public event MapZoomChanged OnMapZoomChanged - { - add - { - Core.OnMapZoomChanged += value; - } - remove - { - Core.OnMapZoomChanged -= value; - } - } - - /// - /// occures on map type changed - /// - public event MapTypeChanged OnMapTypeChanged - { - add - { - Core.OnMapTypeChanged += value; - } - remove - { - Core.OnMapTypeChanged -= value; - } - } - - /// - /// occurs on empty tile displayed - /// - public event EmptyTileError OnEmptyTileError - { - add - { - Core.OnEmptyTileError += value; - } - remove - { - Core.OnEmptyTileError -= value; - } - } - - #endregion - -#if !PocketPC - #region Serialization - - static readonly BinaryFormatter BinaryFormatter = new BinaryFormatter(); - - /// - /// Serializes the overlays. - /// - /// The stream. - public void SerializeOverlays(Stream stream) - { - if(stream == null) - { - throw new ArgumentNullException("stream"); - } - - // Create an array from the overlays - GMapOverlay[] overlayArray = new GMapOverlay[this.Overlays.Count]; - this.Overlays.CopyTo(overlayArray, 0); - - // Serialize the overlays - BinaryFormatter.Serialize(stream, overlayArray); - } - - /// - /// De-serializes the overlays. - /// - /// The stream. - public void DeserializeOverlays(Stream stream) - { - if(stream == null) - { - throw new ArgumentNullException("stream"); - } - - // De-serialize the overlays - GMapOverlay[] overlayArray = BinaryFormatter.Deserialize(stream) as GMapOverlay[]; - - // Populate the collection of overlays. - foreach(GMapOverlay overlay in overlayArray) - { - overlay.Control = this; - this.Overlays.Add(overlay); - } - - this.ForceUpdateOverlays(); - } - - #endregion + set + { +#if !DESIGN + CacheLocator.Location = value; #endif - } + } + } + + bool isDragging = false; + + /// + /// is user dragging map + /// + [Browsable(false)] + public bool IsDragging + { + get + { + return isDragging; + } + } + + bool isMouseOverMarker; + internal int overObjectCount = 0; + + /// + /// is mouse over marker + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverMarker + { + get + { + return isMouseOverMarker; + } + internal set + { + isMouseOverMarker = value; + overObjectCount += value ? 1 : -1; + } + } + + bool isMouseOverRoute; + + /// + /// is mouse over route + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverRoute + { + get + { + return isMouseOverRoute; + } + internal set + { + isMouseOverRoute = value; + overObjectCount += value ? 1 : -1; + } + } + + bool isMouseOverPolygon; + + /// + /// is mouse over polygon + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverPolygon + { + get + { + return isMouseOverPolygon; + } + internal set + { + isMouseOverPolygon = value; + overObjectCount += value ? 1 : -1; + } + } + + /// + /// gets current map view top/left coordinate, width in Lng, height in Lat + /// + [Browsable(false)] + public RectLatLng ViewArea + { + get + { + return Core.ViewArea; + } + } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public GMapProvider MapProvider + { + get + { + return Core.Provider; + } + set + { + if (Core.Provider == null || !Core.Provider.Equals(value)) + { + Debug.WriteLine("MapType: " + Core.Provider.Name + " -> " + value.Name); + + RectLatLng viewarea = SelectedArea; + if (viewarea != RectLatLng.Empty) + { + Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2); + } + else + { + viewarea = ViewArea; + } + + Core.Provider = value; + + if (Core.IsStarted) + { + if (Core.zoomToArea) + { + // restore zoomrect as close as possible + if (viewarea != RectLatLng.Empty && viewarea != ViewArea) + { + int bestZoom = Core.GetMaxZoomToFitRect(viewarea); + if (bestZoom > 0 && Zoom != bestZoom) + { + Zoom = bestZoom; + } + } + } + else + { + ForceUpdateOverlays(); + } + } + } + } + } + + /// + /// is routes enabled + /// + [Category("GMap.NET")] + public bool RoutesEnabled + { + get + { + return Core.RoutesEnabled; + } + set + { + Core.RoutesEnabled = value; + } + } + + /// + /// is polygons enabled + /// + [Category("GMap.NET")] + public bool PolygonsEnabled + { + get + { + return Core.PolygonsEnabled; + } + set + { + Core.PolygonsEnabled = value; + } + } + + /// + /// is markers enabled + /// + [Category("GMap.NET")] + public bool MarkersEnabled + { + get + { + return Core.MarkersEnabled; + } + set + { + Core.MarkersEnabled = value; + } + } + + /// + /// can user drag map + /// + [Category("GMap.NET")] + public bool CanDragMap + { + get + { + return Core.CanDragMap; + } + set + { + Core.CanDragMap = value; + } + } + + /// + /// map render mode + /// + [Browsable(false)] + public RenderMode RenderMode + { + get + { + return Core.RenderMode; + } + internal set + { + Core.RenderMode = value; + } + } + + /// + /// gets map manager + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public GMaps Manager + { + get + { + return GMaps.Instance; + } + } + + #endregion + + #region IGControl event Members + + /// + /// occurs when current position is changed + /// + public event PositionChanged OnPositionChanged + { + add + { + Core.OnCurrentPositionChanged += value; + } + remove + { + Core.OnCurrentPositionChanged -= value; + } + } + + /// + /// occurs when tile set load is complete + /// + public event TileLoadComplete OnTileLoadComplete + { + add + { + Core.OnTileLoadComplete += value; + } + remove + { + Core.OnTileLoadComplete -= value; + } + } + + /// + /// occurs when tile set is starting to load + /// + public event TileLoadStart OnTileLoadStart + { + add + { + Core.OnTileLoadStart += value; + } + remove + { + Core.OnTileLoadStart -= value; + } + } + + /// + /// occurs on map drag + /// + public event MapDrag OnMapDrag + { + add + { + Core.OnMapDrag += value; + } + remove + { + Core.OnMapDrag -= value; + } + } + + /// + /// occurs on map zoom changed + /// + public event MapZoomChanged OnMapZoomChanged + { + add + { + Core.OnMapZoomChanged += value; + } + remove + { + Core.OnMapZoomChanged -= value; + } + } + + /// + /// occures on map type changed + /// + public event MapTypeChanged OnMapTypeChanged + { + add + { + Core.OnMapTypeChanged += value; + } + remove + { + Core.OnMapTypeChanged -= value; + } + } + + /// + /// occurs on empty tile displayed + /// + public event EmptyTileError OnEmptyTileError + { + add + { + Core.OnEmptyTileError += value; + } + remove + { + Core.OnEmptyTileError -= value; + } + } + + #endregion #if !PocketPC - public enum HelperLineOptions - { - DontShow = 0, - ShowAlways = 1, - ShowOnModifierKey = 2 - } + #region Serialization - public delegate void SelectionChange(RectLatLng Selection, bool ZoomToFit); + static readonly BinaryFormatter BinaryFormatter = new BinaryFormatter(); + + /// + /// Serializes the overlays. + /// + /// The stream. + public void SerializeOverlays(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + + // Create an array from the overlays + GMapOverlay[] overlayArray = new GMapOverlay[this.Overlays.Count]; + this.Overlays.CopyTo(overlayArray, 0); + + // Serialize the overlays + BinaryFormatter.Serialize(stream, overlayArray); + } + + /// + /// De-serializes the overlays. + /// + /// The stream. + public void DeserializeOverlays(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + + // De-serialize the overlays + GMapOverlay[] overlayArray = BinaryFormatter.Deserialize(stream) as GMapOverlay[]; + + // Populate the collection of overlays. + foreach (GMapOverlay overlay in overlayArray) + { + overlay.Control = this; + this.Overlays.Add(overlay); + } + + this.ForceUpdateOverlays(); + } + + #endregion +#endif + } + +#if !PocketPC + public enum HelperLineOptions + { + DontShow = 0, + ShowAlways = 1, + ShowOnModifierKey = 2 + } + + public delegate void SelectionChange(RectLatLng Selection, bool ZoomToFit); #endif } diff --git a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs index 305b3d2..eb7b174 100644 --- a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs +++ b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs @@ -460,32 +460,50 @@ namespace ScoutBase.Propagation // return null if elevation path is null for whatever reason if (ep == null) return null; - for (int i = 0; i < ep.Count; i++) + // using (StreamWriter sw = new StreamWriter(File.OpenWrite("propagation.csv"))) { - double dist1 = i * stepwidth / 1000.0; - double dist2 = (ep.Count - i - 1) * stepwidth / 1000.0; - double f1c1 = ScoutBase.Core.Propagation.F1Radius(qrg, dist1, dist2) * f1_clearance; - double f1c2 = ScoutBase.Core.Propagation.F1Radius(qrg, dist2, dist1) * f1_clearance; - double nf = NearFieldSuppression / 1000.0; - double eps1; - double eps2; - if (dist1 > nf) + // sw.WriteLine("i;dist1;dist2;f1c1;f1c2;elv;eps1;eps1_min;eps2;eps2_min"); + for (int i = 0; i < ep.Count; i++) { - eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); + double dist1 = i * stepwidth / 1000.0; + double dist2 = (ep.Count - i - 1) * stepwidth / 1000.0; + double f1c1 = ScoutBase.Core.Propagation.F1Radius(qrg, dist1, dist2) * f1_clearance; + double f1c2 = ScoutBase.Core.Propagation.F1Radius(qrg, dist2, dist1) * f1_clearance; + double nf = NearFieldSuppression / 1000.0; + double eps1; + double eps2; + if (dist1 > nf) + eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); + else + eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, nf, ep.Path[i] + f1c1, radius); if (eps1 > eps1_min) eps1_min = eps1; - } - if (dist2 > nf) - { - eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); + if (dist2 > nf) + eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); + else + eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, nf, ep.Path[i] + f1c2, radius); if (eps2 > eps2_min) eps2_min = eps2; - } - if (caller != null) - { - // abort calculation if cancellation pending - if (caller.WorkerSupportsCancellation && caller.CancellationPending) - return null; + if (caller != null) + { + // abort calculation if cancellation pending + if (caller.WorkerSupportsCancellation && caller.CancellationPending) + return null; + } + /* + sw.WriteLine( + i.ToString() + ";" + + dist1.ToString("F8") + ";" + + dist2.ToString("F8") + ";" + + f1c1.ToString("F8") + ";" + + f1c2.ToString("F8") + ";" + + ep.Path[i].ToString() + ";" + + eps1.ToString("F8") + ";" + + eps1_min.ToString("F8") + ";" + + eps2.ToString("F8") + ";" + + eps2_min.ToString("F8") + ); + */ } } PropagationPathDesignator pp = new PropagationPathDesignator(lat1, lon1, h1, lat2, lon2, h2, qrg, radius, f1_clearance, stepwidth, eps1_min, eps2_min, localobstruction); From 5d83dce0a8f1558b45e6196751e6913a9c3bb5e9 Mon Sep 17 00:00:00 2001 From: dl2alf Date: Sun, 2 Jan 2022 09:22:23 +0100 Subject: [PATCH 4/4] Merge with V1.4.x (2)V1.3.3.6 --- .../Properties/AssemblyInfo.cs | 4 +- .../TLS.cs | 91 +- .../VirtualRadarServer.cs | 9 +- AirScout/Properties/AssemblyInfo.cs | 4 +- .../GMap.NET.WindowsForms/GMapControl.cs | 5502 +++++++++-------- .../PropagationDatabase.cs | 58 +- 6 files changed, 2881 insertions(+), 2787 deletions(-) diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs index 75276f8..0259f8c 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, // indem Sie "*" wie unten gezeigt eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.1")] -[assembly: AssemblyFileVersion("1.3.3.1")] +[assembly: AssemblyVersion("1.3.3.4")] +[assembly: AssemblyFileVersion("1.3.3.4")] diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs index b3bf035..e3bb157 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/TLS.cs @@ -74,7 +74,7 @@ namespace System.Net throw new TimeoutException("Connection timed out."); } while (!trailer.Contains("\r\n")); - Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); + // Console.WriteLine("Reading content [" + contentlength.ToString() + " bytes]: " + resp); response += resp; return true; } @@ -91,50 +91,57 @@ namespace System.Net int contentlength = 0; // chunked transfer, first line should contain content length // read stream bytewise until CRLF is detected - do + try { - count = stream.Read(buff, 0, buff.Length); - strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); + do + { + count = stream.Read(buff, 0, buff.Length); + strcontentlength += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!strcontentlength.Contains("\r\n")); + strcontentlength = strcontentlength.Replace("\r\n", ""); + contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); + // finished reading all chunks + if (contentlength == 0) + { + Console.WriteLine("Reading chunked content finished"); + return true; + } + int bytesread = 0; + // read content bytewise + while (bytesread < contentlength) + { + bytesread += stream.Read(buff, 0, buff.Length); + // add it to response + resp += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + string trailer = ""; + // reassign buffer + buff = new byte[1]; + // read stream bytewise until CRLFCRLF is detected, should be the next two bytes + do + { + count = stream.Read(buff, 0, buff.Length); + trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); + if (st.ElapsedMilliseconds > timeout) + throw new TimeoutException("Connection timed out."); + } + while (!trailer.Contains("\r\n")); } - while (!strcontentlength.Contains("\r\n")); - strcontentlength = strcontentlength.Replace("\r\n", ""); - contentlength = int.Parse(strcontentlength, System.Globalization.NumberStyles.HexNumber); - // finished reading all chunks - if (contentlength == 0) + catch (Exception ex) { - Console.WriteLine("Reading chunked content finished"); - return true; + Console.WriteLine("Error while reading chunked content: " + ex.Message); } - int bytesread = 0; - // read content bytewise - while (bytesread < contentlength) - { - bytesread += stream.Read(buff, 0, buff.Length); - // add it to response - resp += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); - } - string trailer = ""; - // reassign buffer - buff = new byte[1]; - // read stream bytewise until CRLFCRLF is detected, should be the next two bytes - do - { - count = stream.Read(buff, 0, buff.Length); - trailer += Encoding.ASCII.GetString(buff, 0, buff.Length); - if (st.ElapsedMilliseconds > timeout) - throw new TimeoutException("Connection timed out."); - } - while (!trailer.Contains("\r\n")); - Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); + // Console.WriteLine("Reading chunked content [" + contentlength.ToString() + " bytes]: " + resp); response += resp; return false; } - public static string DownloadFile (string url, int timeout, string apikey) + public static string DownloadFile(string url, int timeout, string apikey) { string response = ""; Uri uri = null; @@ -209,13 +216,13 @@ namespace System.Net class MyTlsAuthentication : TlsAuthentication { - public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) - { - return null; + public TlsCredentials GetClientCredentials(CertificateRequest certificateRequest) + { + return null; } - public void NotifyServerCertificate(Certificate serverCertificate) - { + public void NotifyServerCertificate(Certificate serverCertificate) + { } } diff --git a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs index afeaffc..79d64c4 100644 --- a/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs +++ b/AirScout.PlaneFeeds.Plugin.VirtualRadarServer/VirtualRadarServer.cs @@ -178,7 +178,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer } -[Export(typeof(IPlaneFeedPlugin))] + [Export(typeof(IPlaneFeedPlugin))] [ExportMetadata("Name", "PlaneFeedPlugin")] public class VirtualRadarServerPlugin : IPlaneFeedPlugin { @@ -297,7 +297,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer APIKey = Settings.APIKey; return; } - + // get AirScout internal key try { @@ -377,7 +377,6 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer { // deserialize JSON dynamic root = JsonConvert.DeserializeObject(json); - // get local time of request in milliseconds DateTime lt = DateTime.UtcNow; long ltime = (long)(lt - new DateTime(1970, 1, 1)).TotalMilliseconds; @@ -410,7 +409,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer { PlaneFeedPluginPlaneInfo plane = new PlaneFeedPluginPlaneInfo(); // get hex first - plane.Hex = ReadPropertyString(ac, "Icao").Trim().Replace("\"",""); + plane.Hex = ReadPropertyString(ac, "Icao").Trim().Replace("\"", ""); // get position plane.Lat = ReadPropertyDouble(ac, "Lat"); plane.Lon = ReadPropertyDouble(ac, "Long"); @@ -549,7 +548,7 @@ namespace AirScout.PlaneFeeds.Plugin.VirtualRadarServer return decrypted; } - [System.Diagnostics.DebuggerNonUserCode] + [System.Diagnostics.DebuggerNonUserCode] private string ReadPropertyString(dynamic o, string propertyname) { string s = null; diff --git a/AirScout/Properties/AssemblyInfo.cs b/AirScout/Properties/AssemblyInfo.cs index 5ca38fb..1df1696 100644 --- a/AirScout/Properties/AssemblyInfo.cs +++ b/AirScout/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern // übernehmen, indem Sie "*" eingeben: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.3.3.6")] -[assembly: AssemblyFileVersion("1.3.3.6")] +[assembly: AssemblyVersion("1.3.3.7")] +[assembly: AssemblyFileVersion("1.3.3.7")] diff --git a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs index a862b73..37e5c83 100644 --- a/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs +++ b/GreatMaps/GMap.NET.WindowsForms/GMap.NET.WindowsForms/GMapControl.cs @@ -1,287 +1,287 @@  namespace GMap.NET.WindowsForms { - using System; - using System.ComponentModel; - using System.Drawing; - using System.Drawing.Drawing2D; - using System.Drawing.Imaging; - using System.IO; - using System.Threading; - using System.Windows.Forms; - using GMap.NET; - using GMap.NET.Internals; - using GMap.NET.ObjectModel; - using System.Diagnostics; - using System.Drawing.Text; - using GMap.NET.MapProviders; + using System; + using System.ComponentModel; + using System.Drawing; + using System.Drawing.Drawing2D; + using System.Drawing.Imaging; + using System.IO; + using System.Threading; + using System.Windows.Forms; + using GMap.NET; + using GMap.NET.Internals; + using GMap.NET.ObjectModel; + using System.Diagnostics; + using System.Drawing.Text; + using GMap.NET.MapProviders; #if !PocketPC - using System.Runtime.Serialization.Formatters.Binary; - using System.Collections.Generic; - using GMap.NET.Projections; + using System.Runtime.Serialization.Formatters.Binary; + using System.Collections.Generic; + using GMap.NET.Projections; #else using OpenNETCF.ComponentModel; #endif - /// - /// GMap.NET control for Windows Forms - /// - public partial class GMapControl : UserControl, Interface - { + /// + /// GMap.NET control for Windows Forms + /// + public partial class GMapControl : UserControl, Interface + { #if !PocketPC - /// - /// occurs when clicked on marker - /// - public event MarkerClick OnMarkerClick; + /// + /// occurs when clicked on marker + /// + public event MarkerClick OnMarkerClick; - /// - /// occurs when clicked on polygon - /// - public event PolygonClick OnPolygonClick; + /// + /// occurs when clicked on polygon + /// + public event PolygonClick OnPolygonClick; - /// - /// occurs when clicked on route - /// - public event RouteClick OnRouteClick; + /// + /// occurs when clicked on route + /// + public event RouteClick OnRouteClick; - /// - /// occurs on mouse enters route area - /// - public event RouteEnter OnRouteEnter; + /// + /// occurs on mouse enters route area + /// + public event RouteEnter OnRouteEnter; - /// - /// occurs on mouse leaves route area - /// - public event RouteLeave OnRouteLeave; + /// + /// occurs on mouse leaves route area + /// + public event RouteLeave OnRouteLeave; - /// - /// occurs when mouse selection is changed - /// - public event SelectionChange OnSelectionChange; + /// + /// occurs when mouse selection is changed + /// + public event SelectionChange OnSelectionChange; #endif - /// - /// occurs on mouse enters marker area - /// - public event MarkerEnter OnMarkerEnter; + /// + /// occurs on mouse enters marker area + /// + public event MarkerEnter OnMarkerEnter; - /// - /// occurs on mouse leaves marker area - /// - public event MarkerLeave OnMarkerLeave; + /// + /// occurs on mouse leaves marker area + /// + public event MarkerLeave OnMarkerLeave; - /// - /// occurs on mouse enters Polygon area - /// - public event PolygonEnter OnPolygonEnter; + /// + /// occurs on mouse enters Polygon area + /// + public event PolygonEnter OnPolygonEnter; - /// - /// occurs on mouse leaves Polygon area - /// - public event PolygonLeave OnPolygonLeave; + /// + /// occurs on mouse leaves Polygon area + /// + public event PolygonLeave OnPolygonLeave; - /// - /// list of overlays, should be thread safe - /// - public readonly ObservableCollectionThreadSafe Overlays = new ObservableCollectionThreadSafe(); + /// + /// list of overlays, should be thread safe + /// + public readonly ObservableCollectionThreadSafe Overlays = new ObservableCollectionThreadSafe(); - /// - /// max zoom - /// - [Category("GMap.NET")] - [Description("maximum zoom level of map")] - public int MaxZoom - { - get - { - return Core.maxZoom; - } - set - { - Core.maxZoom = value; - } - } + /// + /// max zoom + /// + [Category("GMap.NET")] + [Description("maximum zoom level of map")] + public int MaxZoom + { + get + { + return Core.maxZoom; + } + set + { + Core.maxZoom = value; + } + } - /// - /// min zoom - /// - [Category("GMap.NET")] - [Description("minimum zoom level of map")] - public int MinZoom - { - get - { - return Core.minZoom; - } - set - { - Core.minZoom = value; - } - } + /// + /// min zoom + /// + [Category("GMap.NET")] + [Description("minimum zoom level of map")] + public int MinZoom + { + get + { + return Core.minZoom; + } + set + { + Core.minZoom = value; + } + } - /// - /// map zooming type for mouse wheel - /// - [Category("GMap.NET")] - [Description("map zooming type for mouse wheel")] - public MouseWheelZoomType MouseWheelZoomType - { - get - { - return Core.MouseWheelZoomType; - } - set - { - Core.MouseWheelZoomType = value; - } - } + /// + /// map zooming type for mouse wheel + /// + [Category("GMap.NET")] + [Description("map zooming type for mouse wheel")] + public MouseWheelZoomType MouseWheelZoomType + { + get + { + return Core.MouseWheelZoomType; + } + set + { + Core.MouseWheelZoomType = value; + } + } - /// - /// text on empty tiles - /// - public string EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region."; + /// + /// text on empty tiles + /// + public string EmptyTileText = "We are sorry, but we don't\nhave imagery at this zoom\nlevel for this region."; - /// - /// pen for empty tile borders - /// + /// + /// pen for empty tile borders + /// #if !PocketPC - public Pen EmptyTileBorders = new Pen(Brushes.White, 1); + public Pen EmptyTileBorders = new Pen(Brushes.White, 1); #else public Pen EmptyTileBorders = new Pen(Color.White, 1); #endif - public bool ShowCenter = true; + public bool ShowCenter = true; - /// - /// pen for scale info - /// + /// + /// pen for scale info + /// #if !PocketPC - public Pen ScalePen = new Pen(Brushes.Blue, 1); - public Pen CenterPen = new Pen(Brushes.Red, 1); + public Pen ScalePen = new Pen(Brushes.Blue, 1); + public Pen CenterPen = new Pen(Brushes.Red, 1); #else public Pen ScalePen = new Pen(Color.Blue, 1); public Pen CenterPen = new Pen(Color.Red, 1); #endif #if !PocketPC - /// - /// area selection pen - /// - public Pen SelectionPen = new Pen(Brushes.Blue, 2); + /// + /// area selection pen + /// + public Pen SelectionPen = new Pen(Brushes.Blue, 2); - Brush SelectedAreaFill = new SolidBrush(Color.FromArgb(33, Color.RoyalBlue)); - Color selectedAreaFillColor = Color.FromArgb(33, Color.RoyalBlue); + Brush SelectedAreaFill = new SolidBrush(Color.FromArgb(33, Color.RoyalBlue)); + Color selectedAreaFillColor = Color.FromArgb(33, Color.RoyalBlue); - /// - /// background of selected area - /// - [Category("GMap.NET")] - [Description("background color od the selected area")] - public Color SelectedAreaFillColor - { - get - { - return selectedAreaFillColor; - } - set - { - if(selectedAreaFillColor != value) + /// + /// background of selected area + /// + [Category("GMap.NET")] + [Description("background color od the selected area")] + public Color SelectedAreaFillColor + { + get { - selectedAreaFillColor = value; - - if(SelectedAreaFill != null) - { - SelectedAreaFill.Dispose(); - SelectedAreaFill = null; - } - SelectedAreaFill = new SolidBrush(selectedAreaFillColor); + return selectedAreaFillColor; } - } - } - - HelperLineOptions helperLineOption = HelperLineOptions.DontShow; - - /// - /// draw lines at the mouse pointer position - /// - [Browsable(false)] - public HelperLineOptions HelperLineOption - { - get - { - return helperLineOption; - } - set - { - helperLineOption = value; - renderHelperLine = (helperLineOption == HelperLineOptions.ShowAlways); - if(Core.IsStarted) + set { - Invalidate(); + if (selectedAreaFillColor != value) + { + selectedAreaFillColor = value; + + if (SelectedAreaFill != null) + { + SelectedAreaFill.Dispose(); + SelectedAreaFill = null; + } + SelectedAreaFill = new SolidBrush(selectedAreaFillColor); + } } - } - } + } - public Pen HelperLinePen = new Pen(Color.Blue, 1); - bool renderHelperLine = false; + HelperLineOptions helperLineOption = HelperLineOptions.DontShow; - protected override void OnKeyDown(KeyEventArgs e) - { - if(HelperLineOption == HelperLineOptions.ShowOnModifierKey) - { - renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); - if(renderHelperLine) + /// + /// draw lines at the mouse pointer position + /// + [Browsable(false)] + public HelperLineOptions HelperLineOption + { + get { - Invalidate(); + return helperLineOption; } - } - base.OnKeyDown(e); - } - - protected override void OnKeyUp(KeyEventArgs e) - { - if(HelperLineOption == HelperLineOptions.ShowOnModifierKey) - { - renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); - if(!renderHelperLine) + set { - Invalidate(); + helperLineOption = value; + renderHelperLine = (helperLineOption == HelperLineOptions.ShowAlways); + if (Core.IsStarted) + { + Invalidate(); + } } - } - base.OnKeyUp(e); - } + } + + public Pen HelperLinePen = new Pen(Color.Blue, 1); + bool renderHelperLine = false; + + protected override void OnKeyDown(KeyEventArgs e) + { + if (HelperLineOption == HelperLineOptions.ShowOnModifierKey) + { + renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); + if (renderHelperLine) + { + Invalidate(); + } + } + base.OnKeyDown(e); + } + + protected override void OnKeyUp(KeyEventArgs e) + { + if (HelperLineOption == HelperLineOptions.ShowOnModifierKey) + { + renderHelperLine = (e.Modifiers == Keys.Shift || e.Modifiers == Keys.Alt); + if (!renderHelperLine) + { + Invalidate(); + } + } + base.OnKeyUp(e); + } #endif - Brush EmptytileBrush = new SolidBrush(Color.Navy); - Color emptyTileColor = Color.Navy; + Brush EmptytileBrush = new SolidBrush(Color.Navy); + Color emptyTileColor = Color.Navy; - /// - /// color of empty tile background - /// - [Category("GMap.NET")] - [Description("background color of the empty tile")] - public Color EmptyTileColor - { - get - { - return emptyTileColor; - } - set - { - if(emptyTileColor != value) + /// + /// color of empty tile background + /// + [Category("GMap.NET")] + [Description("background color of the empty tile")] + public Color EmptyTileColor + { + get { - emptyTileColor = value; - - if(EmptytileBrush != null) - { - EmptytileBrush.Dispose(); - EmptytileBrush = null; - } - EmptytileBrush = new SolidBrush(emptyTileColor); + return emptyTileColor; } - } - } + set + { + if (emptyTileColor != value) + { + emptyTileColor = value; + + if (EmptytileBrush != null) + { + EmptytileBrush.Dispose(); + EmptytileBrush = null; + } + EmptytileBrush = new SolidBrush(emptyTileColor); + } + } + } #if PocketPC readonly Brush TileGridLinesTextBrush = new SolidBrush(Color.Red); @@ -289,463 +289,533 @@ namespace GMap.NET.WindowsForms readonly Brush CopyrightBrush = new SolidBrush(Color.Navy); #endif - /// - /// show map scale info - /// - public bool MapScaleInfoEnabled = false; + /// + /// show map scale info + /// + public bool MapScaleInfoEnabled = false; - /// - /// enables filling empty tiles using lower level images - /// - public bool FillEmptyTiles = true; + /// + /// enables filling empty tiles using lower level images + /// + public bool FillEmptyTiles = true; - /// - /// if true, selects area just by holding mouse and moving - /// - public bool DisableAltForSelection = false; + /// + /// if true, selects area just by holding mouse and moving + /// + public bool DisableAltForSelection = false; - /// - /// retry count to get tile - /// - [Browsable(false)] - public int RetryLoadTile - { - get - { - return Core.RetryLoadTile; - } - set - { - Core.RetryLoadTile = value; - } - } - - /// - /// how many levels of tiles are staying decompresed in memory - /// - [Browsable(true)] - public int LevelsKeepInMemmory - { - get - { - return Core.LevelsKeepInMemmory; - } - - set - { - Core.LevelsKeepInMemmory = value; - } - } - - /// - /// map dragg button - /// - [Category("GMap.NET")] - public MouseButtons DragButton = MouseButtons.Right; - - private bool showTileGridLines = false; - - /// - /// shows tile gridlines - /// - [Category("GMap.NET")] - [Description("shows tile gridlines")] - public bool ShowTileGridLines - { - get - { - return showTileGridLines; - } - set - { - showTileGridLines = value; - Invalidate(); - } - } - - /// - /// current selected area in map - /// - private RectLatLng selectedArea; - - [Browsable(false)] - public RectLatLng SelectedArea - { - get - { - return selectedArea; - } - set - { - selectedArea = value; - - if(Core.IsStarted) + /// + /// retry count to get tile + /// + [Browsable(false)] + public int RetryLoadTile + { + get { - Invalidate(); + return Core.RetryLoadTile; } - } - } + set + { + Core.RetryLoadTile = value; + } + } - /// - /// map boundaries - /// - public RectLatLng? BoundsOfMap = null; + /// + /// how many levels of tiles are staying decompresed in memory + /// + [Browsable(true)] + public int LevelsKeepInMemmory + { + get + { + return Core.LevelsKeepInMemmory; + } - /// - /// enables integrated DoubleBuffer for running on windows mobile - /// + set + { + Core.LevelsKeepInMemmory = value; + } + } + + /// + /// map dragg button + /// + [Category("GMap.NET")] + public MouseButtons DragButton = MouseButtons.Right; + + private bool showTileGridLines = false; + + /// + /// shows tile gridlines + /// + [Category("GMap.NET")] + [Description("shows tile gridlines")] + public bool ShowTileGridLines + { + get + { + return showTileGridLines; + } + set + { + showTileGridLines = value; + Invalidate(); + } + } + + /// + /// current selected area in map + /// + private RectLatLng selectedArea; + + [Browsable(false)] + public RectLatLng SelectedArea + { + get + { + return selectedArea; + } + set + { + selectedArea = value; + + if (Core.IsStarted) + { + Invalidate(); + } + } + } + + /// + /// map boundaries + /// + public RectLatLng? BoundsOfMap = null; + + /// + /// enables integrated DoubleBuffer for running on windows mobile + /// #if !PocketPC - public bool ForceDoubleBuffer = false; - readonly bool MobileMode = false; + public bool ForceDoubleBuffer = false; + readonly bool MobileMode = false; #else readonly bool ForceDoubleBuffer = true; #endif - /// - /// stops immediate marker/route/polygon invalidations; - /// call Refresh to perform single refresh and reset invalidation state - /// - public bool HoldInvalidation = false; + /// + /// stops immediate marker/route/polygon invalidations; + /// call Refresh to perform single refresh and reset invalidation state + /// + public bool HoldInvalidation = false; - /// - /// call this to stop HoldInvalidation and perform single forced instant refresh - /// - public override void Refresh() - { - HoldInvalidation = false; + /// + /// call this to stop HoldInvalidation and perform single forced instant refresh + /// + public override void Refresh() + { + HoldInvalidation = false; - lock(Core.invalidationLock) - { - Core.lastInvalidation = DateTime.Now; - } + lock (Core.invalidationLock) + { + Core.lastInvalidation = DateTime.Now; + } - base.Refresh(); - } + base.Refresh(); + } #if !DESIGN - /// - /// enque built-in thread safe invalidation - /// - public new void Invalidate() - { - if(Core.Refresh != null) - { - Core.Refresh.Set(); - } - } -#endif - -#if !PocketPC - private bool _GrayScale = false; - - [Category("GMap.NET")] - public bool GrayScaleMode - { - get - { - return _GrayScale; - } - set - { - _GrayScale = value; - ColorMatrix = (value == true ? ColorMatrixs.GrayScale : null); - } - } - - private bool _Negative = false; - - [Category("GMap.NET")] - public bool NegativeMode - { - get - { - return _Negative; - } - set - { - _Negative = value; - ColorMatrix = (value == true ? ColorMatrixs.Negative : null); - } - } - - ColorMatrix colorMatrix; - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public ColorMatrix ColorMatrix - { - get - { - return colorMatrix; - } - set - { - colorMatrix = value; - if(GMapProvider.TileImageProxy != null && GMapProvider.TileImageProxy is WindowsFormsImageProxy) + /// + /// enque built-in thread safe invalidation + /// + public new void Invalidate() + { + if (Core.Refresh != null) { - (GMapProvider.TileImageProxy as WindowsFormsImageProxy).ColorMatrix = value; - if(Core.IsStarted) - { - ReloadMap(); - } + Core.Refresh.Set(); } - } - } + } #endif - // internal stuff - internal readonly Core Core = new Core(); - - internal readonly Font CopyrightFont = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Regular); #if !PocketPC - internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold); + private bool _GrayScale = false; + + [Category("GMap.NET")] + public bool GrayScaleMode + { + get + { + return _GrayScale; + } + set + { + _GrayScale = value; + ColorMatrix = (value == true ? ColorMatrixs.GrayScale : null); + } + } + + private bool _Negative = false; + + [Category("GMap.NET")] + public bool NegativeMode + { + get + { + return _Negative; + } + set + { + _Negative = value; + ColorMatrix = (value == true ? ColorMatrixs.Negative : null); + } + } + + ColorMatrix colorMatrix; + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public ColorMatrix ColorMatrix + { + get + { + return colorMatrix; + } + set + { + colorMatrix = value; + if (GMapProvider.TileImageProxy != null && GMapProvider.TileImageProxy is WindowsFormsImageProxy) + { + (GMapProvider.TileImageProxy as WindowsFormsImageProxy).ColorMatrix = value; + if (Core.IsStarted) + { + ReloadMap(); + } + } + } + } +#endif + + private double _Opacity = 1.0; + public double Opacity + { + get + { + return _Opacity; + } + set + { + _Opacity = value; + if (Core.IsStarted) + { + ReloadMap(); + } + } + } + + // internal stuff + internal readonly Core Core = new Core(); + + internal readonly Font CopyrightFont = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Regular); +#if !PocketPC + internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 11, FontStyle.Bold); #else internal readonly Font MissingDataFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular); #endif - // geändert 29.11.2012 DL2ALF - Font ScaleFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold); -// Font ScaleFont = new Font(FontFamily.GenericSansSerif, 5, FontStyle.Italic); - internal readonly StringFormat CenterFormat = new StringFormat(); - internal readonly StringFormat BottomFormat = new StringFormat(); + // geändert 29.11.2012 DL2ALF + Font ScaleFont = new Font(FontFamily.GenericSansSerif, 8, FontStyle.Bold); + // Font ScaleFont = new Font(FontFamily.GenericSansSerif, 5, FontStyle.Italic); + internal readonly StringFormat CenterFormat = new StringFormat(); + internal readonly StringFormat BottomFormat = new StringFormat(); #if !PocketPC - readonly ImageAttributes TileFlipXYAttributes = new ImageAttributes(); + readonly ImageAttributes TileFlipXYAttributes = new ImageAttributes(); #endif - double zoomReal; - Bitmap backBuffer; - Graphics gxOff; + double zoomReal; + Bitmap backBuffer; + Graphics gxOff; #if !DESIGN - /// - /// construct - /// - public GMapControl() - { + /// + /// construct + /// + public GMapControl() + { #if !PocketPC - if(!DesignModeInConstruct && !IsDesignerHosted) + if (!DesignModeInConstruct && !IsDesignerHosted) #endif - { + { #if !PocketPC - Manager.SQLitePing(); + Manager.SQLitePing(); - this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); - this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); - this.SetStyle(ControlStyles.UserPaint, true); - this.SetStyle(ControlStyles.Opaque, true); - ResizeRedraw = true; + this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true); + this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); + this.SetStyle(ControlStyles.UserPaint, true); + // this.SetStyle(ControlStyles.Opaque, true); + this.SetStyle(ControlStyles.Opaque, false); + ResizeRedraw = true; - TileFlipXYAttributes.SetWrapMode(WrapMode.TileFlipXY); + TileFlipXYAttributes.SetWrapMode(WrapMode.TileFlipXY); - // only one mode will be active, to get mixed mode create new ColorMatrix - GrayScaleMode = GrayScaleMode; - NegativeMode = NegativeMode; + // only one mode will be active, to get mixed mode create new ColorMatrix + GrayScaleMode = GrayScaleMode; + NegativeMode = NegativeMode; #endif - GMapProvider.TileImageProxy = WindowsFormsImageProxy.Instance; + GMapProvider.TileImageProxy = WindowsFormsImageProxy.Instance; - Core.SystemType = "WindowsForms"; + Core.SystemType = "WindowsForms"; - RenderMode = RenderMode.GDI_PLUS; + RenderMode = RenderMode.GDI_PLUS; - CenterFormat.Alignment = StringAlignment.Center; - CenterFormat.LineAlignment = StringAlignment.Center; + CenterFormat.Alignment = StringAlignment.Center; + CenterFormat.LineAlignment = StringAlignment.Center; - BottomFormat.Alignment = StringAlignment.Center; + BottomFormat.Alignment = StringAlignment.Center; #if !PocketPC - BottomFormat.LineAlignment = StringAlignment.Far; + BottomFormat.LineAlignment = StringAlignment.Far; #endif - if(GMaps.Instance.IsRunningOnMono) - { - // no imports to move pointer - MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter; - } + if (GMaps.Instance.IsRunningOnMono) + { + // no imports to move pointer + MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionWithoutCenter; + } - Overlays.CollectionChanged += new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); - } - } - - void Overlays_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - if(e.NewItems != null) - { - foreach(GMapOverlay obj in e.NewItems) - { - if(obj != null) - { - obj.Control = this; - } + Overlays.CollectionChanged += new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); } + } - if(Core.IsStarted && !HoldInvalidation) + void Overlays_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) + { + if (e.NewItems != null) { - Invalidate(); + foreach (GMapOverlay obj in e.NewItems) + { + if (obj != null) + { + obj.Control = this; + } + } + + if (Core.IsStarted && !HoldInvalidation) + { + Invalidate(); + } } - } - } + } #endif - void invalidatorEngage(object sender, ProgressChangedEventArgs e) - { - base.Invalidate(); - } + void invalidatorEngage(object sender, ProgressChangedEventArgs e) + { + base.Invalidate(); + } - /// - /// update objects when map is draged/zoomed - /// - internal void ForceUpdateOverlays() - { - try - { - HoldInvalidation = true; - - foreach(GMapOverlay o in Overlays) + /// + /// update objects when map is draged/zoomed + /// + internal void ForceUpdateOverlays() + { + try { - if(o.IsVisibile) - { - o.ForceUpdate(); - } + HoldInvalidation = true; + + foreach (GMapOverlay o in Overlays) + { + if (o.IsVisibile) + { + o.ForceUpdate(); + } + } } - } - finally - { - Refresh(); - } - } - - /// - /// render map in GDI+ - /// - /// - void DrawMap(Graphics g) - { - if(Core.updatingBounds || MapProvider == EmptyProvider.Instance || MapProvider == null) - { - Debug.WriteLine("Core.updatingBounds"); - return; - } - - Core.tileDrawingListLock.AcquireReaderLock(); - Core.Matrix.EnterReadLock(); - try - { - foreach(var tilePoint in Core.tileDrawingList) + finally { - { - Core.tileRect.Location = tilePoint.PosPixel; - if(ForceDoubleBuffer) - { + Refresh(); + } + } + + private const int bytesPerPixel = 4; + + /// + /// method for changing the opacity of an image + /// + /// image to set opacity on + /// percentage of opacity + /// + public Image SetImageOpacity(Image image, double opacity) + { + try + { + //create a Bitmap the size of the image provided + Bitmap bmp = new Bitmap(image.Width, image.Height); + + //create a graphics object from the image + using (Graphics gfx = Graphics.FromImage(bmp)) + { + + //create a color matrix object + ColorMatrix matrix = new ColorMatrix(); + + //set the opacity + matrix.Matrix33 = (float)opacity; + + //create image attributes + ImageAttributes attributes = new ImageAttributes(); + + //set the color(opacity) of the image + attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); + + //now draw the image + gfx.DrawImage(image, new Rectangle(0, 0, bmp.Width, bmp.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, attributes); + } + return bmp; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + return null; + } + } + /// + /// render map in GDI+ + /// + /// + void DrawMap(Graphics g) + { + if (Core.updatingBounds || MapProvider == EmptyProvider.Instance || MapProvider == null) + { + Debug.WriteLine("Core.updatingBounds"); + return; + } + + Core.tileDrawingListLock.AcquireReaderLock(); + Core.Matrix.EnterReadLock(); + try + { + foreach (var tilePoint in Core.tileDrawingList) + { + { + Core.tileRect.Location = tilePoint.PosPixel; + if (ForceDoubleBuffer) + { #if !PocketPC - if(MobileMode) - { - Core.tileRect.Offset(Core.renderOffset); - } + if (MobileMode) + { + Core.tileRect.Offset(Core.renderOffset); + } #else Core.tileRect.Offset(Core.renderOffset); #endif - } - Core.tileRect.OffsetNegative(Core.compensationOffset); + } + Core.tileRect.OffsetNegative(Core.compensationOffset); - //if(Core.currentRegion.IntersectsWith(Core.tileRect) || IsRotated) - { - bool found = false; - - Tile t = Core.Matrix.GetTileWithNoLock(Core.Zoom, tilePoint.PosXY); - if(t.NotEmpty) - { - // render tile + //if(Core.currentRegion.IntersectsWith(Core.tileRect) || IsRotated) { - foreach(WindowsFormsImage img in t.Overlays) - { - try - { - if (img != null && img.Img != null) + bool found = false; + + Tile t = Core.Matrix.GetTileWithNoLock(Core.Zoom, tilePoint.PosXY); + if (t.NotEmpty) + { + // render tile + { + foreach (WindowsFormsImage img in t.Overlays) { - if (!found) - found = true; - - if (!img.IsParent) + if (img != null && img.Img != null) { + if (!found) + found = true; + + if (!img.IsParent) + { #if !PocketPC - g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + // change opacity if < 1.0 + if (Opacity < 1) + { + Image im = SetImageOpacity(img.Img, Opacity); + g.DrawImage(im, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + } + else + { + g.DrawImage(img.Img, Core.tileRect.X, Core.tileRect.Y, Core.tileRectBearing.Width, Core.tileRectBearing.Height); + } #else - g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); + g.DrawImage(img.Img, (int) Core.tileRect.X, (int) Core.tileRect.Y); #endif - } + } #if !PocketPC - else - { - // TODO: move calculations to loader thread - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - } + else + { + // TODO: move calculations to loader thread + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(img.Xoff * (img.Img.Width / img.Ix)), (float)(img.Yoff * (img.Img.Height / img.Ix)), (img.Img.Width / img.Ix), (img.Img.Height / img.Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + // change opacity if < 1.0 + if (Opacity < 1) + { + Image im = SetImageOpacity(img.Img, Opacity); + g.DrawImage(im, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } + else + { + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + } + } #endif + } } - } - catch (Exception ex) - { - Console.WriteLine("GMapControl: Error while drwing Image: " + ex.Message); - } - } - } - } + } + } #if !PocketPC - else if(FillEmptyTiles && MapProvider.Projection is MercatorProjection) - { - #region -- fill empty lines -- - int zoomOffset = 1; - Tile parentTile = Tile.Empty; - long Ix = 0; + else if (FillEmptyTiles && MapProvider.Projection is MercatorProjection) + { + #region -- fill empty lines -- + int zoomOffset = 1; + Tile parentTile = Tile.Empty; + long Ix = 0; - while(!parentTile.NotEmpty && zoomOffset < Core.Zoom && zoomOffset <= LevelsKeepInMemmory) - { - Ix = (long)Math.Pow(2, zoomOffset); - parentTile = Core.Matrix.GetTileWithNoLock(Core.Zoom - zoomOffset++, new GPoint((int)(tilePoint.PosXY.X / Ix), (int)(tilePoint.PosXY.Y / Ix))); - } + while (!parentTile.NotEmpty && zoomOffset < Core.Zoom && zoomOffset <= LevelsKeepInMemmory) + { + Ix = (long)Math.Pow(2, zoomOffset); + parentTile = Core.Matrix.GetTileWithNoLock(Core.Zoom - zoomOffset++, new GPoint((int)(tilePoint.PosXY.X / Ix), (int)(tilePoint.PosXY.Y / Ix))); + } - if(parentTile.NotEmpty) - { - long Xoff = Math.Abs(tilePoint.PosXY.X - (parentTile.Pos.X * Ix)); - long Yoff = Math.Abs(tilePoint.PosXY.Y - (parentTile.Pos.Y * Ix)); + if (parentTile.NotEmpty) + { + long Xoff = Math.Abs(tilePoint.PosXY.X - (parentTile.Pos.X * Ix)); + long Yoff = Math.Abs(tilePoint.PosXY.Y - (parentTile.Pos.Y * Ix)); - // render tile - { - foreach(WindowsFormsImage img in parentTile.Overlays) - { - if(img != null && img.Img != null && !img.IsParent) - { - if(!found) - found = true; + // render tile + { + foreach (WindowsFormsImage img in parentTile.Overlays) + { + if (img != null && img.Img != null && !img.IsParent) + { + if (!found) + found = true; - System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); - System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + System.Drawing.RectangleF srcRect = new System.Drawing.RectangleF((float)(Xoff * (img.Img.Width / Ix)), (float)(Yoff * (img.Img.Height / Ix)), (img.Img.Width / Ix), (img.Img.Height / Ix)); + System.Drawing.Rectangle dst = new System.Drawing.Rectangle((int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); - g.FillRectangle(SelectedAreaFill, dst); - } - } - } - } - #endregion - } + g.DrawImage(img.Img, dst, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, GraphicsUnit.Pixel, TileFlipXYAttributes); + g.FillRectangle(SelectedAreaFill, dst); + } + } + } + } + #endregion + } #endif - // add text if tile is missing - if(!found) - { - lock(Core.FailedLoads) - { - var lt = new LoadTask(tilePoint.PosXY, Core.Zoom); - if(Core.FailedLoads.ContainsKey(lt)) - { - var ex = Core.FailedLoads[lt]; + // add text if tile is missing + if (!found) + { + lock (Core.FailedLoads) + { + var lt = new LoadTask(tilePoint.PosXY, Core.Zoom); + if (Core.FailedLoads.ContainsKey(lt)) + { + var ex = Core.FailedLoads[lt]; #if !PocketPC - g.FillRectangle(EmptytileBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height)); + g.FillRectangle(EmptytileBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height)); - g.DrawString("Exception: " + ex.Message, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X + 11, Core.tileRect.Y + 11, Core.tileRect.Width - 11, Core.tileRect.Height - 11)); + g.DrawString("Exception: " + ex.Message, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X + 11, Core.tileRect.Y + 11, Core.tileRect.Width - 11, Core.tileRect.Height - 11)); - g.DrawString(EmptyTileText, MissingDataFont, Brushes.Blue, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); + g.DrawString(EmptyTileText, MissingDataFont, Brushes.Blue, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #else g.FillRectangle(EmptytileBrush, new System.Drawing.Rectangle((int) Core.tileRect.X, (int) Core.tileRect.Y, (int) Core.tileRect.Width, (int) Core.tileRect.Height)); @@ -755,526 +825,526 @@ namespace GMap.NET.WindowsForms g.DrawString(EmptyTileText, MissingDataFont, TileGridMissingTextBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y + Core.tileRect.Width / 2 + (ShowTileGridLines ? 11 : -22), Core.tileRect.Width, Core.tileRect.Height), BottomFormat); #endif - g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - } - } - } + g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + } + } + } - if(ShowTileGridLines) - { - g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); - { + if (ShowTileGridLines) + { + g.DrawRectangle(EmptyTileBorders, (int)Core.tileRect.X, (int)Core.tileRect.Y, (int)Core.tileRect.Width, (int)Core.tileRect.Height); + { #if !PocketPC - g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "CENTER: " : "TILE: ") + tilePoint, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); + g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "CENTER: " : "TILE: ") + tilePoint, MissingDataFont, Brushes.Red, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #else g.DrawString((tilePoint.PosXY == Core.centerTileXYLocation ? "" : "TILE: ") + tilePoint, MissingDataFont, TileGridLinesTextBrush, new RectangleF(Core.tileRect.X, Core.tileRect.Y, Core.tileRect.Width, Core.tileRect.Height), CenterFormat); #endif + } + } } - } - } - } + } + } } - } - finally - { - Core.Matrix.LeaveReadLock(); - Core.tileDrawingListLock.ReleaseReaderLock(); - } - } - - /// - /// updates markers local position - /// - /// - public void UpdateMarkerLocalPosition(GMapMarker marker) - { - GPoint p = FromLatLngToLocal(marker.Position); - { -#if !PocketPC - if(!MobileMode) + finally { - p.OffsetNegative(Core.renderOffset); + Core.Matrix.LeaveReadLock(); + Core.tileDrawingListLock.ReleaseReaderLock(); } + } + + /// + /// updates markers local position + /// + /// + public void UpdateMarkerLocalPosition(GMapMarker marker) + { + GPoint p = FromLatLngToLocal(marker.Position); + { +#if !PocketPC + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - var f = new System.Drawing.Point((int)(p.X + marker.Offset.X), (int)(p.Y + marker.Offset.Y)); - marker.LocalPosition = f; - } - } + var f = new System.Drawing.Point((int)(p.X + marker.Offset.X), (int)(p.Y + marker.Offset.Y)); + marker.LocalPosition = f; + } + } - /// - /// updates routes local position - /// - /// - public void UpdateRouteLocalPosition(GMapRoute route) - { - route.LocalPoints.Clear(); + /// + /// updates routes local position + /// + /// + public void UpdateRouteLocalPosition(GMapRoute route) + { + route.LocalPoints.Clear(); - foreach(GMap.NET.PointLatLng pg in route.Points) - { - GPoint p = FromLatLngToLocal(pg); + foreach (GMap.NET.PointLatLng pg in route.Points) + { + GPoint p = FromLatLngToLocal(pg); #if !PocketPC - if(!MobileMode) - { - p.OffsetNegative(Core.renderOffset); - } + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - // if(IsRotated) - // { - //#if !PocketPC - // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; - // rotationMatrix.TransformPoints(tt); - // var f = tt[0]; + // if(IsRotated) + // { + //#if !PocketPC + // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; + // rotationMatrix.TransformPoints(tt); + // var f = tt[0]; - // p.X = f.X; - // p.Y = f.Y; - //#endif - // } + // p.X = f.X; + // p.Y = f.Y; + //#endif + // } - route.LocalPoints.Add(p); - } -#if !PocketPC - route.UpdateGraphicsPath(); -#endif - } - - /// - /// updates polygons local position - /// - /// - public void UpdatePolygonLocalPosition(GMapPolygon polygon) - { - polygon.LocalPoints.Clear(); - - foreach(GMap.NET.PointLatLng pg in polygon.Points) - { - GPoint p = FromLatLngToLocal(pg); - -#if !PocketPC - if(!MobileMode) - { - p.OffsetNegative(Core.renderOffset); + route.LocalPoints.Add(p); } +#if !PocketPC + route.UpdateGraphicsPath(); +#endif + } + + /// + /// updates polygons local position + /// + /// + public void UpdatePolygonLocalPosition(GMapPolygon polygon) + { + polygon.LocalPoints.Clear(); + + foreach (GMap.NET.PointLatLng pg in polygon.Points) + { + GPoint p = FromLatLngToLocal(pg); + +#if !PocketPC + if (!MobileMode) + { + p.OffsetNegative(Core.renderOffset); + } #endif - // if(IsRotated) - // { - //#if !PocketPC - // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; - // rotationMatrix.TransformPoints(tt); - // var f = tt[0]; + // if(IsRotated) + // { + //#if !PocketPC + // System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(p.X, p.Y) }; + // rotationMatrix.TransformPoints(tt); + // var f = tt[0]; - // p.X = f.X; - // p.Y = f.Y; - //#endif - // } + // p.X = f.X; + // p.Y = f.Y; + //#endif + // } - polygon.LocalPoints.Add(p); - } - } - - /// - /// sets zoom to max to fit rect - /// - /// - /// - public bool SetZoomToFitRect(RectLatLng rect) - { - if(lazyEvents) - { - lazySetZoomToFitRect = rect; - } - else - { - int maxZoom = Core.GetMaxZoomToFitRect(rect); - if(maxZoom > 0) - { - PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2)); - Position = center; - - if(maxZoom > MaxZoom) - { - maxZoom = MaxZoom; - } - - if((int)Zoom != maxZoom) - { - Zoom = maxZoom; - } - - return true; + polygon.LocalPoints.Add(p); } - } + } - return false; - } - - RectLatLng? lazySetZoomToFitRect = null; - bool lazyEvents = true; - - /// - /// sets to max zoom to fit all markers and centers them in map - /// - /// overlay id or null to check all - /// - public bool ZoomAndCenterMarkers(string overlayId) - { - RectLatLng? rect = GetRectOfAllMarkers(overlayId); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// zooms and centers all route - /// - /// overlay id or null to check all - /// - public bool ZoomAndCenterRoutes(string overlayId) - { - RectLatLng? rect = GetRectOfAllRoutes(overlayId); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// zooms and centers route - /// - /// - /// - public bool ZoomAndCenterRoute(MapRoute route) - { - RectLatLng? rect = GetRectOfRoute(route); - if(rect.HasValue) - { - return SetZoomToFitRect(rect.Value); - } - - return false; - } - - /// - /// gets rectangle with all objects inside - /// - /// overlay id or null to check all - /// - public RectLatLng? GetRectOfAllMarkers(string overlayId) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - foreach(GMapOverlay o in Overlays) - { - if(overlayId == null || o.Id == overlayId) + /// + /// sets zoom to max to fit rect + /// + /// + /// + public bool SetZoomToFitRect(RectLatLng rect) + { + if (lazyEvents) { - if(o.IsVisibile && o.Markers.Count > 0) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible) - { - // left - if(m.Position.Lng < left) - { - left = m.Position.Lng; - } - - // top - if(m.Position.Lat > top) - { - top = m.Position.Lat; - } - - // right - if(m.Position.Lng > right) - { - right = m.Position.Lng; - } - - // bottom - if(m.Position.Lat < bottom) - { - bottom = m.Position.Lat; - } - } - } - } - } - } - - if(left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) - { - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - - return ret; - } - - /// - /// gets rectangle with all objects inside - /// - /// overlay id or null to check all - /// - public RectLatLng? GetRectOfAllRoutes(string overlayId) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - foreach(GMapOverlay o in Overlays) - { - if(overlayId == null || o.Id == overlayId) - { - if(o.IsVisibile && o.Routes.Count > 0) - { - foreach(GMapRoute route in o.Routes) - { - if(route.IsVisible && route.From.HasValue && route.To.HasValue) - { - foreach(PointLatLng p in route.Points) - { - // left - if(p.Lng < left) - { - left = p.Lng; - } - - // top - if(p.Lat > top) - { - top = p.Lat; - } - - // right - if(p.Lng > right) - { - right = p.Lng; - } - - // bottom - if(p.Lat < bottom) - { - bottom = p.Lat; - } - } - } - } - } - } - } - - if(left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) - { - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - - return ret; - } - - /// - /// gets rect of route - /// - /// - /// - public RectLatLng? GetRectOfRoute(MapRoute route) - { - RectLatLng? ret = null; - - double left = double.MaxValue; - double top = double.MinValue; - double right = double.MinValue; - double bottom = double.MaxValue; - - if(route.From.HasValue && route.To.HasValue) - { - foreach(PointLatLng p in route.Points) - { - // left - if(p.Lng < left) - { - left = p.Lng; - } - - // top - if(p.Lat > top) - { - top = p.Lat; - } - - // right - if(p.Lng > right) - { - right = p.Lng; - } - - // bottom - if(p.Lat < bottom) - { - bottom = p.Lat; - } - } - ret = RectLatLng.FromLTRB(left, top, right, bottom); - } - return ret; - } - -#if !PocketPC - /// - /// gets image of the current view - /// - /// - public Image ToImage() - { - Image ret = null; - try - { - using(Bitmap bitmap = new Bitmap(Width, Height)) - { - using(Graphics g = Graphics.FromImage(bitmap)) - { - using(Graphics gg = this.CreateGraphics()) - { -#if !PocketPC - g.CopyFromScreen(PointToScreen(new System.Drawing.Point()).X, PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(Width, Height)); -#else - throw new NotImplementedException("Not implemeted for PocketPC"); -#endif - } - } - - // Convert the Image to a png - using(MemoryStream ms = new MemoryStream()) - { - bitmap.Save(ms, ImageFormat.Png); -#if !PocketPC - ret = Image.FromStream(ms); -#else - throw new NotImplementedException("Not implemeted for PocketPC"); -#endif - } - } - } - catch - { - ret = null; - } - return ret; - } -#endif - - /// - /// offset position in pixels - /// - /// - /// - public void Offset(int x, int y) - { - if(IsHandleCreated) - { - // need to fix in rotated mode usinf rotationMatrix - // ... - Core.DragOffset(new GPoint(x, y)); - - ForceUpdateOverlays(); - } - } - - #region UserControl Events - -#if !PocketPC - protected bool DesignModeInConstruct - { - get - { - return (LicenseManager.UsageMode == LicenseUsageMode.Designtime); - } - } - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsDesignerHosted - { - get - { - return IsControlDesignerHosted(this); - } - } - - public bool IsControlDesignerHosted(Control ctrl) - { - if(ctrl != null) - { - if(ctrl.Site != null) - { - - if(ctrl.Site.DesignMode == true) - return true; - - else - { - if(IsControlDesignerHosted(ctrl.Parent)) - return true; - - else - return false; - } + lazySetZoomToFitRect = rect; } else { - if(IsControlDesignerHosted(ctrl.Parent)) - return true; - else - return false; + int maxZoom = Core.GetMaxZoomToFitRect(rect); + if (maxZoom > 0) + { + PointLatLng center = new PointLatLng(rect.Lat - (rect.HeightLat / 2), rect.Lng + (rect.WidthLng / 2)); + Position = center; + + if (maxZoom > MaxZoom) + { + maxZoom = MaxZoom; + } + + if ((int)Zoom != maxZoom) + { + Zoom = maxZoom; + } + + return true; + } } - } - else + return false; - } + } - protected override void OnLoad(EventArgs e) - { - base.OnLoad(e); + RectLatLng? lazySetZoomToFitRect = null; + bool lazyEvents = true; - if(!IsDesignerHosted) - { - //MethodInvoker m = delegate - //{ - // Thread.Sleep(444); - - //OnSizeChanged(null); - - if(lazyEvents) + /// + /// sets to max zoom to fit all markers and centers them in map + /// + /// overlay id or null to check all + /// + public bool ZoomAndCenterMarkers(string overlayId) + { + RectLatLng? rect = GetRectOfAllMarkers(overlayId); + if (rect.HasValue) { - lazyEvents = false; - - if(lazySetZoomToFitRect.HasValue) - { - SetZoomToFitRect(lazySetZoomToFitRect.Value); - lazySetZoomToFitRect = null; - } + return SetZoomToFitRect(rect.Value); } - Core.OnMapOpen().ProgressChanged += new ProgressChangedEventHandler(invalidatorEngage); - ForceUpdateOverlays(); - //}; - //this.BeginInvoke(m); - } - } + + return false; + } + + /// + /// zooms and centers all route + /// + /// overlay id or null to check all + /// + public bool ZoomAndCenterRoutes(string overlayId) + { + RectLatLng? rect = GetRectOfAllRoutes(overlayId); + if (rect.HasValue) + { + return SetZoomToFitRect(rect.Value); + } + + return false; + } + + /// + /// zooms and centers route + /// + /// + /// + public bool ZoomAndCenterRoute(MapRoute route) + { + RectLatLng? rect = GetRectOfRoute(route); + if (rect.HasValue) + { + return SetZoomToFitRect(rect.Value); + } + + return false; + } + + /// + /// gets rectangle with all objects inside + /// + /// overlay id or null to check all + /// + public RectLatLng? GetRectOfAllMarkers(string overlayId) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + foreach (GMapOverlay o in Overlays) + { + if (overlayId == null || o.Id == overlayId) + { + if (o.IsVisibile && o.Markers.Count > 0) + { + foreach (GMapMarker m in o.Markers) + { + if (m.IsVisible) + { + // left + if (m.Position.Lng < left) + { + left = m.Position.Lng; + } + + // top + if (m.Position.Lat > top) + { + top = m.Position.Lat; + } + + // right + if (m.Position.Lng > right) + { + right = m.Position.Lng; + } + + // bottom + if (m.Position.Lat < bottom) + { + bottom = m.Position.Lat; + } + } + } + } + } + } + + if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) + { + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + + return ret; + } + + /// + /// gets rectangle with all objects inside + /// + /// overlay id or null to check all + /// + public RectLatLng? GetRectOfAllRoutes(string overlayId) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + foreach (GMapOverlay o in Overlays) + { + if (overlayId == null || o.Id == overlayId) + { + if (o.IsVisibile && o.Routes.Count > 0) + { + foreach (GMapRoute route in o.Routes) + { + if (route.IsVisible && route.From.HasValue && route.To.HasValue) + { + foreach (PointLatLng p in route.Points) + { + // left + if (p.Lng < left) + { + left = p.Lng; + } + + // top + if (p.Lat > top) + { + top = p.Lat; + } + + // right + if (p.Lng > right) + { + right = p.Lng; + } + + // bottom + if (p.Lat < bottom) + { + bottom = p.Lat; + } + } + } + } + } + } + } + + if (left != double.MaxValue && right != double.MinValue && top != double.MinValue && bottom != double.MaxValue) + { + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + + return ret; + } + + /// + /// gets rect of route + /// + /// + /// + public RectLatLng? GetRectOfRoute(MapRoute route) + { + RectLatLng? ret = null; + + double left = double.MaxValue; + double top = double.MinValue; + double right = double.MinValue; + double bottom = double.MaxValue; + + if (route.From.HasValue && route.To.HasValue) + { + foreach (PointLatLng p in route.Points) + { + // left + if (p.Lng < left) + { + left = p.Lng; + } + + // top + if (p.Lat > top) + { + top = p.Lat; + } + + // right + if (p.Lng > right) + { + right = p.Lng; + } + + // bottom + if (p.Lat < bottom) + { + bottom = p.Lat; + } + } + ret = RectLatLng.FromLTRB(left, top, right, bottom); + } + return ret; + } + +#if !PocketPC + /// + /// gets image of the current view + /// + /// + public Image ToImage() + { + Image ret = null; + try + { + using (Bitmap bitmap = new Bitmap(Width, Height)) + { + using (Graphics g = Graphics.FromImage(bitmap)) + { + using (Graphics gg = this.CreateGraphics()) + { +#if !PocketPC + g.CopyFromScreen(PointToScreen(new System.Drawing.Point()).X, PointToScreen(new System.Drawing.Point()).Y, 0, 0, new System.Drawing.Size(Width, Height)); +#else + throw new NotImplementedException("Not implemeted for PocketPC"); +#endif + } + } + + // Convert the Image to a png + using (MemoryStream ms = new MemoryStream()) + { + bitmap.Save(ms, ImageFormat.Png); +#if !PocketPC + ret = Image.FromStream(ms); +#else + throw new NotImplementedException("Not implemeted for PocketPC"); +#endif + } + } + } + catch + { + ret = null; + } + return ret; + } +#endif + + /// + /// offset position in pixels + /// + /// + /// + public void Offset(int x, int y) + { + if (IsHandleCreated) + { + // need to fix in rotated mode usinf rotationMatrix + // ... + Core.DragOffset(new GPoint(x, y)); + + ForceUpdateOverlays(); + } + } + + #region UserControl Events + +#if !PocketPC + protected bool DesignModeInConstruct + { + get + { + return (LicenseManager.UsageMode == LicenseUsageMode.Designtime); + } + } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsDesignerHosted + { + get + { + return IsControlDesignerHosted(this); + } + } + + public bool IsControlDesignerHosted(Control ctrl) + { + if (ctrl != null) + { + if (ctrl.Site != null) + { + + if (ctrl.Site.DesignMode == true) + return true; + + else + { + if (IsControlDesignerHosted(ctrl.Parent)) + return true; + + else + return false; + } + } + else + { + if (IsControlDesignerHosted(ctrl.Parent)) + return true; + else + return false; + } + } + else + return false; + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + + if (!IsDesignerHosted) + { + //MethodInvoker m = delegate + //{ + // Thread.Sleep(444); + + //OnSizeChanged(null); + + if (lazyEvents) + { + lazyEvents = false; + + if (lazySetZoomToFitRect.HasValue) + { + SetZoomToFitRect(lazySetZoomToFitRect.Value); + lazySetZoomToFitRect = null; + } + } + Core.OnMapOpen().ProgressChanged += new ProgressChangedEventHandler(invalidatorEngage); + ForceUpdateOverlays(); + //}; + //this.BeginInvoke(m); + } + } #else //delegate void MethodInvoker(); bool IsHandleCreated = false; @@ -1303,1852 +1373,1852 @@ namespace GMap.NET.WindowsForms #endif #if !PocketPC - protected override void OnCreateControl() - { - base.OnCreateControl(); + protected override void OnCreateControl() + { + base.OnCreateControl(); - var f = ParentForm; - if(f != null) - { - while(f.ParentForm != null) + var f = ParentForm; + if (f != null) { - f = f.ParentForm; - } + while (f.ParentForm != null) + { + f = f.ParentForm; + } - if(f != null) + if (f != null) + { + f.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); + } + } + } + + void ParentForm_FormClosing(object sender, FormClosingEventArgs e) + { + if (e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) { - f.FormClosing += new FormClosingEventHandler(ParentForm_FormClosing); + Manager.CancelTileCaching(); } - } - } - - void ParentForm_FormClosing(object sender, FormClosingEventArgs e) - { - if(e.CloseReason == CloseReason.WindowsShutDown || e.CloseReason == CloseReason.TaskManagerClosing) - { - Manager.CancelTileCaching(); - } - } + } #endif - protected override void Dispose(bool disposing) - { - if(disposing) - { - Core.OnMapClose(); - - Overlays.CollectionChanged -= new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); - - foreach(var o in Overlays) + protected override void Dispose(bool disposing) + { + if (disposing) { - o.Dispose(); - } - Overlays.Clear(); + Core.OnMapClose(); - if (ScaleFont != null) - ScaleFont.Dispose(); - if (ScalePen != null) - ScalePen.Dispose(); - CenterFormat.Dispose(); - CenterPen.Dispose(); - BottomFormat.Dispose(); - CopyrightFont.Dispose(); - EmptyTileBorders.Dispose(); - EmptytileBrush.Dispose(); + Overlays.CollectionChanged -= new NotifyCollectionChangedEventHandler(Overlays_CollectionChanged); + + foreach (var o in Overlays) + { + o.Dispose(); + } + Overlays.Clear(); + + if (ScaleFont != null) + ScaleFont.Dispose(); + if (ScalePen != null) + ScalePen.Dispose(); + CenterFormat.Dispose(); + CenterPen.Dispose(); + BottomFormat.Dispose(); + CopyrightFont.Dispose(); + EmptyTileBorders.Dispose(); + EmptytileBrush.Dispose(); #if !PocketPC - SelectedAreaFill.Dispose(); - if (SelectionPen != null) - SelectionPen.Dispose(); + SelectedAreaFill.Dispose(); + if (SelectionPen != null) + SelectionPen.Dispose(); #endif - if(backBuffer != null) - { - backBuffer.Dispose(); - backBuffer = null; - } + if (backBuffer != null) + { + backBuffer.Dispose(); + backBuffer = null; + } - if(gxOff != null) - { - gxOff.Dispose(); - gxOff = null; + if (gxOff != null) + { + gxOff.Dispose(); + gxOff = null; + } } - } - base.Dispose(disposing); - } + base.Dispose(disposing); + } - PointLatLng selectionStart; - PointLatLng selectionEnd; + PointLatLng selectionStart; + PointLatLng selectionEnd; #if !PocketPC - float? MapRenderTransform = null; + float? MapRenderTransform = null; #endif - public Color EmptyMapBackground = Color.WhiteSmoke; + public Color EmptyMapBackground = Color.WhiteSmoke; #if !DESIGN - protected override void OnPaint(PaintEventArgs e) - { - if(ForceDoubleBuffer) - { - #region -- manual buffer -- - if(gxOff != null && backBuffer != null) + protected override void OnPaint(PaintEventArgs e) + { + if (ForceDoubleBuffer) { - // render white background - gxOff.Clear(EmptyMapBackground); + #region -- manual buffer -- + if (gxOff != null && backBuffer != null) + { + // render white background + gxOff.Clear(EmptyMapBackground); #if !PocketPC - if(MapRenderTransform.HasValue) - { - gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - gxOff.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value); - { - DrawMap(gxOff); - OnPaintOverlays(gxOff); - } - } - else + if (MapRenderTransform.HasValue) + { + gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + gxOff.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value); + { + DrawMap(gxOff); + OnPaintOverlays(gxOff); + } + } + else #endif - { + { #if !PocketPC - if(!MobileMode) - { - gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - } + if (!MobileMode) + { + gxOff.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + } #endif - DrawMap(gxOff); - } + DrawMap(gxOff); + } - OnPaintOverlays(gxOff); + OnPaintOverlays(gxOff); - e.Graphics.DrawImage(backBuffer, 0, 0); - } - #endregion - } - else - { - e.Graphics.Clear(EmptyMapBackground); - -#if !PocketPC - if(MapRenderTransform.HasValue) - { - if(!MobileMode) - { - var pc = new GPoint(Width / 2, Height / 2); - var pc2 = pc; - pc.OffsetNegative(Core.renderOffset); - pc2.OffsetNegative(pc); - - e.Graphics.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value, MatrixOrder.Append); - - e.Graphics.TranslateTransform(pc2.X, pc2.Y, MatrixOrder.Append); - } - - { - DrawMap(e.Graphics); - - e.Graphics.ResetTransform(); - if(!MobileMode) - { - var pc = Core.renderOffset; - pc.OffsetNegative(new GPoint(Width / 2, Height / 2)); - e.Graphics.TranslateTransform(Core.renderOffset.X + -pc.X, Core.renderOffset.Y + -pc.Y); - } - - OnPaintOverlays(e.Graphics); - } + e.Graphics.DrawImage(backBuffer, 0, 0); + } + #endregion } else -#endif { + e.Graphics.Clear(EmptyMapBackground); + #if !PocketPC - if(IsRotated) - { - #region -- rotation -- + if (MapRenderTransform.HasValue) + { + if (!MobileMode) + { + var pc = new GPoint(Width / 2, Height / 2); + var pc2 = pc; + pc.OffsetNegative(Core.renderOffset); + pc2.OffsetNegative(pc); - e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; - e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.ScaleTransform(MapRenderTransform.Value, MapRenderTransform.Value, MatrixOrder.Append); - e.Graphics.TranslateTransform((float)(Core.Width / 2.0), (float)(Core.Height / 2.0)); - e.Graphics.RotateTransform(-Bearing); - e.Graphics.TranslateTransform((float)(-Core.Width / 2.0), (float)(-Core.Height / 2.0)); + e.Graphics.TranslateTransform(pc2.X, pc2.Y, MatrixOrder.Append); + } - e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + { + DrawMap(e.Graphics); - DrawMap(e.Graphics); - OnPaintOverlays(e.Graphics); + e.Graphics.ResetTransform(); + if (!MobileMode) + { + var pc = Core.renderOffset; + pc.OffsetNegative(new GPoint(Width / 2, Height / 2)); + e.Graphics.TranslateTransform(Core.renderOffset.X + -pc.X, Core.renderOffset.Y + -pc.Y); + } - #endregion - } - else + OnPaintOverlays(e.Graphics); + } + } + else #endif - { + { #if !PocketPC - if(!MobileMode) - { - e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); - } + if (IsRotated) + { + #region -- rotation -- + + e.Graphics.TextRenderingHint = TextRenderingHint.AntiAlias; + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + + e.Graphics.TranslateTransform((float)(Core.Width / 2.0), (float)(Core.Height / 2.0)); + e.Graphics.RotateTransform(-Bearing); + e.Graphics.TranslateTransform((float)(-Core.Width / 2.0), (float)(-Core.Height / 2.0)); + + e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + + DrawMap(e.Graphics); + OnPaintOverlays(e.Graphics); + + #endregion + } + else #endif - DrawMap(e.Graphics); - OnPaintOverlays(e.Graphics); - } + { +#if !PocketPC + if (!MobileMode) + { + e.Graphics.TranslateTransform(Core.renderOffset.X, Core.renderOffset.Y); + } +#endif + DrawMap(e.Graphics); + OnPaintOverlays(e.Graphics); + } + } } - } - base.OnPaint(e); - } + base.OnPaint(e); + } #endif #if !PocketPC - readonly Matrix rotationMatrix = new Matrix(); - readonly Matrix rotationMatrixInvert = new Matrix(); + readonly Matrix rotationMatrix = new Matrix(); + readonly Matrix rotationMatrixInvert = new Matrix(); - /// - /// updates rotation matrix - /// - void UpdateRotationMatrix() - { - PointF center = new PointF(Core.Width / 2, Core.Height / 2); + /// + /// updates rotation matrix + /// + void UpdateRotationMatrix() + { + PointF center = new PointF(Core.Width / 2, Core.Height / 2); - rotationMatrix.Reset(); - rotationMatrix.RotateAt(-Bearing, center); + rotationMatrix.Reset(); + rotationMatrix.RotateAt(-Bearing, center); - rotationMatrixInvert.Reset(); - rotationMatrixInvert.RotateAt(-Bearing, center); - rotationMatrixInvert.Invert(); - } + rotationMatrixInvert.Reset(); + rotationMatrixInvert.RotateAt(-Bearing, center); + rotationMatrixInvert.Invert(); + } - /// - /// returs true if map bearing is not zero - /// - [Browsable(false)] - public bool IsRotated - { - get - { - return Core.IsRotated; - } - } - - /// - /// bearing for rotation of the map - /// - [Category("GMap.NET")] - public float Bearing - { - get - { - return Core.bearing; - } - set - { - //if(Core.bearing != value) - //{ - // bool resize = Core.bearing == 0; - // Core.bearing = value; - - // //if(VirtualSizeEnabled) - // //{ - // // c.X += (Width - Core.vWidth) / 2; - // // c.Y += (Height - Core.vHeight) / 2; - // //} - - // UpdateRotationMatrix(); - - // if(value != 0 && value % 360 != 0) - // { - // Core.IsRotated = true; - - // if(Core.tileRectBearing.Size == Core.tileRect.Size) - // { - // Core.tileRectBearing = Core.tileRect; - // Core.tileRectBearing.Inflate(1, 1); - // } - // } - // else - // { - // Core.IsRotated = false; - // Core.tileRectBearing = Core.tileRect; - // } - - // if(resize) - // { - // Core.OnMapSizeChanged(Width, Height); - // } - - // if(!HoldInvalidation && Core.IsStarted) - // { - // ForceUpdateOverlays(); - // } - //} - } - } -#endif - - /// - /// override, to render something more - /// - /// - protected virtual void OnPaintOverlays(Graphics g) - { -#if !PocketPC - g.SmoothingMode = SmoothingMode.HighQuality; -#endif - foreach(GMapOverlay o in Overlays) - { - if(o.IsVisibile) + /// + /// returs true if map bearing is not zero + /// + [Browsable(false)] + public bool IsRotated + { + get { - o.OnRender(g); + return Core.IsRotated; } - } + } - // center in virtual spcace... + /// + /// bearing for rotation of the map + /// + [Category("GMap.NET")] + public float Bearing + { + get + { + return Core.bearing; + } + set + { + //if(Core.bearing != value) + //{ + // bool resize = Core.bearing == 0; + // Core.bearing = value; + + // //if(VirtualSizeEnabled) + // //{ + // // c.X += (Width - Core.vWidth) / 2; + // // c.Y += (Height - Core.vHeight) / 2; + // //} + + // UpdateRotationMatrix(); + + // if(value != 0 && value % 360 != 0) + // { + // Core.IsRotated = true; + + // if(Core.tileRectBearing.Size == Core.tileRect.Size) + // { + // Core.tileRectBearing = Core.tileRect; + // Core.tileRectBearing.Inflate(1, 1); + // } + // } + // else + // { + // Core.IsRotated = false; + // Core.tileRectBearing = Core.tileRect; + // } + + // if(resize) + // { + // Core.OnMapSizeChanged(Width, Height); + // } + + // if(!HoldInvalidation && Core.IsStarted) + // { + // ForceUpdateOverlays(); + // } + //} + } + } +#endif + + /// + /// override, to render something more + /// + /// + protected virtual void OnPaintOverlays(Graphics g) + { +#if !PocketPC + g.SmoothingMode = SmoothingMode.HighQuality; +#endif + foreach (GMapOverlay o in Overlays) + { + if (o.IsVisibile) + { + o.OnRender(g); + } + } + + // center in virtual spcace... #if DEBUG - g.DrawLine(ScalePen, -20, 0, 20, 0); - g.DrawLine(ScalePen, 0, -20, 0, 20); + g.DrawLine(ScalePen, -20, 0, 20, 0); + g.DrawLine(ScalePen, 0, -20, 0, 20); #if PocketPC g.DrawString("debug build", CopyrightFont, CopyrightBrush, 2, CopyrightFont.Size); #else -// g.DrawString("debug build", CopyrightFont, Brushes.Blue, 2, CopyrightFont.Height); + // g.DrawString("debug build", CopyrightFont, Brushes.Blue, 2, CopyrightFont.Height); #endif #endif #if !PocketPC - if(!MobileMode) - { - g.ResetTransform(); - } + if (!MobileMode) + { + g.ResetTransform(); + } - if(!SelectedArea.IsEmpty) - { - GPoint p1 = FromLatLngToLocal(SelectedArea.LocationTopLeft); - GPoint p2 = FromLatLngToLocal(SelectedArea.LocationRightBottom); + if (!SelectedArea.IsEmpty) + { + GPoint p1 = FromLatLngToLocal(SelectedArea.LocationTopLeft); + GPoint p2 = FromLatLngToLocal(SelectedArea.LocationRightBottom); - long x1 = p1.X; - long y1 = p1.Y; - long x2 = p2.X; - long y2 = p2.Y; + long x1 = p1.X; + long y1 = p1.Y; + long x2 = p2.X; + long y2 = p2.Y; - g.DrawRectangle(SelectionPen, x1, y1, x2 - x1, y2 - y1); - g.FillRectangle(SelectedAreaFill, x1, y1, x2 - x1, y2 - y1); - } + g.DrawRectangle(SelectionPen, x1, y1, x2 - x1, y2 - y1); + g.FillRectangle(SelectedAreaFill, x1, y1, x2 - x1, y2 - y1); + } #endif - if(ShowCenter) - { - g.DrawLine(CenterPen, Width / 2 - 5, Height / 2, Width / 2 + 5, Height / 2); - g.DrawLine(CenterPen, Width / 2, Height / 2 - 5, Width / 2, Height / 2 + 5); - } + if (ShowCenter) + { + g.DrawLine(CenterPen, Width / 2 - 5, Height / 2, Width / 2 + 5, Height / 2); + g.DrawLine(CenterPen, Width / 2, Height / 2 - 5, Width / 2, Height / 2 + 5); + } - if(renderHelperLine) - { - var p = PointToClient(Form.MousePosition); + if (renderHelperLine) + { + var p = PointToClient(Form.MousePosition); - g.DrawLine(HelperLinePen, p.X, 0, p.X, Height); - g.DrawLine(HelperLinePen, 0, p.Y, Width, p.Y); - } + g.DrawLine(HelperLinePen, p.X, 0, p.X, Height); + g.DrawLine(HelperLinePen, 0, p.Y, Width, p.Y); + } - #region -- copyright -- + #region -- copyright -- - if(!string.IsNullOrEmpty(Core.provider.Copyright)) - { + if (!string.IsNullOrEmpty(Core.provider.Copyright)) + { #if !PocketPC - g.DrawString(Core.provider.Copyright, CopyrightFont, Brushes.Navy, 3, Height - CopyrightFont.Height - 5); + g.DrawString(Core.provider.Copyright, CopyrightFont, Brushes.Navy, 3, Height - CopyrightFont.Height - 5); #else g.DrawString(Core.provider.Copyright, CopyrightFont, CopyrightBrush, 3, Height - CopyrightFont.Size - 15); #endif - } + } - #endregion + #endregion - #region -- draw scale -- + #region -- draw scale -- #if !PocketPC - if(MapScaleInfoEnabled) - { - /* - if(Width > Core.pxRes5000km) + if (MapScaleInfoEnabled) { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes5000km, 10); - g.DrawString("5000Km", ScaleFont, Brushes.Blue, Core.pxRes5000km + 10, 11); + /* + if(Width > Core.pxRes5000km) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes5000km, 10); + g.DrawString("5000Km", ScaleFont, Brushes.Blue, Core.pxRes5000km + 10, 11); + } + if(Width > Core.pxRes1000km) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000km, 10); + g.DrawString("1000Km", ScaleFont, Brushes.Blue, Core.pxRes1000km + 10, 11); + } + if(Width > Core.pxRes100km && Zoom > 2) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100km, 10); + g.DrawString("100Km", ScaleFont, Brushes.Blue, Core.pxRes100km + 10, 11); + } + if(Width > Core.pxRes10km && Zoom > 5) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes10km, 10); + g.DrawString("10Km", ScaleFont, Brushes.Blue, Core.pxRes10km + 10, 11); + } + if(Width > Core.pxRes1000m && Zoom >= 10) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000m, 10); + g.DrawString("1000m", ScaleFont, Brushes.Blue, Core.pxRes1000m + 10, 11); + } + if(Width > Core.pxRes100m && Zoom > 11) + { + g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100m, 10); + g.DrawString("100m", ScaleFont, Brushes.Blue, Core.pxRes100m + 9, 11); + } + */ + // Darstellung ScaleInfo geändert 21.11.2012 + if ((Core.pxRes5000km > 0) && (Width > Core.pxRes5000km)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes5000km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes5000km + 10, 10, Core.pxRes5000km + 10, 20); + g.DrawString("5000Km", ScaleFont, Brushes.Black, Core.pxRes5000km - 40, 13); + } + if ((Core.pxRes1000km > 0) && (Width > Core.pxRes1000km)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes1000km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes1000km + 10, 10, Core.pxRes1000km + 10, 20); + g.DrawString("1000Km", ScaleFont, Brushes.Black, Core.pxRes1000km - 40, 13); + } + if ((Core.pxRes100km > 0) && (Width > Core.pxRes100km) && (Zoom > 5)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes100km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes100km + 10, 10, Core.pxRes100km + 10, 20); + g.DrawString("100Km", ScaleFont, Brushes.Black, Core.pxRes100km - 35, 13); + } + if ((Core.pxRes10km > 0) && (Width > Core.pxRes10km) && (Zoom > 8)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes10km + 10, 10); + g.DrawLine(ScalePen, Core.pxRes10km + 10, 10, Core.pxRes10km + 10, 20); + g.DrawString("10Km", ScaleFont, Brushes.Black, Core.pxRes10km - 30, 13); + } + if ((Core.pxRes1000m > 0) && (Width > Core.pxRes1000m) && (Zoom >= 12)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes1000m + 10, 10); + g.DrawLine(ScalePen, Core.pxRes1000m + 10, 10, Core.pxRes1000m + 10, 20); + g.DrawString("1km", ScaleFont, Brushes.Black, Core.pxRes1000m - 25, 13); + } + if ((Core.pxRes100m > 0) && (Width > Core.pxRes100m) && (Zoom > 14)) + { + g.DrawLine(ScalePen, 10, 10, 10, 20); + g.DrawLine(ScalePen, 10, 10, Core.pxRes100m + 10, 10); + g.DrawLine(ScalePen, Core.pxRes100m + 10, 10, Core.pxRes100m + 10, 20); + g.DrawString("100m", ScaleFont, Brushes.Black, Core.pxRes100m - 30, 13); + } } - if(Width > Core.pxRes1000km) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000km, 10); - g.DrawString("1000Km", ScaleFont, Brushes.Blue, Core.pxRes1000km + 10, 11); - } - if(Width > Core.pxRes100km && Zoom > 2) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100km, 10); - g.DrawString("100Km", ScaleFont, Brushes.Blue, Core.pxRes100km + 10, 11); - } - if(Width > Core.pxRes10km && Zoom > 5) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes10km, 10); - g.DrawString("10Km", ScaleFont, Brushes.Blue, Core.pxRes10km + 10, 11); - } - if(Width > Core.pxRes1000m && Zoom >= 10) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes1000m, 10); - g.DrawString("1000m", ScaleFont, Brushes.Blue, Core.pxRes1000m + 10, 11); - } - if(Width > Core.pxRes100m && Zoom > 11) - { - g.DrawRectangle(ScalePen, 10, 10, Core.pxRes100m, 10); - g.DrawString("100m", ScaleFont, Brushes.Blue, Core.pxRes100m + 9, 11); - } - */ - // Darstellung ScaleInfo geändert 21.11.2012 - if((Core.pxRes5000km > 0) && (Width > Core.pxRes5000km)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes5000km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes5000km + 10, 10, Core.pxRes5000km + 10, 20); - g.DrawString("5000Km", ScaleFont, Brushes.Black, Core.pxRes5000km - 40, 13); - } - if((Core.pxRes1000km > 0) && (Width > Core.pxRes1000km)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes1000km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes1000km + 10, 10, Core.pxRes1000km + 10, 20); - g.DrawString("1000Km", ScaleFont, Brushes.Black, Core.pxRes1000km - 40, 13); - } - if((Core.pxRes100km > 0) && (Width > Core.pxRes100km) && (Zoom > 5)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes100km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes100km + 10, 10, Core.pxRes100km + 10, 20); - g.DrawString("100Km", ScaleFont, Brushes.Black, Core.pxRes100km - 35, 13); - } - if((Core.pxRes10km > 0) && (Width > Core.pxRes10km) && (Zoom > 8)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes10km + 10, 10); - g.DrawLine(ScalePen, Core.pxRes10km + 10, 10, Core.pxRes10km + 10, 20); - g.DrawString("10Km", ScaleFont, Brushes.Black, Core.pxRes10km - 30, 13); - } - if((Core.pxRes1000m > 0) && (Width > Core.pxRes1000m) && (Zoom >= 12)) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes1000m + 10, 10); - g.DrawLine(ScalePen, Core.pxRes1000m + 10, 10, Core.pxRes1000m + 10, 20); - g.DrawString("1km", ScaleFont, Brushes.Black, Core.pxRes1000m - 25, 13); - } - if((Core.pxRes100m > 0) && (Width > Core.pxRes100m) && (Zoom > 14) ) - { - g.DrawLine(ScalePen, 10, 10, 10, 20); - g.DrawLine(ScalePen, 10, 10, Core.pxRes100m+10, 10); - g.DrawLine(ScalePen, Core.pxRes100m + 10, 10, Core.pxRes100m + 10, 20); - g.DrawString("100m", ScaleFont, Brushes.Black, Core.pxRes100m -30, 13); - } - } #endif - #endregion - } + #endregion + } #if !PocketPC - /// - /// shrinks map area, useful just for testing - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool VirtualSizeEnabled - { - get - { - return Core.VirtualSizeEnabled; - } - set - { - Core.VirtualSizeEnabled = value; - } - } + /// + /// shrinks map area, useful just for testing + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool VirtualSizeEnabled + { + get + { + return Core.VirtualSizeEnabled; + } + set + { + Core.VirtualSizeEnabled = value; + } + } - protected override void OnSizeChanged(EventArgs e) - { - base.OnSizeChanged(e); + protected override void OnSizeChanged(EventArgs e) + { + base.OnSizeChanged(e); #else protected override void OnResize(EventArgs e) { base.OnResize(e); #endif - if(Width == 0 || Height == 0) - { - Debug.WriteLine("minimized"); - return; - } - - if(Width == Core.Width && Height == Core.Height) - { - Debug.WriteLine("maximized"); - return; - } - -#if !PocketPC - if(!IsDesignerHosted && !DesignModeInConstruct) -#endif - { - if(ForceDoubleBuffer) + if (Width == 0 || Height == 0) { - if(backBuffer != null) - { - backBuffer.Dispose(); - backBuffer = null; - } - if(gxOff != null) - { - gxOff.Dispose(); - gxOff = null; - } + Debug.WriteLine("minimized"); + return; + } - backBuffer = new Bitmap(Width, Height); - gxOff = Graphics.FromImage(backBuffer); + if (Width == Core.Width && Height == Core.Height) + { + Debug.WriteLine("maximized"); + return; } #if !PocketPC - if(VirtualSizeEnabled) - { - Core.OnMapSizeChanged(Core.vWidth, Core.vHeight); - } - else + if (!IsDesignerHosted && !DesignModeInConstruct) #endif { - Core.OnMapSizeChanged(Width, Height); - } - //Core.currentRegion = new GRect(-50, -50, Core.Width + 50, Core.Height + 50); + if (ForceDoubleBuffer) + { + if (backBuffer != null) + { + backBuffer.Dispose(); + backBuffer = null; + } + if (gxOff != null) + { + gxOff.Dispose(); + gxOff = null; + } - if(Visible && IsHandleCreated && Core.IsStarted) + backBuffer = new Bitmap(Width, Height); + gxOff = Graphics.FromImage(backBuffer); + } + +#if !PocketPC + if (VirtualSizeEnabled) + { + Core.OnMapSizeChanged(Core.vWidth, Core.vHeight); + } + else +#endif + { + Core.OnMapSizeChanged(Width, Height); + } + //Core.currentRegion = new GRect(-50, -50, Core.Width + 50, Core.Height + 50); + + if (Visible && IsHandleCreated && Core.IsStarted) + { +#if !PocketPC + if (IsRotated) + { + UpdateRotationMatrix(); + } +#endif + ForceUpdateOverlays(); + } + } + } + + bool isSelected = false; + protected override void OnMouseDown(MouseEventArgs e) + { + if (!IsMouseOverMarker) { #if !PocketPC - if(IsRotated) - { - UpdateRotationMatrix(); - } -#endif - ForceUpdateOverlays(); - } - } - } - - bool isSelected = false; - protected override void OnMouseDown(MouseEventArgs e) - { - if(!IsMouseOverMarker) - { -#if !PocketPC - if(e.Button == DragButton && CanDragMap) + if (e.Button == DragButton && CanDragMap) #else if(CanDragMap) #endif - { + { #if !PocketPC - Core.mouseDown = ApplyRotationInversion(e.X, e.Y); + Core.mouseDown = ApplyRotationInversion(e.X, e.Y); #else Core.mouseDown = new GPoint(e.X, e.Y); #endif - this.Invalidate(); + this.Invalidate(); + } + else if (!isSelected) + { + isSelected = true; + SelectedArea = RectLatLng.Empty; + selectionEnd = PointLatLng.Empty; + selectionStart = FromLocalToLatLng(e.X, e.Y); + } } - else if(!isSelected) + + base.OnMouseDown(e); + } + + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + + if (isSelected) { - isSelected = true; - SelectedArea = RectLatLng.Empty; - selectionEnd = PointLatLng.Empty; - selectionStart = FromLocalToLatLng(e.X, e.Y); + isSelected = false; } - } - base.OnMouseDown(e); - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - - if(isSelected) - { - isSelected = false; - } - - if(Core.IsDragging) - { - if(isDragging) + if (Core.IsDragging) { - isDragging = false; - Debug.WriteLine("IsDragging = " + isDragging); + if (isDragging) + { + isDragging = false; + Debug.WriteLine("IsDragging = " + isDragging); #if !PocketPC - this.Cursor = cursorBefore; - cursorBefore = null; + this.Cursor = cursorBefore; + cursorBefore = null; #endif - } - Core.EndDrag(); + } + Core.EndDrag(); - if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) - { - if(Core.LastLocationInBounds.HasValue) - { - Position = Core.LastLocationInBounds.Value; - } - } - } - else - { -#if !PocketPC - if(e.Button == DragButton) - { - Core.mouseDown = GPoint.Empty; - } - - if(!selectionEnd.IsEmpty && !selectionStart.IsEmpty) - { - bool zoomtofit = false; - - if(!SelectedArea.IsEmpty && Form.ModifierKeys == Keys.Shift) - { - zoomtofit = SetZoomToFitRect(SelectedArea); - } - - if(OnSelectionChange != null) - { - OnSelectionChange(SelectedArea, zoomtofit); - } + if (BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) + { + if (Core.LastLocationInBounds.HasValue) + { + Position = Core.LastLocationInBounds.Value; + } + } } else { - Invalidate(); - } +#if !PocketPC + if (e.Button == DragButton) + { + Core.mouseDown = GPoint.Empty; + } + + if (!selectionEnd.IsEmpty && !selectionStart.IsEmpty) + { + bool zoomtofit = false; + + if (!SelectedArea.IsEmpty && Form.ModifierKeys == Keys.Shift) + { + zoomtofit = SetZoomToFitRect(SelectedArea); + } + + if (OnSelectionChange != null) + { + OnSelectionChange(SelectedArea, zoomtofit); + } + } + else + { + Invalidate(); + } #endif - } - } + } + } #if !PocketPC - protected override void OnMouseClick(MouseEventArgs e) - { - if(!Core.IsDragging) - { - for(int i = Overlays.Count - 1; i >= 0; i--) + protected override void OnMouseClick(MouseEventArgs e) + { + if (!Core.IsDragging) { - GMapOverlay o = Overlays[i]; - if(o != null && o.IsVisibile) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - if((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + for (int i = Overlays.Count - 1; i >= 0; i--) + { + GMapOverlay o = Overlays[i]; + if (o != null && o.IsVisibile) + { + foreach (GMapMarker m in o.Markers) { - if(OnMarkerClick != null) - { - OnMarkerClick(m, e); - } - break; + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + + if ((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + { + if (OnMarkerClick != null) + { + OnMarkerClick(m, e); + } + break; + } + + #endregion + } } - #endregion - } - } + foreach (GMapRoute m in o.Routes) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- - foreach(GMapRoute m in o.Routes) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - GPoint rp = new GPoint(e.X, e.Y); + GPoint rp = new GPoint(e.X, e.Y); #if !PocketPC - if(!MobileMode) - { - rp.OffsetNegative(Core.renderOffset); - } + if (!MobileMode) + { + rp.OffsetNegative(Core.renderOffset); + } #endif - if(m.IsInside((int)rp.X, (int)rp.Y)) - { - if(OnRouteClick != null) - { - OnRouteClick(m, e); - } - break; + if (m.IsInside((int)rp.X, (int)rp.Y)) + { + if (OnRouteClick != null) + { + OnRouteClick(m, e); + } + break; + } + #endregion + } } - #endregion - } - } - foreach(GMapPolygon m in o.Polygons) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - if(m.IsInside(FromLocalToLatLng(e.X, e.Y))) + foreach (GMapPolygon m in o.Polygons) { - if(OnPolygonClick != null) - { - OnPolygonClick(m, e); - } - break; + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + if (m.IsInside(FromLocalToLatLng(e.X, e.Y))) + { + if (OnPolygonClick != null) + { + OnPolygonClick(m, e); + } + break; + } + #endregion + } } - #endregion - } - } - } + } + } } - } - //m_mousepos = e.Location; - //if(HelperLineOption == HelperLineOptions.ShowAlways) - //{ - // base.Invalidate(); - //} + //m_mousepos = e.Location; + //if(HelperLineOption == HelperLineOptions.ShowAlways) + //{ + // base.Invalidate(); + //} - base.OnMouseClick(e); - } + base.OnMouseClick(e); + } #endif #if !PocketPC - /// - /// apply transformation if in rotation mode - /// - GPoint ApplyRotationInversion(int x, int y) - { - GPoint ret = new GPoint(x, y); + /// + /// apply transformation if in rotation mode + /// + GPoint ApplyRotationInversion(int x, int y) + { + GPoint ret = new GPoint(x, y); - if(IsRotated) - { + if (IsRotated) + { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrixInvert.TransformPoints(tt); - var f = tt[0]; + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrixInvert.TransformPoints(tt); + var f = tt[0]; - ret.X = f.X; - ret.Y = f.Y; - } + ret.X = f.X; + ret.Y = f.Y; + } - return ret; - } + return ret; + } - /// - /// apply transformation if in rotation mode - /// - GPoint ApplyRotation(int x, int y) - { - GPoint ret = new GPoint(x, y); + /// + /// apply transformation if in rotation mode + /// + GPoint ApplyRotation(int x, int y) + { + GPoint ret = new GPoint(x, y); - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrix.TransformPoints(tt); - var f = tt[0]; + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrix.TransformPoints(tt); + var f = tt[0]; - ret.X = f.X; - ret.Y = f.Y; - } + ret.X = f.X; + ret.Y = f.Y; + } - return ret; - } + return ret; + } - Cursor cursorBefore = Cursors.Default; + Cursor cursorBefore = Cursors.Default; #endif - /// - /// Gets the width and height of a rectangle centered on the point the mouse - /// button was pressed, within which a drag operation will not begin. - /// + /// + /// Gets the width and height of a rectangle centered on the point the mouse + /// button was pressed, within which a drag operation will not begin. + /// #if !PocketPC - public Size DragSize = SystemInformation.DragSize; + public Size DragSize = SystemInformation.DragSize; #else public Size DragSize = new Size(4, 4); #endif - protected override void OnMouseMove(MouseEventArgs e) - { - if(!Core.IsDragging && !Core.mouseDown.IsEmpty) - { + protected override void OnMouseMove(MouseEventArgs e) + { + if (!Core.IsDragging && !Core.mouseDown.IsEmpty) + { #if PocketPC GPoint p = new GPoint(e.X, e.Y); #else - GPoint p = ApplyRotationInversion(e.X, e.Y); + GPoint p = ApplyRotationInversion(e.X, e.Y); #endif - if(Math.Abs(p.X - Core.mouseDown.X) * 2 >= DragSize.Width || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= DragSize.Height) - { - Core.BeginDrag(Core.mouseDown); + if (Math.Abs(p.X - Core.mouseDown.X) * 2 >= DragSize.Width || Math.Abs(p.Y - Core.mouseDown.Y) * 2 >= DragSize.Height) + { + Core.BeginDrag(Core.mouseDown); + } } - } - if(Core.IsDragging) - { - if(!isDragging) + if (Core.IsDragging) { - isDragging = true; - Debug.WriteLine("IsDragging = " + isDragging); + if (!isDragging) + { + isDragging = true; + Debug.WriteLine("IsDragging = " + isDragging); #if !PocketPC - cursorBefore = this.Cursor; - this.Cursor = Cursors.SizeAll; + cursorBefore = this.Cursor; + this.Cursor = Cursors.SizeAll; #endif - } + } - if(BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) - { - // ... - } - else - { + if (BoundsOfMap.HasValue && !BoundsOfMap.Value.Contains(Position)) + { + // ... + } + else + { #if !PocketPC - Core.mouseCurrent = ApplyRotationInversion(e.X, e.Y); + Core.mouseCurrent = ApplyRotationInversion(e.X, e.Y); #else Core.mouseCurrent = new GPoint(e.X, e.Y); #endif - Core.Drag(Core.mouseCurrent); + Core.Drag(Core.mouseCurrent); #if !PocketPC - if(MobileMode) - { - ForceUpdateOverlays(); - } + if (MobileMode) + { + ForceUpdateOverlays(); + } #else ForceUpdateOverlays(); #endif - base.Invalidate(); - } - } - else - { -#if !PocketPC - if(isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift || DisableAltForSelection)) - { - selectionEnd = FromLocalToLatLng(e.X, e.Y); - { - GMap.NET.PointLatLng p1 = selectionStart; - GMap.NET.PointLatLng p2 = selectionEnd; - - double x1 = Math.Min(p1.Lng, p2.Lng); - double y1 = Math.Max(p1.Lat, p2.Lat); - double x2 = Math.Max(p1.Lng, p2.Lng); - double y2 = Math.Min(p1.Lat, p2.Lat); - - SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2); - } + base.Invalidate(); + } } else -#endif - if(Core.mouseDown.IsEmpty) - { - for(int i = Overlays.Count - 1; i >= 0; i--) - { - GMapOverlay o = Overlays[i]; - if(o != null && o.IsVisibile) - { - foreach(GMapMarker m in o.Markers) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- + { #if !PocketPC - if((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) + if (isSelected && !selectionStart.IsEmpty && (Form.ModifierKeys == Keys.Alt || Form.ModifierKeys == Keys.Shift || DisableAltForSelection)) + { + selectionEnd = FromLocalToLatLng(e.X, e.Y); + { + GMap.NET.PointLatLng p1 = selectionStart; + GMap.NET.PointLatLng p2 = selectionEnd; + + double x1 = Math.Min(p1.Lng, p2.Lng); + double y1 = Math.Max(p1.Lat, p2.Lat); + double x2 = Math.Max(p1.Lng, p2.Lng); + double y2 = Math.Min(p1.Lat, p2.Lat); + + SelectedArea = new RectLatLng(y1, x1, x2 - x1, y1 - y2); + } + } + else +#endif + if (Core.mouseDown.IsEmpty) + { + for (int i = Overlays.Count - 1; i >= 0; i--) + { + GMapOverlay o = Overlays[i]; + if (o != null && o.IsVisibile) + { + foreach (GMapMarker m in o.Markers) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- +#if !PocketPC + if ((MobileMode && m.LocalArea.Contains(e.X, e.Y)) || (!MobileMode && m.LocalAreaInControlSpace.Contains(e.X, e.Y))) #else if(m.LocalArea.Contains(e.X, e.Y)) #endif - { - if(!m.IsMouseOver) - { -#if !PocketPC - SetCursorHandOnEnter(); -#endif - m.IsMouseOver = true; - IsMouseOverMarker = true; - - if(OnMarkerEnter != null) { - OnMarkerEnter(m); - } - - Invalidate(); - } - } - else if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverMarker = false; + if (!m.IsMouseOver) + { #if !PocketPC - RestoreCursorOnLeave(); + SetCursorHandOnEnter(); #endif - if(OnMarkerLeave != null) - { - OnMarkerLeave(m); - } + m.IsMouseOver = true; + IsMouseOverMarker = true; - Invalidate(); - } - #endregion - } - } + if (OnMarkerEnter != null) + { + OnMarkerEnter(m); + } + + Invalidate(); + } + } + else if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverMarker = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnMarkerLeave != null) + { + OnMarkerLeave(m); + } + + Invalidate(); + } + #endregion + } + } #if !PocketPC - foreach(GMapRoute m in o.Routes) + foreach (GMapRoute m in o.Routes) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + + GPoint rp = new GPoint(e.X, e.Y); +#if !PocketPC + if (!MobileMode) + { + rp.OffsetNegative(Core.renderOffset); + } +#endif + if (m.IsInside((int)rp.X, (int)rp.Y)) + { + if (!m.IsMouseOver) + { +#if !PocketPC + SetCursorHandOnEnter(); +#endif + m.IsMouseOver = true; + IsMouseOverRoute = true; + + if (OnRouteEnter != null) + { + OnRouteEnter(m); + } + + Invalidate(); + } + } + else + { + if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverRoute = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnRouteLeave != null) + { + OnRouteLeave(m); + } + + Invalidate(); + } + } + #endregion + } + } +#endif + + foreach (GMapPolygon m in o.Polygons) + { + if (m.IsVisible && m.IsHitTestVisible) + { + #region -- check -- + if (m.IsInside(FromLocalToLatLng(e.X, e.Y))) + { + if (!m.IsMouseOver) + { +#if !PocketPC + SetCursorHandOnEnter(); +#endif + m.IsMouseOver = true; + IsMouseOverPolygon = true; + + if (OnPolygonEnter != null) + { + OnPolygonEnter(m); + } + + Invalidate(); + } + } + else + { + if (m.IsMouseOver) + { + m.IsMouseOver = false; + IsMouseOverPolygon = false; +#if !PocketPC + RestoreCursorOnLeave(); +#endif + if (OnPolygonLeave != null) + { + OnPolygonLeave(m); + } + + Invalidate(); + } + } + #endregion + } + } + } + } + } + + if (renderHelperLine) + { + base.Invalidate(); + } + } + + base.OnMouseMove(e); + } + +#if !PocketPC + + internal void RestoreCursorOnLeave() + { + if (overObjectCount == 0 && cursorBefore != null) + { + this.Cursor = this.cursorBefore; + cursorBefore = null; + } + } + + internal void SetCursorHandOnEnter() + { + if (overObjectCount == 0 && Cursor != Cursors.Hand) + { + cursorBefore = this.Cursor; + this.Cursor = Cursors.Hand; + } + } + + /// + /// prevents focusing map if mouse enters it's area + /// + public bool DisableFocusOnMouseEnter = false; + + protected override void OnMouseEnter(EventArgs e) + { + base.OnMouseEnter(e); + + if (!DisableFocusOnMouseEnter) + { + Focus(); + } + } + + /// + /// reverses MouseWheel zooming direction + /// + public bool InvertedMouseWheelZooming = false; + + /// + /// lets you zoom by MouseWheel even when pointer is in area of marker + /// + public bool IgnoreMarkerOnMouseWheel = false; + + protected override void OnMouseWheel(MouseEventArgs e) + { + base.OnMouseWheel(e); + + if ((!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging) + { + if (Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y) + { + if (MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter) + { + Core.position = FromLocalToLatLng(e.X, e.Y); + } + else if (MouseWheelZoomType == MouseWheelZoomType.ViewCenter) + { + Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2); + } + else if (MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter) + { + Core.position = FromLocalToLatLng(e.X, e.Y); + } + + Core.mouseLastZoom.X = e.X; + Core.mouseLastZoom.Y = e.Y; + } + + // set mouse position to map center + if (MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter) + { + if (!GMaps.Instance.IsRunningOnMono) + { + System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2)); + Stuff.SetCursorPos((int)p.X, (int)p.Y); + } + } + + Core.MouseWheelZooming = true; + + if (e.Delta > 0) + { + if (!InvertedMouseWheelZooming) + { + Zoom++; + } + else + { + Zoom--; + } + } + else if (e.Delta < 0) + { + if (!InvertedMouseWheelZooming) + { + Zoom--; + } + else + { + Zoom++; + } + } + + Core.MouseWheelZooming = false; + } + } +#endif + #endregion + + #region IGControl Members + + /// + /// Call it to empty tile cache & reload tiles + /// + public void ReloadMap() + { + Core.ReloadMap(); + } + + /// + /// set current position using keywords + /// + /// + /// true if successfull + public GeoCoderStatusCode SetCurrentPositionByKeywords(string keys) + { + GeoCoderStatusCode status = GeoCoderStatusCode.Unknow; + + GeocodingProvider gp = MapProvider as GeocodingProvider; + if (gp == null) + { + gp = GMapProviders.OpenStreetMap as GeocodingProvider; + } + + if (gp != null) + { + var pt = gp.GetPoint(keys, out status); + if (status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue) + { + Position = pt.Value; + } + } + + return status; + } + + /// + /// gets world coordinate from local control coordinate + /// + /// + /// + /// + public PointLatLng FromLocalToLatLng(int x, int y) + { +#if !PocketPC + if (MapRenderTransform.HasValue) + { + //var xx = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); + //var yy = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); + + //PointF center = new PointF(Core.Width / 2, Core.Height / 2); + + //Matrix m = new Matrix(); + //m.Translate(-Core.renderOffset.X, -Core.renderOffset.Y); + //m.Scale(MapRenderTransform.Value, MapRenderTransform.Value); + + //System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + //m.TransformPoints(tt); + //var z = tt[0]; + + // + + x = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); + y = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); + } + + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; + rotationMatrixInvert.TransformPoints(tt); + var f = tt[0]; + + if (VirtualSizeEnabled) + { + f.X += (Width - Core.vWidth) / 2; + f.Y += (Height - Core.vHeight) / 2; + } + + x = f.X; + y = f.Y; + } +#endif + return Core.FromLocalToLatLng(x, y); + } + + /// + /// gets local coordinate from world coordinate + /// + /// + /// + public GPoint FromLatLngToLocal(PointLatLng point) + { + GPoint ret = Core.FromLatLngToLocal(point); + +#if !PocketPC + if (MapRenderTransform.HasValue) + { + ret.X = (int)(Core.renderOffset.X + ((Core.renderOffset.X - ret.X) * -MapRenderTransform.Value)); + ret.Y = (int)(Core.renderOffset.Y + ((Core.renderOffset.Y - ret.Y) * -MapRenderTransform.Value)); + } + + if (IsRotated) + { + System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point((int)ret.X, (int)ret.Y) }; + rotationMatrix.TransformPoints(tt); + var f = tt[0]; + + if (VirtualSizeEnabled) + { + f.X += (Width - Core.vWidth) / 2; + f.Y += (Height - Core.vHeight) / 2; + } + + ret.X = f.X; + ret.Y = f.Y; + } + +#endif + return ret; + } + +#if !PocketPC + + /// + /// shows map db export dialog + /// + /// + public bool ShowExportDialog() + { + using (FileDialog dlg = new SaveFileDialog()) + { + dlg.CheckPathExists = true; + dlg.CheckFileExists = false; + dlg.AddExtension = true; + dlg.DefaultExt = "gmdb"; + dlg.ValidateNames = true; + dlg.Title = "GMap.NET: Export map to db, if file exsist only new data will be added"; + dlg.FileName = "DataExp"; + dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; + dlg.FilterIndex = 1; + dlg.RestoreDirectory = true; + + if (dlg.ShowDialog() == DialogResult.OK) + { + bool ok = GMaps.Instance.ExportToGMDB(dlg.FileName); + if (ok) + { + MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + else + { + MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + return ok; + } + } + + return false; + } + + /// + /// shows map dbimport dialog + /// + /// + public bool ShowImportDialog() + { + using (FileDialog dlg = new OpenFileDialog()) + { + dlg.CheckPathExists = true; + dlg.CheckFileExists = false; + dlg.AddExtension = true; + dlg.DefaultExt = "gmdb"; + dlg.ValidateNames = true; + dlg.Title = "GMap.NET: Import to db, only new data will be added"; + dlg.FileName = "DataImport"; + dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); + dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; + dlg.FilterIndex = 1; + dlg.RestoreDirectory = true; + + if (dlg.ShowDialog() == DialogResult.OK) + { + bool ok = GMaps.Instance.ImportFromGMDB(dlg.FileName); + if (ok) + { + MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); + ReloadMap(); + } + else + { + MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + + return ok; + } + } + + return false; + } +#endif + + [Category("GMap.NET"), DefaultValue(0)] + public double Zoom + { + get + { + return zoomReal; + } + set + { + if (zoomReal != value) + { + Debug.WriteLine("ZoomPropertyChanged: " + zoomReal + " -> " + value); + + if (value > MaxZoom) + { + zoomReal = MaxZoom; + } + else if (value < MinZoom) + { + zoomReal = MinZoom; + } + else + { + zoomReal = value; + } + + double remainder = value % 1; + if (remainder != 0) + { + float scaleValue = (float)Math.Pow(2d, remainder); { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - - GPoint rp = new GPoint(e.X, e.Y); #if !PocketPC - if(!MobileMode) - { - rp.OffsetNegative(Core.renderOffset); - } + MapRenderTransform = scaleValue; #endif - if(m.IsInside((int)rp.X, (int)rp.Y)) - { - if(!m.IsMouseOver) - { -#if !PocketPC - SetCursorHandOnEnter(); -#endif - m.IsMouseOver = true; - IsMouseOverRoute = true; - - if(OnRouteEnter != null) - { - OnRouteEnter(m); - } - - Invalidate(); - } - } - else - { - if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverRoute = false; -#if !PocketPC - RestoreCursorOnLeave(); -#endif - if(OnRouteLeave != null) - { - OnRouteLeave(m); - } - - Invalidate(); - } - } - #endregion - } } -#endif - foreach(GMapPolygon m in o.Polygons) - { - if(m.IsVisible && m.IsHitTestVisible) - { - #region -- check -- - if(m.IsInside(FromLocalToLatLng(e.X, e.Y))) - { - if(!m.IsMouseOver) - { + ZoomStep = Convert.ToInt32(value - remainder); + } + else + { #if !PocketPC - SetCursorHandOnEnter(); + MapRenderTransform = null; #endif - m.IsMouseOver = true; - IsMouseOverPolygon = true; + ZoomStep = Convert.ToInt32(value); + zoomReal = ZoomStep; + } - if(OnPolygonEnter != null) - { - OnPolygonEnter(m); - } - - Invalidate(); - } - } - else - { - if(m.IsMouseOver) - { - m.IsMouseOver = false; - IsMouseOverPolygon = false; -#if !PocketPC - RestoreCursorOnLeave(); -#endif - if(OnPolygonLeave != null) - { - OnPolygonLeave(m); - } - - Invalidate(); - } - } - #endregion - } - } - } - } - } - - if(renderHelperLine) - { - base.Invalidate(); + if (Core.IsStarted && !IsDragging) + { + ForceUpdateOverlays(); + } + } } - } + } - base.OnMouseMove(e); - } - -#if !PocketPC - - internal void RestoreCursorOnLeave() - { - if(overObjectCount == 0 && cursorBefore != null) - { - this.Cursor = this.cursorBefore; - cursorBefore = null; - } - } - - internal void SetCursorHandOnEnter() - { - if(overObjectCount == 0 && Cursor != Cursors.Hand) - { - cursorBefore = this.Cursor; - this.Cursor = Cursors.Hand; - } - } - - /// - /// prevents focusing map if mouse enters it's area - /// - public bool DisableFocusOnMouseEnter = false; - - protected override void OnMouseEnter(EventArgs e) - { - base.OnMouseEnter(e); - - if(!DisableFocusOnMouseEnter) - { - Focus(); - } - } - - /// - /// reverses MouseWheel zooming direction - /// - public bool InvertedMouseWheelZooming = false; - - /// - /// lets you zoom by MouseWheel even when pointer is in area of marker - /// - public bool IgnoreMarkerOnMouseWheel = false; - - protected override void OnMouseWheel(MouseEventArgs e) - { - base.OnMouseWheel(e); - - if((!IsMouseOverMarker || IgnoreMarkerOnMouseWheel) && !Core.IsDragging) - { - if(Core.mouseLastZoom.X != e.X && Core.mouseLastZoom.Y != e.Y) + /// + /// map zoom level + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + internal int ZoomStep + { + get { - if(MouseWheelZoomType == MouseWheelZoomType.MousePositionAndCenter) - { - Core.position = FromLocalToLatLng(e.X, e.Y); - } - else if(MouseWheelZoomType == MouseWheelZoomType.ViewCenter) - { - Core.position = FromLocalToLatLng((int)Width / 2, (int)Height / 2); - } - else if(MouseWheelZoomType == MouseWheelZoomType.MousePositionWithoutCenter) - { - Core.position = FromLocalToLatLng(e.X, e.Y); - } - - Core.mouseLastZoom.X = e.X; - Core.mouseLastZoom.Y = e.Y; + return Core.Zoom; } - - // set mouse position to map center - if(MouseWheelZoomType != MouseWheelZoomType.MousePositionWithoutCenter) + set { - if(!GMaps.Instance.IsRunningOnMono) - { - System.Drawing.Point p = PointToScreen(new System.Drawing.Point(Width / 2, Height / 2)); - Stuff.SetCursorPos((int)p.X, (int)p.Y); - } + if (value > MaxZoom) + { + Core.Zoom = MaxZoom; + } + else if (value < MinZoom) + { + Core.Zoom = MinZoom; + } + else + { + Core.Zoom = value; + } } + } - Core.MouseWheelZooming = true; - - if(e.Delta > 0) + /// + /// current map center position + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public PointLatLng Position + { + get { - if(!InvertedMouseWheelZooming) - { - Zoom++; - } - else - { - Zoom--; - } + return Core.Position; } - else if(e.Delta < 0) + set { - if(!InvertedMouseWheelZooming) - { - Zoom--; - } - else - { - Zoom++; - } + Core.Position = value; + + if (Core.IsStarted) + { + ForceUpdateOverlays(); + } } + } - Core.MouseWheelZooming = false; - } - } -#endif - #endregion - - #region IGControl Members - - /// - /// Call it to empty tile cache & reload tiles - /// - public void ReloadMap() - { - Core.ReloadMap(); - } - - /// - /// set current position using keywords - /// - /// - /// true if successfull - public GeoCoderStatusCode SetCurrentPositionByKeywords(string keys) - { - GeoCoderStatusCode status = GeoCoderStatusCode.Unknow; - - GeocodingProvider gp = MapProvider as GeocodingProvider; - if(gp == null) - { - gp = GMapProviders.OpenStreetMap as GeocodingProvider; - } - - if(gp != null) - { - var pt = gp.GetPoint(keys, out status); - if(status == GeoCoderStatusCode.G_GEO_SUCCESS && pt.HasValue) + /// + /// current position in pixel coordinates + /// + [Browsable(false)] + public GPoint PositionPixel + { + get { - Position = pt.Value; + return Core.PositionPixel; } - } + } - return status; - } - - /// - /// gets world coordinate from local control coordinate - /// - /// - /// - /// - public PointLatLng FromLocalToLatLng(int x, int y) - { -#if !PocketPC - if(MapRenderTransform.HasValue) - { - //var xx = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); - //var yy = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); - - //PointF center = new PointF(Core.Width / 2, Core.Height / 2); - - //Matrix m = new Matrix(); - //m.Translate(-Core.renderOffset.X, -Core.renderOffset.Y); - //m.Scale(MapRenderTransform.Value, MapRenderTransform.Value); - - //System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - //m.TransformPoints(tt); - //var z = tt[0]; - - // - - x = (int)(Core.renderOffset.X + ((x - Core.renderOffset.X) / MapRenderTransform.Value)); - y = (int)(Core.renderOffset.Y + ((y - Core.renderOffset.Y) / MapRenderTransform.Value)); - } - - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point(x, y) }; - rotationMatrixInvert.TransformPoints(tt); - var f = tt[0]; - - if(VirtualSizeEnabled) + /// + /// location of cache + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public string CacheLocation + { + get { - f.X += (Width - Core.vWidth) / 2; - f.Y += (Height - Core.vHeight) / 2; - } - - x = f.X; - y = f.Y; - } -#endif - return Core.FromLocalToLatLng(x, y); - } - - /// - /// gets local coordinate from world coordinate - /// - /// - /// - public GPoint FromLatLngToLocal(PointLatLng point) - { - GPoint ret = Core.FromLatLngToLocal(point); - -#if !PocketPC - if(MapRenderTransform.HasValue) - { - ret.X = (int)(Core.renderOffset.X + ((Core.renderOffset.X - ret.X) * -MapRenderTransform.Value)); - ret.Y = (int)(Core.renderOffset.Y + ((Core.renderOffset.Y - ret.Y) * -MapRenderTransform.Value)); - } - - if(IsRotated) - { - System.Drawing.Point[] tt = new System.Drawing.Point[] { new System.Drawing.Point((int)ret.X, (int)ret.Y) }; - rotationMatrix.TransformPoints(tt); - var f = tt[0]; - - if(VirtualSizeEnabled) - { - f.X += (Width - Core.vWidth) / 2; - f.Y += (Height - Core.vHeight) / 2; - } - - ret.X = f.X; - ret.Y = f.Y; - } - -#endif - return ret; - } - -#if !PocketPC - - /// - /// shows map db export dialog - /// - /// - public bool ShowExportDialog() - { - using(FileDialog dlg = new SaveFileDialog()) - { - dlg.CheckPathExists = true; - dlg.CheckFileExists = false; - dlg.AddExtension = true; - dlg.DefaultExt = "gmdb"; - dlg.ValidateNames = true; - dlg.Title = "GMap.NET: Export map to db, if file exsist only new data will be added"; - dlg.FileName = "DataExp"; - dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; - dlg.FilterIndex = 1; - dlg.RestoreDirectory = true; - - if(dlg.ShowDialog() == DialogResult.OK) - { - bool ok = GMaps.Instance.ExportToGMDB(dlg.FileName); - if(ok) - { - MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); - } - else - { - MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - return ok; - } - } - - return false; - } - - /// - /// shows map dbimport dialog - /// - /// - public bool ShowImportDialog() - { - using(FileDialog dlg = new OpenFileDialog()) - { - dlg.CheckPathExists = true; - dlg.CheckFileExists = false; - dlg.AddExtension = true; - dlg.DefaultExt = "gmdb"; - dlg.ValidateNames = true; - dlg.Title = "GMap.NET: Import to db, only new data will be added"; - dlg.FileName = "DataImport"; - dlg.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); - dlg.Filter = "GMap.NET DB files (*.gmdb)|*.gmdb"; - dlg.FilterIndex = 1; - dlg.RestoreDirectory = true; - - if(dlg.ShowDialog() == DialogResult.OK) - { - bool ok = GMaps.Instance.ImportFromGMDB(dlg.FileName); - if(ok) - { - MessageBox.Show("Complete!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Information); - ReloadMap(); - } - else - { - MessageBox.Show("Failed!", "GMap.NET", MessageBoxButtons.OK, MessageBoxIcon.Warning); - } - - return ok; - } - } - - return false; - } -#endif - - [Category("GMap.NET"), DefaultValue(0)] - public double Zoom - { - get - { - return zoomReal; - } - set - { - if(zoomReal != value) - { - Debug.WriteLine("ZoomPropertyChanged: " + zoomReal + " -> " + value); - - if(value > MaxZoom) - { - zoomReal = MaxZoom; - } - else if(value < MinZoom) - { - zoomReal = MinZoom; - } - else - { - zoomReal = value; - } - - double remainder = value % 1; - if(remainder != 0) - { - float scaleValue = (float)Math.Pow(2d, remainder); - { -#if !PocketPC - MapRenderTransform = scaleValue; -#endif - } - - ZoomStep = Convert.ToInt32(value - remainder); - } - else - { -#if !PocketPC - MapRenderTransform = null; -#endif - ZoomStep = Convert.ToInt32(value); - zoomReal = ZoomStep; - } - - if(Core.IsStarted && !IsDragging) - { - ForceUpdateOverlays(); - } - } - } - } - - /// - /// map zoom level - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - internal int ZoomStep - { - get - { - return Core.Zoom; - } - set - { - if(value > MaxZoom) - { - Core.Zoom = MaxZoom; - } - else if(value < MinZoom) - { - Core.Zoom = MinZoom; - } - else - { - Core.Zoom = value; - } - } - } - - /// - /// current map center position - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public PointLatLng Position - { - get - { - return Core.Position; - } - set - { - Core.Position = value; - - if(Core.IsStarted) - { - ForceUpdateOverlays(); - } - } - } - - /// - /// current position in pixel coordinates - /// - [Browsable(false)] - public GPoint PositionPixel - { - get - { - return Core.PositionPixel; - } - } - - /// - /// location of cache - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public string CacheLocation - { - get - { #if !DESIGN - return CacheLocator.Location; + return CacheLocator.Location; #else return string.Empty; #endif - } - set - { -#if !DESIGN - CacheLocator.Location = value; -#endif - } - } - - bool isDragging = false; - - /// - /// is user dragging map - /// - [Browsable(false)] - public bool IsDragging - { - get - { - return isDragging; - } - } - - bool isMouseOverMarker; - internal int overObjectCount = 0; - - /// - /// is mouse over marker - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverMarker - { - get - { - return isMouseOverMarker; - } - internal set - { - isMouseOverMarker = value; - overObjectCount += value ? 1 : -1; - } - } - - bool isMouseOverRoute; - - /// - /// is mouse over route - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverRoute - { - get - { - return isMouseOverRoute; - } - internal set - { - isMouseOverRoute = value; - overObjectCount += value ? 1 : -1; - } - } - - bool isMouseOverPolygon; - - /// - /// is mouse over polygon - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public bool IsMouseOverPolygon - { - get - { - return isMouseOverPolygon; - } - internal set - { - isMouseOverPolygon = value; - overObjectCount += value ? 1 : -1; - } - } - - /// - /// gets current map view top/left coordinate, width in Lng, height in Lat - /// - [Browsable(false)] - public RectLatLng ViewArea - { - get - { - return Core.ViewArea; - } - } - - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public GMapProvider MapProvider - { - get - { - return Core.Provider; - } - set - { - if(Core.Provider == null || !Core.Provider.Equals(value)) - { - Debug.WriteLine("MapType: " + Core.Provider.Name + " -> " + value.Name); - - RectLatLng viewarea = SelectedArea; - if(viewarea != RectLatLng.Empty) - { - Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2); - } - else - { - viewarea = ViewArea; - } - - Core.Provider = value; - - if(Core.IsStarted) - { - if(Core.zoomToArea) - { - // restore zoomrect as close as possible - if(viewarea != RectLatLng.Empty && viewarea != ViewArea) - { - int bestZoom = Core.GetMaxZoomToFitRect(viewarea); - if(bestZoom > 0 && Zoom != bestZoom) - { - Zoom = bestZoom; - } - } - } - else - { - ForceUpdateOverlays(); - } - } } - } - } - - /// - /// is routes enabled - /// - [Category("GMap.NET")] - public bool RoutesEnabled - { - get - { - return Core.RoutesEnabled; - } - set - { - Core.RoutesEnabled = value; - } - } - - /// - /// is polygons enabled - /// - [Category("GMap.NET")] - public bool PolygonsEnabled - { - get - { - return Core.PolygonsEnabled; - } - set - { - Core.PolygonsEnabled = value; - } - } - - /// - /// is markers enabled - /// - [Category("GMap.NET")] - public bool MarkersEnabled - { - get - { - return Core.MarkersEnabled; - } - set - { - Core.MarkersEnabled = value; - } - } - - /// - /// can user drag map - /// - [Category("GMap.NET")] - public bool CanDragMap - { - get - { - return Core.CanDragMap; - } - set - { - Core.CanDragMap = value; - } - } - - /// - /// map render mode - /// - [Browsable(false)] - public RenderMode RenderMode - { - get - { - return Core.RenderMode; - } - internal set - { - Core.RenderMode = value; - } - } - - /// - /// gets map manager - /// - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - [Browsable(false)] - public GMaps Manager - { - get - { - return GMaps.Instance; - } - } - - #endregion - - #region IGControl event Members - - /// - /// occurs when current position is changed - /// - public event PositionChanged OnPositionChanged - { - add - { - Core.OnCurrentPositionChanged += value; - } - remove - { - Core.OnCurrentPositionChanged -= value; - } - } - - /// - /// occurs when tile set load is complete - /// - public event TileLoadComplete OnTileLoadComplete - { - add - { - Core.OnTileLoadComplete += value; - } - remove - { - Core.OnTileLoadComplete -= value; - } - } - - /// - /// occurs when tile set is starting to load - /// - public event TileLoadStart OnTileLoadStart - { - add - { - Core.OnTileLoadStart += value; - } - remove - { - Core.OnTileLoadStart -= value; - } - } - - /// - /// occurs on map drag - /// - public event MapDrag OnMapDrag - { - add - { - Core.OnMapDrag += value; - } - remove - { - Core.OnMapDrag -= value; - } - } - - /// - /// occurs on map zoom changed - /// - public event MapZoomChanged OnMapZoomChanged - { - add - { - Core.OnMapZoomChanged += value; - } - remove - { - Core.OnMapZoomChanged -= value; - } - } - - /// - /// occures on map type changed - /// - public event MapTypeChanged OnMapTypeChanged - { - add - { - Core.OnMapTypeChanged += value; - } - remove - { - Core.OnMapTypeChanged -= value; - } - } - - /// - /// occurs on empty tile displayed - /// - public event EmptyTileError OnEmptyTileError - { - add - { - Core.OnEmptyTileError += value; - } - remove - { - Core.OnEmptyTileError -= value; - } - } - - #endregion - -#if !PocketPC - #region Serialization - - static readonly BinaryFormatter BinaryFormatter = new BinaryFormatter(); - - /// - /// Serializes the overlays. - /// - /// The stream. - public void SerializeOverlays(Stream stream) - { - if(stream == null) - { - throw new ArgumentNullException("stream"); - } - - // Create an array from the overlays - GMapOverlay[] overlayArray = new GMapOverlay[this.Overlays.Count]; - this.Overlays.CopyTo(overlayArray, 0); - - // Serialize the overlays - BinaryFormatter.Serialize(stream, overlayArray); - } - - /// - /// De-serializes the overlays. - /// - /// The stream. - public void DeserializeOverlays(Stream stream) - { - if(stream == null) - { - throw new ArgumentNullException("stream"); - } - - // De-serialize the overlays - GMapOverlay[] overlayArray = BinaryFormatter.Deserialize(stream) as GMapOverlay[]; - - // Populate the collection of overlays. - foreach(GMapOverlay overlay in overlayArray) - { - overlay.Control = this; - this.Overlays.Add(overlay); - } - - this.ForceUpdateOverlays(); - } - - #endregion + set + { +#if !DESIGN + CacheLocator.Location = value; #endif - } + } + } + + bool isDragging = false; + + /// + /// is user dragging map + /// + [Browsable(false)] + public bool IsDragging + { + get + { + return isDragging; + } + } + + bool isMouseOverMarker; + internal int overObjectCount = 0; + + /// + /// is mouse over marker + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverMarker + { + get + { + return isMouseOverMarker; + } + internal set + { + isMouseOverMarker = value; + overObjectCount += value ? 1 : -1; + } + } + + bool isMouseOverRoute; + + /// + /// is mouse over route + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverRoute + { + get + { + return isMouseOverRoute; + } + internal set + { + isMouseOverRoute = value; + overObjectCount += value ? 1 : -1; + } + } + + bool isMouseOverPolygon; + + /// + /// is mouse over polygon + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public bool IsMouseOverPolygon + { + get + { + return isMouseOverPolygon; + } + internal set + { + isMouseOverPolygon = value; + overObjectCount += value ? 1 : -1; + } + } + + /// + /// gets current map view top/left coordinate, width in Lng, height in Lat + /// + [Browsable(false)] + public RectLatLng ViewArea + { + get + { + return Core.ViewArea; + } + } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public GMapProvider MapProvider + { + get + { + return Core.Provider; + } + set + { + if (Core.Provider == null || !Core.Provider.Equals(value)) + { + Debug.WriteLine("MapType: " + Core.Provider.Name + " -> " + value.Name); + + RectLatLng viewarea = SelectedArea; + if (viewarea != RectLatLng.Empty) + { + Position = new PointLatLng(viewarea.Lat - viewarea.HeightLat / 2, viewarea.Lng + viewarea.WidthLng / 2); + } + else + { + viewarea = ViewArea; + } + + Core.Provider = value; + + if (Core.IsStarted) + { + if (Core.zoomToArea) + { + // restore zoomrect as close as possible + if (viewarea != RectLatLng.Empty && viewarea != ViewArea) + { + int bestZoom = Core.GetMaxZoomToFitRect(viewarea); + if (bestZoom > 0 && Zoom != bestZoom) + { + Zoom = bestZoom; + } + } + } + else + { + ForceUpdateOverlays(); + } + } + } + } + } + + /// + /// is routes enabled + /// + [Category("GMap.NET")] + public bool RoutesEnabled + { + get + { + return Core.RoutesEnabled; + } + set + { + Core.RoutesEnabled = value; + } + } + + /// + /// is polygons enabled + /// + [Category("GMap.NET")] + public bool PolygonsEnabled + { + get + { + return Core.PolygonsEnabled; + } + set + { + Core.PolygonsEnabled = value; + } + } + + /// + /// is markers enabled + /// + [Category("GMap.NET")] + public bool MarkersEnabled + { + get + { + return Core.MarkersEnabled; + } + set + { + Core.MarkersEnabled = value; + } + } + + /// + /// can user drag map + /// + [Category("GMap.NET")] + public bool CanDragMap + { + get + { + return Core.CanDragMap; + } + set + { + Core.CanDragMap = value; + } + } + + /// + /// map render mode + /// + [Browsable(false)] + public RenderMode RenderMode + { + get + { + return Core.RenderMode; + } + internal set + { + Core.RenderMode = value; + } + } + + /// + /// gets map manager + /// + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public GMaps Manager + { + get + { + return GMaps.Instance; + } + } + + #endregion + + #region IGControl event Members + + /// + /// occurs when current position is changed + /// + public event PositionChanged OnPositionChanged + { + add + { + Core.OnCurrentPositionChanged += value; + } + remove + { + Core.OnCurrentPositionChanged -= value; + } + } + + /// + /// occurs when tile set load is complete + /// + public event TileLoadComplete OnTileLoadComplete + { + add + { + Core.OnTileLoadComplete += value; + } + remove + { + Core.OnTileLoadComplete -= value; + } + } + + /// + /// occurs when tile set is starting to load + /// + public event TileLoadStart OnTileLoadStart + { + add + { + Core.OnTileLoadStart += value; + } + remove + { + Core.OnTileLoadStart -= value; + } + } + + /// + /// occurs on map drag + /// + public event MapDrag OnMapDrag + { + add + { + Core.OnMapDrag += value; + } + remove + { + Core.OnMapDrag -= value; + } + } + + /// + /// occurs on map zoom changed + /// + public event MapZoomChanged OnMapZoomChanged + { + add + { + Core.OnMapZoomChanged += value; + } + remove + { + Core.OnMapZoomChanged -= value; + } + } + + /// + /// occures on map type changed + /// + public event MapTypeChanged OnMapTypeChanged + { + add + { + Core.OnMapTypeChanged += value; + } + remove + { + Core.OnMapTypeChanged -= value; + } + } + + /// + /// occurs on empty tile displayed + /// + public event EmptyTileError OnEmptyTileError + { + add + { + Core.OnEmptyTileError += value; + } + remove + { + Core.OnEmptyTileError -= value; + } + } + + #endregion #if !PocketPC - public enum HelperLineOptions - { - DontShow = 0, - ShowAlways = 1, - ShowOnModifierKey = 2 - } + #region Serialization - public delegate void SelectionChange(RectLatLng Selection, bool ZoomToFit); + static readonly BinaryFormatter BinaryFormatter = new BinaryFormatter(); + + /// + /// Serializes the overlays. + /// + /// The stream. + public void SerializeOverlays(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + + // Create an array from the overlays + GMapOverlay[] overlayArray = new GMapOverlay[this.Overlays.Count]; + this.Overlays.CopyTo(overlayArray, 0); + + // Serialize the overlays + BinaryFormatter.Serialize(stream, overlayArray); + } + + /// + /// De-serializes the overlays. + /// + /// The stream. + public void DeserializeOverlays(Stream stream) + { + if (stream == null) + { + throw new ArgumentNullException("stream"); + } + + // De-serialize the overlays + GMapOverlay[] overlayArray = BinaryFormatter.Deserialize(stream) as GMapOverlay[]; + + // Populate the collection of overlays. + foreach (GMapOverlay overlay in overlayArray) + { + overlay.Control = this; + this.Overlays.Add(overlay); + } + + this.ForceUpdateOverlays(); + } + + #endregion +#endif + } + +#if !PocketPC + public enum HelperLineOptions + { + DontShow = 0, + ShowAlways = 1, + ShowOnModifierKey = 2 + } + + public delegate void SelectionChange(RectLatLng Selection, bool ZoomToFit); #endif } diff --git a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs index 305b3d2..eb7b174 100644 --- a/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs +++ b/ScoutBase/ScoutBase.Propagation/PropagationDatabase.cs @@ -460,32 +460,50 @@ namespace ScoutBase.Propagation // return null if elevation path is null for whatever reason if (ep == null) return null; - for (int i = 0; i < ep.Count; i++) + // using (StreamWriter sw = new StreamWriter(File.OpenWrite("propagation.csv"))) { - double dist1 = i * stepwidth / 1000.0; - double dist2 = (ep.Count - i - 1) * stepwidth / 1000.0; - double f1c1 = ScoutBase.Core.Propagation.F1Radius(qrg, dist1, dist2) * f1_clearance; - double f1c2 = ScoutBase.Core.Propagation.F1Radius(qrg, dist2, dist1) * f1_clearance; - double nf = NearFieldSuppression / 1000.0; - double eps1; - double eps2; - if (dist1 > nf) + // sw.WriteLine("i;dist1;dist2;f1c1;f1c2;elv;eps1;eps1_min;eps2;eps2_min"); + for (int i = 0; i < ep.Count; i++) { - eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); + double dist1 = i * stepwidth / 1000.0; + double dist2 = (ep.Count - i - 1) * stepwidth / 1000.0; + double f1c1 = ScoutBase.Core.Propagation.F1Radius(qrg, dist1, dist2) * f1_clearance; + double f1c2 = ScoutBase.Core.Propagation.F1Radius(qrg, dist2, dist1) * f1_clearance; + double nf = NearFieldSuppression / 1000.0; + double eps1; + double eps2; + if (dist1 > nf) + eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, dist1, ep.Path[i] + f1c1, radius); + else + eps1 = ScoutBase.Core.Propagation.EpsilonFromHeights(h1, nf, ep.Path[i] + f1c1, radius); if (eps1 > eps1_min) eps1_min = eps1; - } - if (dist2 > nf) - { - eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); + if (dist2 > nf) + eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, dist2, ep.Path[i] + f1c2, radius); + else + eps2 = ScoutBase.Core.Propagation.EpsilonFromHeights(h2, nf, ep.Path[i] + f1c2, radius); if (eps2 > eps2_min) eps2_min = eps2; - } - if (caller != null) - { - // abort calculation if cancellation pending - if (caller.WorkerSupportsCancellation && caller.CancellationPending) - return null; + if (caller != null) + { + // abort calculation if cancellation pending + if (caller.WorkerSupportsCancellation && caller.CancellationPending) + return null; + } + /* + sw.WriteLine( + i.ToString() + ";" + + dist1.ToString("F8") + ";" + + dist2.ToString("F8") + ";" + + f1c1.ToString("F8") + ";" + + f1c2.ToString("F8") + ";" + + ep.Path[i].ToString() + ";" + + eps1.ToString("F8") + ";" + + eps1_min.ToString("F8") + ";" + + eps2.ToString("F8") + ";" + + eps2_min.ToString("F8") + ); + */ } } PropagationPathDesignator pp = new PropagationPathDesignator(lat1, lon1, h1, lat2, lon2, h2, qrg, radius, f1_clearance, stepwidth, eps1_min, eps2_min, localobstruction);