public WmscLayerConfiguration(string fileCacheRoot, string name, WmscTileSource source) : base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot) { _fileCacheRoot = fileCacheRoot; LegendText = name; var provider = ReflectionHelper.Reflect(source) as HttpTileProvider; if (provider == null) { throw new ArgumentException("Source does not have a WebTileProvider", "source"); } var request = ReflectionHelper.ReflectRequest <WmscRequest>(provider); if (request == null) { throw new ArgumentException("Source does not have a WmscRequest", "source"); } SafeRequest(request); SafeSchema(source.Schema); TileSource = source; TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); _initialized = true; }
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); }
protected void SetTileSource(ITileSource source) { tileSource = source; tileFetcher = new TileFetcher(source, memoryCache, maxRetries); tileFetcher.DataChanged += TileFetcherDataChanged; OnPropertyChanged("Envelope"); }
/// <summary> /// Method called prior to any tile access /// </summary> public void Initialize() { _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(TileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
public void Initialize() { if (_initialized) { return; } _initialized = true; var tileSources = GetTileSources(_capabilitiesUri); var tileSource = tileSources.FirstOrDefault(ts => ts.Name.Equals(LegendText, StringComparison.InvariantCulture)); if (tileSource == null) { throw new ArgumentException("TileSource not found", "capabilitiesUri"); } TileSource = tileSource; var provider = ((HttpTileProvider)ReflectionHelper.Reflect(tileSource)); TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
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"); }
/// <summary> /// Method called prior to any tile access /// </summary> public void Initialize() { _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(TileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
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"); }
[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 VectorTileLayer(ITileSource tileSource, RenderGetStrategy renderStrategy = null) { _tileSource = tileSource; _tileFetcher = new TileFetcher(_tileSource, _tileCache, 1, 4, _fetchStrategy); _tileFetcher.DataChanged += TileFetcherOnDataChanged; _tileFetcher.PropertyChanged += TileFetcherOnPropertyChanged; _renderStrategy = renderStrategy ?? new RenderGetStrategy(); }
private void AbortFetcher() { if (_tileFetcher == null) { return; } var tileFetcher = _tileFetcher; _tileFetcher = null; tileFetcher.AbortFetch(); tileFetcher.DataChanged -= TileFetcherDataChanged; tileFetcher.PropertyChanged -= TileFetcherOnPropertyChanged; }
public MbTilesConfiguration(string mbtilesFile) { _mbTilesFile = mbtilesFile; LegendText = Path.GetFileNameWithoutExtension(_mbTilesFile); #if DEBUG SQLiteLog.Enabled = true; #endif var uri = new Uri(_mbTilesFile); var tileSource = new MbTilesTileSource(uri.LocalPath); TileSource = tileSource; TileFetcher = new TileFetcher(tileSource.Provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, new TileFetcher.NoopCache()); }
public MbTilesConfiguration(string mbtilesFile) { _mbTilesFile = mbtilesFile; LegendText = Path.GetFileNameWithoutExtension(_mbTilesFile); #if DEBUG SQLiteLog.Enabled = true; #endif var uri = new Uri(_mbTilesFile); var tileSource = new MbTilesTileSource(uri.LocalPath); TileSource = tileSource; TileFetcher = new TileFetcher(tileSource.Provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, new TileFetcher.NoopCache()); }
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); }
/// <summary> /// Sets the tile source. /// </summary> /// <param name="source"></param> protected void SetTileSource(ITileSource source) { if (_tileFetcher != null) { _tileFetcher.AbortFetch(); _tileFetcher.DataChanged -= TileFetcherDataChanged; _tileFetcher.PropertyChanged -= TileFetcherOnPropertyChanged; _tileFetcher = null; _bitmaps.Clear(); } _source = source; if (source == null) { return; } _tileFetcher = new TileFetcher(source, _bitmaps, _maxRetries, _maxThreads, _fetchStrategy, _fileCache); _tileFetcher.DataChanged += TileFetcherDataChanged; _tileFetcher.PropertyChanged += TileFetcherOnPropertyChanged; }
public WmtsLayerConfiguration(string fileCacheRoot, string name, ITileSource tileSource) :base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot) { _fileCacheRoot = fileCacheRoot; LegendText = name; //var tileSources = GetTileSources(capabilitiesUri); //var tileSource = tileSources.FirstOrDefault(ts => ts.Title.Equals(name, StringComparison.InvariantCulture)); if (tileSource == null) throw new ArgumentException("TileSource not found", "capabilitiesUri"); TileSource = tileSource; TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(tileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); _initialized = true; }
/// <summary> /// Method called prior to any tile access /// </summary> public void Initialize() { if (_initialized) { return; } _initialized = true; var schema = RestoreSchema(); var request = new WmscRequest(new Uri(_url), schema, _layers, _styles, _customParameters, _version); ITileProvider provider = new HttpTileProvider(request); TileSource = (WmscTileSource)Activator.CreateInstance(typeof(WmscTileSource), BindingFlags.NonPublic, schema, provider); TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
protected virtual void Dispose(bool disposing) { if (IsDisposed) { return; } if (disposing) { TileFetcher?.Dispose(); } if (fileCache != null) { FileCacheManager.Instance.UnsubscribeFileCache(fileCache); fileCache = null; } IsDisposed = true; }
public KnownTileLayerConfiguration(string fileCacheRoot, KnownTileSource tileSource, string apiKey) : base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot ?? Path.Combine(BruTileLayerPlugin.Settings.PermaCacheRoot , tileSource.ToString())) { _knownTileSource = tileSource; _apiKey = apiKey; /* if (tileServers == KnownTileServers.Custom) throw new NotSupportedException(); */ TileSource = KnownTileSources.Create(tileSource, apiKey); TileCache = CreateTileCache(); LegendText = tileSource.ToString(); _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(TileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
public KnownTileLayerConfiguration(string fileCacheRoot, KnownTileSource tileSource, string apiKey) : base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot ?? Path.Combine(BruTileLayerPlugin.Settings.PermaCacheRoot, tileSource.ToString())) { _knownTileSource = tileSource; _apiKey = apiKey; /* * if (tileServers == KnownTileServers.Custom) * throw new NotSupportedException(); */ TileSource = KnownTileSources.Create(tileSource, apiKey); TileCache = CreateTileCache(); LegendText = tileSource.ToString(); _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(TileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
public WmtsLayerConfiguration(string fileCacheRoot, string name, ITileSource tileSource) : base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot) { _fileCacheRoot = fileCacheRoot; LegendText = name; //var tileSources = GetTileSources(capabilitiesUri); //var tileSource = tileSources.FirstOrDefault(ts => ts.Title.Equals(name, StringComparison.InvariantCulture)); if (tileSource == null) { throw new ArgumentException("TileSource not found", "capabilitiesUri"); } TileSource = tileSource; TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(ReflectionHelper.Reflect(tileSource), BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); _initialized = true; }
protected void SetTileSource(ITileSource source) { if (_tileSource != null) { _tileFetcher.AbortFetch(); _tileFetcher.DataChanged -= TileFetcherDataChanged; _tileFetcher.PropertyChanged -= TileFetcherOnPropertyChanged; _tileFetcher = null; _memoryCache.Clear(); } _tileSource = source; if (source == null) { return; } _tileFetcher = new TileFetcher(source, _memoryCache, _maxRetries, _maxThreads, _fetchStrategy); _tileFetcher.DataChanged += TileFetcherDataChanged; _tileFetcher.PropertyChanged += TileFetcherOnPropertyChanged; OnPropertyChanged("Envelope"); }
public void TileFetcherWithFailingFetchesTest() { // Arrange var tileProvider = new SometimesFailingTileProvider(); var tileSchema = new GlobalSphericalMercator(); var tileSource = new TileSource(tileProvider, tileSchema); var tileFetcher = new TileFetcher(tileSource, new MemoryCache<Feature>(), 2, 8); // Act for (int i = 0; i < 100; i++) { for (int j = 0; j < 4; j++) { tileFetcher.ViewChanged(tileSchema.Extent.ToBoundingBox(), tileSchema.Resolutions[j.ToString()].UnitsPerPixel); } } // Assert while (tileFetcher.Busy) { } Assert.Pass("The fetcher did not go into an infinite loop"); }
protected void SetTileSource(ITileSource source) { if (_tileSource != null) { // Is causing thread leak _tileFetcher.AbortFetch(); _tileFetcher.DataChanged -= TileFetcherDataChanged; _tileFetcher.PropertyChanged -= TileFetcherOnPropertyChanged; _tileFetcher = null; _memoryCache.Clear(); } _tileSource = source; if (_tileSource != null) { Attribution.Text = _tileSource.Attribution.Text; Attribution.Url = _tileSource.Attribution.Url; _tileFetcher = new TileFetcher(source, _memoryCache, _maxRetries, _maxThreads, _fetchStrategy); _tileFetcher.DataChanged += TileFetcherDataChanged; _tileFetcher.PropertyChanged += TileFetcherOnPropertyChanged; OnPropertyChanged(nameof(Envelope)); } }
private void CreateFetcher(ITileSource source) { _tileFetcher = new TileFetcher(source, _memoryCache, _maxRetries, _maxThreads, _fetchStrategy); _tileFetcher.DataChanged += TileFetcherDataChanged; _tileFetcher.PropertyChanged += TileFetcherOnPropertyChanged; }
public TileLayer(TileSource source, ITileFactory <T> tileFactory) { this.schema = source.Schema; tileFetcher = new TileFetcher <T>(source, memoryCache, tileFactory); tileFetcher.DataChanged += new DataChangedEventHandler(tileFetcher_DataChanged); }
/// <summary> /// Creates an instanc of this class using the given <paramref name="configuration"/> /// </summary> /// <param name="configuration">The configuration</param> public BruTileLayer(IConfiguration configuration) { if (configuration == null) throw new ArgumentNullException("configuration"); var data = base.ContextMenuItems.Find(m => m.Name == "Data"); if (data != null) base.ContextMenuItems.Remove(data); /* data = base.ContextMenuItems.Find(m => m.Name.StartsWith("Attrib")); if (data != null) base.ContextMenuItems.Remove(data); */ // Initialize the configuration prior to usage configuration.Initialize(); // _configuration = configuration; var tileSource = configuration.TileSource; _projectionInfo = AuthorityCodeHandler.Instance[tileSource.Schema.Srs]; if (_projectionInfo == null) _projectionInfo = AuthorityCodeHandler.Instance["EPSG:3857"]; // WebMercator: set datum to WGS1984 for better accuracy if (tileSource.Schema.Srs == "EPSG:3857") _projectionInfo.GeographicInfo.Datum = KnownCoordinateSystems.Geographic.World.WGS1984.GeographicInfo.Datum; Projection = _projection; var extent = tileSource.Schema.Extent; MyExtent = new Extent(extent.MinX, extent.MinY, extent.MaxX, extent.MaxY); base.LegendText = configuration.LegendText; base.LegendItemVisible = true; base.IsVisible = base.Checked = true; base.LegendSymbolMode = SymbolMode.Symbol; LegendType = LegendType.Custom; _tileFetcher = configuration.TileFetcher; _tileFetcher.TileReceived += HandleTileReceived; _tileFetcher.QueueEmpty += HandleQueueEmpty; //Set the wrap mode _imageAttributes = new ImageAttributes(); _imageAttributes.SetWrapMode(WrapMode.TileFlipXY); }
public WmscLayerConfiguration(string fileCacheRoot, string name, WmscTileSource source) : base(BruTileLayerPlugin.Settings.PermaCacheType, fileCacheRoot) { _fileCacheRoot = fileCacheRoot; LegendText = name; var provider = ReflectionHelper.Reflect(source) as HttpTileProvider; if (provider == null) throw new ArgumentException("Source does not have a WebTileProvider", "source"); var request = ReflectionHelper.ReflectRequest<WmscRequest>(provider); if (request == null) throw new ArgumentException("Source does not have a WmscRequest" ,"source"); SafeRequest(request); SafeSchema(source.Schema); TileSource = source; TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); _initialized = true; }
/// <summary> /// Method called prior to any tile access /// </summary> public void Initialize() { if (_initialized) return; _initialized = true; var schema = RestoreSchema(); var request = new WmscRequest(new Uri(_url), schema, _layers, _styles, _customParameters, _version); ITileProvider provider = new HttpTileProvider(request); TileSource = (WmscTileSource)Activator.CreateInstance(typeof(WmscTileSource), BindingFlags.NonPublic, schema, provider); TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }
public void Initialize() { if (_initialized) return; _initialized = true; var tileSources = GetTileSources(_capabilitiesUri); var tileSource = tileSources.FirstOrDefault(ts => ts.Name.Equals(LegendText, StringComparison.InvariantCulture)); if (tileSource == null) throw new ArgumentException("TileSource not found", "capabilitiesUri"); TileSource = tileSource; var provider = ((HttpTileProvider)ReflectionHelper.Reflect(tileSource)); TileCache = CreateTileCache(); _tileFetcher = new TileFetcher(provider, BruTileLayerPlugin.Settings.MemoryCacheMinimum, BruTileLayerPlugin.Settings.MemoryCacheMaximum, TileCache); }