Skip to content

Commit

Permalink
Unit test to test the PrefetchToFolder() method related to the questi…
Browse files Browse the repository at this point in the history
…on in #117
  • Loading branch information
pmeems committed Aug 24, 2018
1 parent 0b226cb commit b58342a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
30 changes: 25 additions & 5 deletions unittests/MapWinGISTests/TilesTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Threading;
using AxMapWinGIS;
using MapWinGIS;
using Microsoft.VisualStudio.TestTools.UnitTesting;
Expand Down Expand Up @@ -46,17 +47,36 @@ public void ShowProviderDetails()
public void PrefetchToFolder()
{
Console.WriteLine("Tiles projection status: " + _axMap1.Tiles.ProjectionStatus);
Console.WriteLine("_axMap1.Extents: " + _axMap1.Extents.ToDebugString());
Console.WriteLine("_axMap1.Tiles.ProjectionIsSphericalMercator: " + _axMap1.Tiles.ProjectionIsSphericalMercator);

var outputFolder = $@"D:\tmp\axmap.tiles\{_axMap1.Tiles.Provider.ToString()}";
if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder);

var latLongExtents = new Extents();
latLongExtents.SetBounds(3.3700, 50.7500, 0, 7.2100, 53.4700, 0); // The Netherlands in WGS84: http://spatialreference.org/ref/epsg/28992/
var providerId = Convert.ToInt32(tkTileProvider.OpenStreetMap);
var numRounds = 0; // To prevent endless loops
while (true)
{
var numTilesToCache = 0;
for (var i = _axMap1.Tiles.MinZoom; i < 10; i++)
{
numTilesToCache +=
_axMap1.Tiles.PrefetchToFolder(latLongExtents, i, providerId, outputFolder, ".png", this);
Console.WriteLine($"numTilesToCache: {numTilesToCache} for zoom {i}");
// Wait a moment:
Thread.Sleep(2000);
}

numRounds++;
Console.WriteLine($"Finished round {numRounds}");

var numTilesToCache = _axMap1.Tiles.PrefetchToFolder(_axMap1.Extents, 5,
Convert.ToInt32(tkTileProvider.OpenStreetMap), outputFolder, ".png", this);
Console.WriteLine("numTilesToCache: " + numTilesToCache);
// Wait before doing another round:
if (numTilesToCache > 0) Thread.Sleep(2000);
if (numTilesToCache == 0 || numRounds > 9) break;
}
}


public void Progress(string KeyOfSender, int Percent, string Message)
{
Console.WriteLine($"{Percent} {Message}");
Expand Down
8 changes: 4 additions & 4 deletions unittests/TestExecutor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public static void Main(string[] args)
//var t = new PostGisTest();
//t.ReadAttributesFromPostGISLayer();

var t = new ShapefileTests();
// var t = new ShapefileTests();
//t.ShapefileDataTest();
t.UnionShapefiles();
// t.UnionShapefiles();

//t.Reproject2280Test();
//t.ReadRussionDataFromTable();
Expand Down Expand Up @@ -78,8 +78,8 @@ public static void Main(string[] args)
//t.ClipPolygon();
//t.PointInPolygon();

//var t = new TilesTests();
//t.PrefetchToFolder();
var t = new TilesTests();
t.PrefetchToFolder();

Console.WriteLine("Finished");
Console.ReadLine();
Expand Down

0 comments on commit b58342a

Please sign in to comment.