Skip to content

Commit

Permalink
ConfigPanner : Gmaps Acces Mode
Browse files Browse the repository at this point in the history
Add ComboBox in ConfigPlanner to choose if map is loaded from cache only, server only or cache and server (default). This setting is saved in the config.xml
Add button in ConfigPlanner to Open Map Cache Folder
SRTM files are downloaded if GMaps Access Mode is not CacheOnly
  • Loading branch information
Godeffroy committed Jun 10, 2024
1 parent d902629 commit 7c353ea
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 10 deletions.
15 changes: 9 additions & 6 deletions ExtLibs/Utilities/srtm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Net.Http;
using System.Threading.Tasks;
using log4net;
using GMap.NET;

namespace MissionPlanner.Utilities
{
Expand Down Expand Up @@ -388,16 +389,18 @@ public static altresponce getAltitude(double lat, double lng, double zoom = 16)
if (!Directory.Exists(datadirectory))
Directory.CreateDirectory(datadirectory);

lock (objlock)
if (GMaps.Instance.Mode != AccessMode.CacheOnly)
{
if (!queue.Contains(filename))
lock (objlock)
{
log.Info("Getting " + filename);
queue.Add(filename);
requestSemaphore.Release();
if (!queue.Contains(filename))
{
log.Info("Getting " + filename);
queue.Add(filename);
requestSemaphore.Release();
}
}
}

}
}
}
Expand Down
29 changes: 29 additions & 0 deletions GCSViews/ConfigurationView/ConfigPlanner.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions GCSViews/ConfigurationView/ConfigPlanner.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using DirectShowLib;
using MissionPlanner.Controls;
using MissionPlanner.Joystick;
using MissionPlanner.Maps;
using MissionPlanner.Utilities;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
Expand Down Expand Up @@ -240,6 +242,15 @@ public void Activate()
chk_displaytooltip.Checked = Settings.Instance.GetString("mapicondesc", "") != "";
num_linelength.Value = Settings.Instance.GetInt32("GMapMarkerBase_Length", 500);

CMB_mapCache.DataSource = Enum.GetNames(typeof(GMap.NET.AccessMode));
try
{
CMB_mapCache.SelectedIndex = CMB_mapCache.Items.IndexOf(Settings.Instance["mapCache"] ?? GMap.NET.GMaps.Instance.Mode.ToString());
}
catch
{
}

startup = false;
}

Expand Down Expand Up @@ -1125,5 +1136,38 @@ private void cmb_secondarydisplaystyle_SelectedIndexChanged(object sender, Event
Maps.GMapMarkerBase.InactiveDisplayStyle = Maps.GMapMarkerBase.InactiveDisplayStyleEnum.Normal;
}
}

private void CMB_mapCache_SelectedIndexChanged(object sender, EventArgs e)
{
if (startup)
return;
Settings.Instance["mapCache"] = CMB_mapCache.Text;
GMap.NET.GMaps.Instance.Mode = (GMap.NET.AccessMode)Enum.Parse(typeof(GMap.NET.AccessMode), Settings.Instance["mapCache"].ToString());
}

private void BUT_mapCacheDir_Click(object sender, EventArgs e)
{
try
{
string folderPath = MyImageCache.Instance.CacheLocation;
if (Directory.Exists(folderPath))
{
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = folderPath,
FileName = "explorer.exe"
};

Process.Start(startInfo);
}
else
{
MessageBox.Show(string.Format("{0} Directory does not exist!", folderPath));
}
}
catch (Exception)
{
}
}
}
}
83 changes: 79 additions & 4 deletions GCSViews/ConfigurationView/ConfigPlanner.resx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@
<value>NOTE: Set the low level of SEVERITY to speak</value>
</data>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
<value>949, 643</value>
<value>949, 693</value>
</data>
<data name="CMB_raterc.Items14" xml:space="preserve">
<value>50</value>
Expand Down Expand Up @@ -2835,11 +2835,86 @@
</data>
<data name="CMB_rateattitude.Items1" xml:space="preserve">
<value>0</value>
</data>
<data name="CMB_mapCache.Location" type="System.Drawing.Point, System.Drawing">
<value>107, 653</value>
</data>
<data name="CMB_mapCache.Size" type="System.Drawing.Size, System.Drawing">
<value>138, 21</value>
</data>
<data name="CMB_mapCache.TabIndex" type="System.Int32, mscorlib">
<value>127</value>
</data>
<data name="&gt;&gt;CMB_mapCache.Name" xml:space="preserve">
<value>CMB_mapCache</value>
</data>
<data name="&gt;&gt;CMB_mapCache.Type" xml:space="preserve">
<value>System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;CMB_mapCache.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;CMB_mapCache.ZOrder" xml:space="preserve">
<value>80</value>
</data>
<data name="label13.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="label13.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="label13.Location" type="System.Drawing.Point, System.Drawing">
<value>9, 656</value>
</data>
<data name="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 13</value>
</data>
<data name="label13.TabIndex" type="System.Int32, mscorlib">
<value>50</value>
</data>
<data name="label13.Text" xml:space="preserve">
<value>Map Access Mode</value>
</data>
<data name="&gt;&gt;label13.Name" xml:space="preserve">
<value>label13</value>
</data>
<data name="&gt;&gt;label13.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label13.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;label13.ZOrder" xml:space="preserve">
<value>79</value>
</data>
<data name="BUT_mapCacheDir.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="BUT_mapCacheDir.Location" type="System.Drawing.Point, System.Drawing">
<value>251, 653</value>
</data>
<data name="BUT_mapCacheDir.Size" type="System.Drawing.Size, System.Drawing">
<value>94, 21</value>
</data>
<data name="BUT_mapCacheDir.TabIndex" type="System.Int32, mscorlib">
<value>95</value>
</data>
<data name="BUT_mapCacheDir.Text" xml:space="preserve">
<value>Open Map Cache</value>
</data>
<data name="&gt;&gt;BUT_mapCacheDir.Name" xml:space="preserve">
<value>BUT_mapCacheDir</value>
</data>
<data name="&gt;&gt;BUT_mapCacheDir.Type" xml:space="preserve">
<value>MissionPlanner.Controls.MyButton, MissionPlanner.Controls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;BUT_mapCacheDir.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;BUT_mapCacheDir.ZOrder" xml:space="preserve">
<value>81</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="$this.Language" type="System.Globalization.CultureInfo, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>zh-TW</value>
</metadata>
</root>
5 changes: 5 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ public static void Start(string[] args)
Console.WriteLine("Setup GMaps 1");
// set the cache provider to my custom version
GMap.NET.GMaps.Instance.PrimaryCache = new Maps.MyImageCache();
if (Settings.Instance["mapCache"] != null)
{
GMap.NET.GMaps.Instance.Mode = (GMap.NET.AccessMode)Enum.Parse(typeof(GMap.NET.AccessMode), Settings.Instance["mapCache"].ToString());
log.Info("Map access mode set to : " + GMap.NET.GMaps.Instance.Mode.ToString());
}
Console.WriteLine("Setup GMaps 2");
// add my custom map providers
GMap.NET.MapProviders.GMapProviders.List.Add(Maps.WMSProvider.Instance);
Expand Down

0 comments on commit 7c353ea

Please sign in to comment.