public void TileFetcherShouldBehaveProperlyWithNoisyResponses() { // Arrange var schema = new GlobalSphericalMercator(); var tileSource = new TileSource(new SometimesFailingTileProvider(), schema); var memoryCache = new MemoryCache <Feature>(14, 17); var tileFetcher = new TileFetcher(tileSource, memoryCache); var random = new Random(31747074); var tiles = new List <Feature>(); // Act for (int i = 0; i < 100; i++) { var randomLevel = "5"; var randomCol = random.Next(schema.GetMatrixWidth(randomLevel)); var randomRow = random.Next(schema.GetMatrixHeight(randomLevel)); var tileRange = new TileRange(randomCol - 2, randomRow - 2, 5, 5); var unitsPerPixel = schema.Resolutions[randomLevel].UnitsPerPixel; var extent = TileTransform.TileToWorld(tileRange, randomLevel, schema); tileFetcher.ViewChanged(TileTransform.TileToWorld(tileRange, randomLevel, schema).ToBoundingBox(), unitsPerPixel); var tileInfos = schema.GetTileInfos(extent, randomLevel); foreach (var tileInfo in tileInfos) { tiles.Add(memoryCache.Find(tileInfo.Index)); } } // Assert Assert.True(tiles.Count > 0); Assert.True(memoryCache.TileCount == 0); }
public static ITileSource CreateTileSource(string urlString, string layerName, string CRS) { var schema = new GlobalSphericalMercator("png", YAxis.OSM, 0, 21, null); var layers = new List <string>(); layers.Add(layerName); var styles = new List <string>(); if (!urlString.ToLower().Contains("&version=")) { urlString = urlString + "&version=1.3.0"; } if (!urlString.ToLower().Contains("&crs=")) { urlString = urlString + "&CRS=" + CRS; } if (!urlString.ToLower().Contains("&format=")) { urlString = urlString + "&format=png"; } if (!urlString.ToLower().Contains("&transparent=")) { urlString = urlString + "&transparent=true"; } var request = new WmscRequest(new Uri(urlString), schema, layers, new string[0].ToList()); var provider = new HttpTileProvider(request); return(new TileSource(provider, schema)); }
public void TileFetcherShouldRequestAllTilesJustOnes() { // Arrange var tileProvider = new CountingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); using var cache = new MemoryCache <IFeature?>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var level = 3; var expectedTiles = 64; var fetchInfo = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel); // Act // Get all tiles of level 3 fetchDispatcher.SetViewport(fetchInfo); tileMachine.Start(); // Assert while (fetchDispatcher.Busy) { Thread.Sleep(1); } Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Keys.Count); Assert.AreEqual(expectedTiles, tileProvider.CountByTile.Values.Sum()); Assert.AreEqual(expectedTiles, tileProvider.TotalCount); }
public void RepeatedRestartsShouldNotCauseInfiniteLoop() { // Arrange var tileProvider = new CountingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); using var cache = new MemoryCache <IFeature?>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var numberOfWorkers = 8; var numberOfRestarts = 3; var fetchInfo = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[3].UnitsPerPixel); // Act for (var i = 0; i < numberOfRestarts; i++) { fetchDispatcher.SetViewport(fetchInfo); tileMachine.Start(); while (fetchDispatcher.Busy) { Thread.Sleep(1); } } // Assert Assert.Greater(numberOfWorkers * numberOfRestarts, FetchWorker.RestartCounter); }
[Test] // handing in build server but not on client public void TileFetcherShouldBehaveProperlyWithTileProviderReturningNull() { // Arrange var schema = new GlobalSphericalMercator(); var tileSource = new TileSource(new NullTileProvider(), schema); var memoryCache = new MemoryCache <Feature>(); var tileFetcher = new TileFetcher(tileSource, memoryCache); // Act Task.Run(() => { Task.Delay(5000); if (tileFetcher.Busy) { Assert.Fail("The fetcher hangs"); } }); tileFetcher.ViewChanged(schema.Extent.ToBoundingBox(), schema.Resolutions["2"].UnitsPerPixel); while (tileFetcher.Busy) { } // Assert Assert.True(memoryCache.TileCount == 0); }
public ITileSource CreateTileSource() { var request = (HttpWebRequest)WebRequest.Create(_url); request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14"; var response = (HttpWebResponse)request.GetResponse(); var stream = response.GetResponseStream(); var tileSource = TileMapParser.CreateTileSource(stream); var s = new GlobalSphericalMercator(); // now remove all resolutions that are not in the Tilesource. // For example Strava level 18 we must not draw. var l = new List <String>(); foreach (var res in s.Resolutions) { var r = tileSource.Schema.Resolutions.ContainsKey(res.Key); if (!r) { l.Add(res.Key); } } foreach (var p in l) { s.Resolutions.Remove(p); } return(new TileSource(tileSource.Provider, s)); }
public void TestTimer() { // arrange DefaultRendererFactory.Create = () => new MapRenderer(); using var memoryLayer = CreatePointLayer(); using var layer = new RasterizingLayer(memoryLayer); var schema = new GlobalSphericalMercator(); var box = schema.Extent.ToMRect(); var resolution = schema.Resolutions.First().Value.UnitsPerPixel; using var waitHandle = new AutoResetEvent(false); Assert.AreEqual(0, layer.GetFeatures(box, resolution).Count()); layer.DataChanged += (_, _) => { // assert waitHandle.Set(); }; var fetchInfo = new FetchInfo(box, resolution, null, ChangeType.Discrete); // act layer.RefreshData(fetchInfo); // assert waitHandle.WaitOne(); Assert.AreEqual(layer.GetFeatures(box, resolution).Count(), 1); }
public void TileFetcherWithFailingFetchesShouldTryAgain() { // Arrange var tileProvider = new FailingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var cache = new MemoryCache <Feature>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var level = "3"; var tilesInLevel = 64; // Act fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); tileMachine.Start(); while (fetchDispatcher.Busy) { } // do it again fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); tileMachine.Start(); while (fetchDispatcher.Busy) { } // Assert Assert.AreEqual(tilesInLevel * 2, tileProvider.TotalCount); // tried all tiles twice }
public QuantizedMeshTileSource(string url, string ext = "terrain") { var request = new TmsRequest(new Uri(url), ext); Provider = new WebTileProvider(request, fetchTile: FetchTile); Schema = new GlobalSphericalMercator(); }
public void TileRequestThatReturnsNullShouldNotBeRequestedAgain() { // Arrange var tileProvider = new NullTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var cache = new MemoryCache <Feature>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var level = "3"; var tilesInLevel = 64; // Act fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); tileMachine.Start(); while (fetchDispatcher.Busy) { } // do it again fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); tileMachine.Start(); while (fetchDispatcher.Busy) { Thread.Sleep(1); } // Assert Assert.AreEqual(tilesInLevel, tileProvider.TotalCount); }
public void TestTimer() { // arrange var layer = new RasterizingLayer(CreatePointLayer()); var schema = new GlobalSphericalMercator(); var box = schema.Extent.ToBoundingBox(); var resolution = schema.Resolutions.First().Value.UnitsPerPixel; var waitHandle = new AutoResetEvent(false); DefaultRendererFactory.Create = () => new MapRenderer(); // Using xaml renderer here to test rasterizer. Suboptimal. Assert.AreEqual(0, layer.GetFeaturesInView(box, resolution).Count()); layer.DataChanged += (sender, args) => { // assert waitHandle.Set(); }; // act layer.RefreshData(box, resolution, ChangeType.Discrete); // assert waitHandle.WaitOne(); Assert.AreEqual(layer.GetFeaturesInView(box, resolution).Count(), 1); }
public MapBoxVectorTileSource(string url, string ext = "pbf") { var request = new TmsRequest(new Uri(url), ext); Provider = new WebTileProvider(request, fetchTile: FetchTile); Schema = new GlobalSphericalMercator(); }
public void TileFetcherWithFailingFetchesShouldTryAgain() { // Arrange var tileProvider = new FailingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); using var cache = new MemoryCache <IFeature?>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, async tileInfo => await TileToFeatureAsync(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var level = 3; var tilesInLevel = 64; var fetchInfo = new FetchInfo(tileSchema.Extent.ToMRect(), tileSchema.Resolutions[level].UnitsPerPixel); // Act fetchDispatcher.SetViewport(fetchInfo); tileMachine.Start(); while (fetchDispatcher.Busy) { Thread.Sleep(1); } // Act again fetchDispatcher.SetViewport(fetchInfo); tileMachine.Start(); while (fetchDispatcher.Busy) { Thread.Sleep(1); } // Assert Assert.AreEqual(tilesInLevel * 2, tileProvider.TotalCount); // tried all tiles twice }
public void RepeatedRestartsShouldNotCauseInfiniteLoop() { // Arrange var tileProvider = new CountingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var cache = new MemoryCache <Feature>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var numberOfWorkers = 8; var numberOfRestarts = 3; // Act for (int i = 0; i < numberOfRestarts; i++) { fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions["3"].UnitsPerPixel); tileMachine.Start(); while (fetchDispatcher.Busy) { } } // Assert Assert.Greater(numberOfWorkers * numberOfRestarts, FetchWorker.RestartCounter); }
public static ITileSchema GetTileSchema() { var schema = new GlobalSphericalMercator(YAxis.OSM); schema.Resolutions.Clear(); schema.Resolutions["0"] = new Resolution("0", 156543.033900000); schema.Resolutions["1"] = new Resolution("1", 78271.51695); schema.Resolutions["2"] = new Resolution("2", 39135.758475); schema.Resolutions["3"] = new Resolution("3", 19567.8792375); schema.Resolutions["4"] = new Resolution("4", 9783.93961875); schema.Resolutions["5"] = new Resolution("5", 4891.969809375); schema.Resolutions["6"] = new Resolution("6", 2445.9849046875); schema.Resolutions["7"] = new Resolution("7", 1222.99245234375); schema.Resolutions["8"] = new Resolution("8", 611.496226171875); schema.Resolutions["9"] = new Resolution("9", 305.748113085938); schema.Resolutions["10"] = new Resolution("10", 152.874056542969); schema.Resolutions["11"] = new Resolution("11", 76.4370282714844); schema.Resolutions["12"] = new Resolution("12", 38.2185141357422); schema.Resolutions["13"] = new Resolution("13", 19.1092570678711); schema.Resolutions["14"] = new Resolution("14", 9.55462853393555); schema.Resolutions["15"] = new Resolution("15", 4.77731426696777); schema.Resolutions["16"] = new Resolution("16", 2.38865713348389); schema.Resolutions["17"] = new Resolution("17", 1.19432856674194); return(schema); }
public void TileFetcherShouldRequestAllTilesJustOnes() { // Arrange var tileProvider = new CountingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var tileFetcher = new TileFetcher(tileSource, new MemoryCache <Feature>(), 2, 8, new MinimalFetchStrategy()); var level = "4"; var expextedTiles = 256; // Act // Get all tiles of level 3 tileFetcher.ViewChanged(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); // Assert while (tileFetcher.Busy) { } Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Keys.Count); //!!! This is an actual bug: Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Values.Sum()); //!!! This is an actual bug: Assert.AreEqual(expextedTiles, tileProvider.TotalCount); Assert.Pass("The fetcher did not go into an infinite loop"); }
public void TileFetcherWithReturningNull() { // Arrange var tileProvider = new NullTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var tileFetcher = new TileFetcher(tileSource, new MemoryCache <Feature>()); // Act for (int i = 0; i < 300; i++) { for (int j = 0; j < 5; j++) { tileFetcher.ViewChanged(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[j.ToString()].UnitsPerPixel); System.Threading.Thread.Sleep(10); } } // Assert while (tileFetcher.Busy) { } ; Assert.Pass("The fetcher did not go into an infinite loop"); }
public void TileFetcherShouldRequestAllTilesJustOnes() { // Arrange var tileProvider = new CountingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var cache = new MemoryCache <Feature>(); var fetchDispatcher = new TileFetchDispatcher(cache, tileSource.Schema, (tileInfo) => TileToFeature(tileSource, tileInfo)); var tileMachine = new FetchMachine(fetchDispatcher); var level = "4"; var expextedTiles = 256; // Act // Get all tiles of level 3 fetchDispatcher.SetViewport(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[level].UnitsPerPixel); tileMachine.Start(); // Assert while (fetchDispatcher.Busy) { } Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Keys.Count); Assert.AreEqual(expextedTiles, tileProvider.CountByTile.Values.Sum()); Assert.AreEqual(expextedTiles, tileProvider.TotalCount); }
public ITileSource CreateTileSource() { var tileSchema = new GlobalSphericalMercator(); var tileLayerRequest = new BasicRequest(_url, Domains); var tileProvider = new WebTileProvider(tileLayerRequest); var tileSource = new TileSource(tileProvider, tileSchema); return(tileSource); }
public static ITileSchema GetTileSchema() { var schema = new GlobalSphericalMercator(YAxis.TMS); schema.Resolutions.Clear(); schema.Resolutions["0"] = new Resolution("0", 156543.033900000); schema.Resolutions["1"] = new Resolution("1", 78271.516950000); return(schema); }
public void TestGlobalSphericalMercatorSchema() { string message; var s1 = new GlobalSphericalMercator("png", YAxis.OSM, 2, 11); var s2 = SandD(s1); var equal = EqualTileSchemas(s1, s2, out message); Assert.IsTrue(equal, message); }
public GeodanWorldWmsTileSource() { var schema = new GlobalSphericalMercator(YAxis.TMS) { Srs = "EPSG:900913" }; Provider = new HttpTileProvider(CreateWmsRequest(schema)); Schema = schema; }
public void TestGetNearestLevel() { // arrange var schema = new GlobalSphericalMercator(); // act var levelId = Utilities.GetNearestLevel(schema.Resolutions, 300.0); // assert Assert.True(levelId == "9"); }
public GeodanWorldTmsTileSource() { const string url = "http://geoserver.nl/tiles/tilecache.aspx/1.0.0/world_GM/"; var parameters = new Dictionary <string, string>(); parameters.Add("seriveparam", "world_GM"); parameters.Add("uid", "4c6b3b161be3a2eb513b66b09a70f18d"); var request = new TmsRequest(new Uri(url), "png", parameters); Provider = new WebTileProvider(request); Schema = new GlobalSphericalMercator(YAxis.TMS); }
private void button7_Click(object sender, EventArgs e) { ITileSchema schema = new GlobalSphericalMercator(); ILayer[] layers = CreateLayers(); SharpMapTileSource source = new SharpMapTileSource(schema, layers); TileAsyncLayer osmLayer = new TileAsyncLayer(source, "TileLayer - SharpMap"); this.mapBox1.Map.BackgroundLayer.Clear(); this.mapBox1.Map.BackgroundLayer.Add(osmLayer); this.mapBox1.Refresh(); }
public ITileSource CreateTileSource() { var tileSchema = new GlobalSphericalMercator(); var servers = new List <string> { "01", "02", "03", "04" }; var yandexRequest = new BasicRequest(_url, servers); var tileProvider = new WebTileProvider(yandexRequest); var tileSource = new TileSource(tileProvider, tileSchema); return(tileSource); }
public void WorldToTileShouldReturnCorrectTileRange() { // arrange var expectedRange = new TileRange(1, 2); var schema = new GlobalSphericalMercator(YAxis.TMS); var extent = new Extent(-15028130, -10018753, -10018755, -5009378); // act var range = TileTransform.WorldToTile(extent, 3, schema); // assert Assert.AreEqual(range, expectedRange); }
public static ITileSchema GetTileSchema() { var schema = new GlobalSphericalMercator(YAxis.TMS); schema.Resolutions.Clear(); schema.Resolutions["0"] = new Resolution { Id = "0", UnitsPerPixel = 156543.033900000 }; schema.Resolutions["1"] = new Resolution { Id = "1", UnitsPerPixel = 78271.516950000 }; return(schema); }
private static ITileCache <IFeature?> PopulateMemoryCache(GlobalSphericalMercator schema, MemoryCache <IFeature?> cache, int levelId) { for (var i = levelId; i >= 0; i--) { var tiles = schema.GetTileInfos(schema.Extent, i); foreach (var tile in tiles) { if ((tile.Index.Col + tile.Index.Row) % 2 == 0) // Add only 50% of the tiles with the arbitrary rule. { cache.Add(tile.Index, new RasterFeature(new MRaster(Array.Empty <byte>(), new MRect(0, 0, 1, 1)))); } } } return(cache); }
private static ITileCache <Feature> PopulateMemoryCache(GlobalSphericalMercator schema, MemoryCache <Feature> cache, int levelId) { for (var i = levelId; i >= 0; i--) { var tiles = schema.GetTileInfos(schema.Extent, i.ToString(CultureInfo.InvariantCulture)); foreach (var tile in tiles) { if ((tile.Index.Col + tile.Index.Row) % 2 == 0) // Add only 50% of the tiles with the arbitrary rule. { cache.Add(tile.Index, new Feature()); } } } return(cache); }