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);

            // 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)
                {
                    var tiles = memoryCache.Find(tileInfo.Index);

                }
            }

            // Assert
            Assert.True(memoryCache.TileCount == 0);
        }
 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;
 }
Exemple #3
0
 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 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);
 }
Exemple #5
0
        public void TestGetNearestLevel()
        {
            // arrange
            var schema = new GlobalSphericalMercator();

            // act
            var levelId = Utilities.GetNearestLevel(schema.Resolutions, 300.0);
            // assert
            Assert.True(levelId == "9");
        }
 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;
 }
        public void TileFetcherShouldBehaveProperlyWithFailingTileRequests()
        {
            // Arrange
            var schema = new GlobalSphericalMercator();
            var tileSource = new TileSource(new FailingTileProvider(), schema);
            var memoryCache = new MemoryCache<Feature>();
            var tileFetcher = new TileFetcher(tileSource, memoryCache);

            // Act
            tileFetcher.ViewChanged(schema.Extent.ToBoundingBox(), schema.Resolutions["2"].UnitsPerPixel);
            while (tileFetcher.Busy) { }

            // Assert
            Assert.True(memoryCache.TileCount == 0);
        }
        public void GetFeaturesWithPartOfOptimalResolutionTilesMissing()
        {
            // arrange
            var schema = new GlobalSphericalMercator();
            var box = schema.Extent.ToBoundingBox();
            const int levelId = 3;
            var resolution = schema.Resolutions[levelId.ToString(CultureInfo.InvariantCulture)];
            var memoryCache = PopulateMemoryCache(schema, new MemoryCache<Feature>(), levelId);
            var renderGetStrategy = new RenderGetStrategy();

            // act
            var tiles = renderGetStrategy.GetFeatures(box, resolution.UnitsPerPixel, schema, memoryCache);

            // assert
            Assert.True(tiles.Count == 43);
        }
        public void InitializeAsBingSchema()
        {
            // arrange
            const string name = "BingMaps";
            const string format = "jpg";

            // act
            var schema = new GlobalSphericalMercator(format, true, 1, 19, name);
            
            // assert
            Assert.True(schema.Resolutions.Count == 19);
            Assert.True(schema.Resolutions.All(r => r.Value.Id != "0"));
            Assert.True(schema.Resolutions.Any(r => r.Value.Id == "1"));
            Assert.True(schema.Resolutions[3].Id == "3");
            Assert.True(schema.Name == name);
            Assert.True(schema.Format == format);
        }
Exemple #10
0
        public void GetTilesInViewWithBiggerExtentThanTileSchemaExtentReturnsCorrectNumberOfTiles()
        {
            // arrange
            var schema = new GlobalSphericalMercator();
            var requestExtent = GrowExtent(schema.Extent, schema.Extent.Width);

            var counter = 0;
            foreach (var resolution in schema.Resolutions.OrderByDescending(r => r.Value.UnitsPerPixel))
            {
                // act
                var tileInfos = schema.GetTileInfos(requestExtent, resolution.Value.Id).ToList();

                // assert
                Assert.True(tileInfos.Count == (int)Math.Round(Math.Pow(4,counter++)));
                if (counter >= 6) break;
            }
        }
Exemple #11
0
    private bool GetMap(string url, string version, string layer, int minLevel, int maxLevel, string imageType, out ITileSource tileSource)
    {
        if (string.IsNullOrEmpty(imageType))
        {
            tileSource = null;
            return(false);
        }

        var schema = new GlobalSphericalMercator(imageType, YAxis.OSM, minLevel, maxLevel);

        schema.Validate();
        var request = new WmscRequest(new Uri(url), schema,
                                      layers: new[] { layer }.ToList(),
                                      styles: new[] { "" }.ToList(),
                                      version: version);
        var provider = new HttpTileProvider(request);

        tileSource = new TileSource(provider, schema);
        return(tileSource != null);
    }
Exemple #12
0
        private bool GetMap(string url, string version, string layer, GeographicBounds bounds, string imageType, out ITileSource tileSource)
        {
            if (string.IsNullOrEmpty(imageType))
            {
                tileSource = null;
                return(false);
            }

            Extent extent = new Extent(bounds.MinimumCoordinates.Longitude, bounds.MinimumCoordinates.Latitude, bounds.MaximumCoordinates.Longitude, bounds.MaximumCoordinates.Latitude);
            var    schema = new GlobalSphericalMercator(imageType, YAxis.OSM, null, null, extent);

            schema.Validate();
            var request = new WmscRequest(new Uri(url), schema,
                                          layers: new[] { layer }.ToList(),
                                          styles: new[] { "" }.ToList(),
                                          version: version);
            var provider = new HttpTileProvider(request);

            tileSource = new TileSource(provider, schema);
            return(tileSource != null);
        }
        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.ViewChanged(true, box, resolution);
            waitHandle.WaitOne();
            Assert.AreEqual(layer.GetFeaturesInView(box, resolution).Count(), 1);
        }
        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");
        }
Exemple #15
0
 public GeodanWorldWmsTileSource()
 {
     var schema = new GlobalSphericalMercator(YAxis.TMS) {Srs = "EPSG:900913"};
     Provider = new HttpTileProvider(CreateWmsRequest(schema));
     Schema = schema;
 }
Exemple #16
0
        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);
        }
Exemple #17
0
 public GeodanWorldWmscTileSource()
 {
     Schema = new GlobalSphericalMercator(YAxis.TMS);
     Provider = GetTileProvider(Schema);
     Name = "Geodan WMS-C";
 }
Exemple #18
0
        public void TileToWorldShouldReturnCorrectExtent()
        {
            // arrange
            var range = new TileRange(1, 2);
            var schema = new GlobalSphericalMercator(YAxis.TMS);
            var expectedExtent = new Extent(-15028131.257989, -10018754.173189, -10018754.173189, -5009377.088389);
            const double toleratedDelta = 0.01;

            // act
            var extent = TileTransform.TileToWorld(range, "3", schema);

            // assert
            Assert.AreEqual(extent.MinX, expectedExtent.MinX, toleratedDelta);
            Assert.AreEqual(extent.MinY, expectedExtent.MinY, toleratedDelta);
            Assert.AreEqual(extent.MaxX, expectedExtent.MaxX, toleratedDelta);
            Assert.AreEqual(extent.MaxY, expectedExtent.MaxY, toleratedDelta);
        }