Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlightPlanner : tweak prefetch, Resolves #2591, resolves #2483 #3320

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ExtLibs/GMap.NET.Core/GMap.NET/GMaps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,31 @@ public PureImage GetImageFrom(GMapProvider provider, GPoint pos, int zoom, out E

readonly Exception noDataException = new Exception("No data in local tile cache...");

public bool CheckImageExist(GMapProvider provider, GPoint pos, int zoom, out Exception result)
{
result = null;
try
{
if (Mode != AccessMode.ServerOnly && !provider.BypassCache)
{
if (PrimaryCache != null)
{
return PrimaryCache.CheckImageFromCache(provider.DbId, pos, zoom);
}

if (SecondaryCache != null)
{
return SecondaryCache.CheckImageFromCache(provider.DbId, pos, zoom);
}
}
}
catch (Exception ex)
{
Debug.WriteLine("CheckImageExist: " + ex.ToString());
}
return false;
}

#if !PocketPC
TileHttpHost host;

Expand Down
9 changes: 9 additions & 0 deletions ExtLibs/GMap.NET.Core/GMap.NET/PureImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,14 @@ public interface PureImageCache
/// <param name="type">provider dbid or null to use all providers</param>
/// <returns>The number of deleted tiles.</returns>
int DeleteOlderThan(DateTime date, int ? type);

/// <summary>
/// check if image exist on db
/// </summary>
/// <param name="type"></param>
/// <param name="pos"></param>
/// <param name="zoom"></param>
/// <returns>True if Image Exist, false otherwise</returns>
bool CheckImageFromCache(int type, GPoint pos, int zoom);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,22 @@ bool CacheTiles(int zoom, GPoint p)
foreach(var pr in provider.Overlays)
{
Exception ex;
PureImage img;
PureImage img = null;

// tile number inversion(BottomLeft -> TopLeft)
if(pr.InvertedAxisY)
{
img = GMaps.Instance.GetImageFrom(pr, new GPoint(p.X, maxOfTiles.Height - p.Y), zoom, out ex);
if (GMaps.Instance.CheckImageExist(pr, new GPoint(p.X, maxOfTiles.Height - p.Y), zoom, out ex))
return true;
else
img = GMaps.Instance.GetImageFrom(pr, new GPoint(p.X, maxOfTiles.Height - p.Y), zoom, out ex);
}
else // ok
{
img = GMaps.Instance.GetImageFrom(pr, p, zoom, out ex);
if (GMaps.Instance.CheckImageExist(pr, p, zoom, out ex))
return true;
else
img = GMaps.Instance.GetImageFrom(pr, p, zoom, out ex);
}

if(img != null)
Expand Down Expand Up @@ -295,8 +301,10 @@ void worker_DoWork(object sender, DoWorkEventArgs e)

void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
try{
this.label1.Text = "Fetching tile at zoom (" + zoom + "): " + ((int)e.UserState).ToString() + " of " + all + ", complete: " + e.ProgressPercentage.ToString() + "%";
this.progressBarDownload.Value = e.ProgressPercentage;
int percent = Math.Max(0, Math.Min(100, e.ProgressPercentage));
this.progressBarDownload.Value = percent;

if (Overlay != null)
{
Expand All @@ -323,6 +331,10 @@ void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
Overlay.Markers.Add(m);
}
}
}
catch (Exception)
{
}
}

private void Prefetch_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
Expand Down
31 changes: 31 additions & 0 deletions ExtLibs/Maps/MyImageCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,37 @@ int PureImageCache.DeleteOlderThan(DateTime date, int? type)
return affectedRows;
}

public bool CheckImageFromCache(int type, GPoint pos, int zoom)
{
bool ret = false;
if (Created)
{
try
{
string file = CacheLocation + Path.DirectorySeparatorChar + GMapProviders.TryGetProvider(type).Name +
Path.DirectorySeparatorChar + zoom + Path.DirectorySeparatorChar + pos.Y +
Path.DirectorySeparatorChar + pos.X + ".jpg";
if (File.Exists(file))
{
ret = true;
}
else
{
ret = false;
}
}
catch (Exception ex)
{
#if MONO
Console.WriteLine("CheckImageFromCache: " + ex.ToString());
#endif
Debug.WriteLine("CheckImageFromCache: " + ex.ToString());
ret = false;
}
}
return ret;
}

#endregion
}
}
27 changes: 26 additions & 1 deletion GCSViews/FlightPlanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5031,7 +5031,28 @@ public void prefetchToolStripMenuItem_Click(object sender, EventArgs e)

maxzoom = Math.Min(maxzoom, MainMap.MaxZoom);

for (int i = 1; i <= maxzoom; i++)
string minzoomstring = "1";
if (InputBox.Show("min zoom", "Enter the min zoom to prefetch to.", ref minzoomstring) !=
DialogResult.OK)
return;

int minzoom = 20;
if (!int.TryParse(minzoomstring, out minzoom))
{
CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR);
return;
}
minzoom = Math.Max(minzoom, MainMap.MinZoom);

if (minzoom > maxzoom)
{
CustomMessageBox.Show(Strings.InvalidNumberEntered, Strings.ERROR);
return;
}

for (int i = minzoom; i <= maxzoom; i++)
{
try
{
TilePrefetcher obj = new TilePrefetcher();
ThemeManager.ApplyThemeTo(obj);
Expand All @@ -5046,6 +5067,10 @@ public void prefetchToolStripMenuItem_Click(object sender, EventArgs e)

obj.Dispose();
}
catch
{
}
}
}
else
{
Expand Down
Loading