Example #1
0
 protected TileSource(TileSchema tileSchema, ITileCache <byte[]> tileCache, TileDownloader tileDownloader, string id)
     : base(id)
 {
     this.Schema         = tileSchema;
     this.tileCache      = tileCache ?? new MemoryTileCache <byte[]>();
     this.tileDownloader = this.tileDownloader ?? new ImageTileDownloader(tileSchema);
 }
Example #2
0
        public WebTileProvider(IRequest request, ITileCache <byte[]> fileCache,
                               string userAgent, string referer, bool keepAlive)
        {
            if (request == null)
            {
                throw new ArgumentException("RequestBuilder can not be null");
            }
            _request = request;

            if (fileCache == null)
            {
                throw new ArgumentException("FileCache can not be null");
            }
            _fileCache = fileCache;

            if (userAgent == null)
            {
                throw new ArgumentException("UserAgent can not be null");
            }
            _userAgent = userAgent;

            if (referer == null)
            {
                throw new ArgumentException("UserAgent can not be null");
            }
            _referer = referer;

            _keepAlive = keepAlive;
        }
Example #3
0
        public BingLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = new BingSchema();

            if (cache == null)
            {
                // Cache = new MemoryCache<byte[]>(1000, 100000);

                var localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

                var assembly = Assembly.GetEntryAssembly();
                if (assembly == null)
                {
                    cache = new MemoryCache <byte[]>(1000, 100000);
                }
                else
                {
                    var assemblyInfo       = AssemblyUtils.GetAssemblyInfo(assembly);
                    var cacheDirectoryPath = Path.Combine(Path.Combine(Path.Combine(localSettingsDirectoryPath, assemblyInfo.Company), assemblyInfo.Product), "cache_bing");
                    cache = new FileCache(cacheDirectoryPath, "jpg");
                }
            }
        }
Example #4
0
        private static void GetRecursive(IDictionary <TileIndex, IFeature> resultTiles, ITileSchema schema,
                                         ITileCache <Feature> cache, Extent extent, IList <KeyValuePair <string, Resolution> > resolutions, int resolutionIndex)
        {
            if (resolutionIndex < 0 || resolutionIndex >= resolutions.Count)
            {
                return;
            }

            var tiles = schema.GetTileInfos(extent, resolutions[resolutionIndex].Key);

            foreach (var tileInfo in tiles)
            {
                var feature = cache.Find(tileInfo.Index);

                if (feature == null)
                {
                    // only continue the recursive search if this tile is within the extent
                    if (tileInfo.Extent.Intersects(extent))
                    {
                        GetRecursive(resultTiles, schema, cache, tileInfo.Extent.Intersect(extent), resolutions, resolutionIndex - 1);
                    }
                }
                else
                {
                    resultTiles[tileInfo.Index] = feature;
                }
            }
        }
Example #5
0
 public TileFetchDispatcher(ITileCache <Feature> tileCache, IFetchStrategy fetchStrategy = null, Func <TileInfo, object, Feature> fetchToFeature = null, Func <TileInfo, object> fetchGetTile = null)
 {
     _tileCache      = tileCache;
     _fetchStrategy  = fetchStrategy ?? new MinimalFetchStrategy();
     _fetchToFeature = fetchToFeature ?? ToFeature;
     _fetchGetTile   = fetchGetTile;
 }
Example #6
0
 private static IList <TileInfo> GetTilesMissing(IEnumerable <TileInfo> tilesWanted,
                                                 ITileCache <Tile <T> > memoryCache, Retries retries)
 {
     return(tilesWanted.Where(
                info => memoryCache.Find(info.Index) == null &&
                !retries.ReachedMax(info.Index)).ToList());
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            // SetContentView(Resource.Layout.Main);

            AndroidGraphicFactory.CreateInstance(Application);

            this.mapView = new MapView(this);
            SetContentView(this.mapView);

            this.mapView.Clickable           = true;
            this.mapView.MapScaleBar.Visible = true;
            this.mapView.SetBuiltInZoomControls(true);
            this.mapView.SetZoomLevelMin(10);
            this.mapView.SetZoomLevelMax(20);
            this.tileCache = AndroidUtil.CreateTileCache(this, "mapcache", mapView.Model.DisplayModel.TileSize, 1f, this.mapView.Model.FrameBufferModel.OverdrawFactor);

            MapDataStore mapDataStore = new MapFile(new File(Android.OS.Environment.ExternalStorageDirectory, "chile.map"));

            this.tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore, this.mapView.Model.MapViewPosition, AndroidGraphicFactory.Instance);
            tileRendererLayer.SetXmlRenderTheme(InternalRenderTheme.Osmarender);

            this.mapView.LayerManager.Layers.Add(tileRendererLayer);

            mapView.SetCenter(new LatLong(-33.44, -70.68));
            // Get our button from the layout resource,
            // and attach an event to it
            //Button button = FindViewById<Button>(Resource.Id.MyButton);

            //button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
        }
Example #8
0
        private static void GetRecursive(IDictionary<TileIndex, IFeature> resultTiles, ITileSchema schema,
            ITileCache<Feature> cache, Extent extent, IList<KeyValuePair<string, Resolution>> resolutions, int resolutionIndex)
        {
            if (resolutionIndex < 0 || resolutionIndex >= resolutions.Count)
                return;

            var tiles = schema.GetTileInfos(extent, resolutions[resolutionIndex].Key);

            foreach (var tileInfo in tiles)
            {
                var feature = cache.Find(tileInfo.Index);

                if (feature == null)
                {
                    // only continue the recursive search if this tile is within the extent
                    if (tileInfo.Extent.Intersects(extent))
                    {
                        GetRecursive(resultTiles, schema, cache, tileInfo.Extent.Intersect(extent), resolutions, resolutionIndex - 1);
                    }
                }
                else
                {
                    resultTiles[tileInfo.Index] = feature;
                }
            }
        }
Example #9
0
        /// <summary>
        /// Creates an instance of <see cref="AsyncTileFetcher"/>.
        /// </summary>
        /// <param name="provider">The tile provider.</param>
        /// <param name="minTiles">Minimum number of tiles in memory cache.</param>
        /// <param name="maxTiles">Maximum number of tiles in memory cache.</param>
        /// <param name="permaCache">Optional: the persistent cache. When null, no tiles
        /// will be cached outside of the volatile memory cache.</param>
        /// <exception cref="ArgumentNullException">Throw when <paramref name="provider"/>
        /// is <c>null</c>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when either <paramref name="minTiles"/>
        /// or <paramref name="maxTiles"/> is negative.</exception>
        /// <exception cref="ArgumentException">Thrown when <paramref name="minTiles"/>
        /// is not smaller than <paramref name="maxTiles"/>.</exception>
        public AsyncTileFetcher(ITileProvider provider, int minTiles, int maxTiles, ITileCache <byte[]> permaCache = null)
        {
            if (provider == null)
            {
                throw new ArgumentNullException(nameof(provider));
            }

            if (minTiles < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(minTiles), Resources.AsyncTileFetcher_Number_of_tiles_for_memory_cache_cannot_be_negative);
            }

            if (maxTiles < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(maxTiles), Resources.AsyncTileFetcher_Number_of_tiles_for_memory_cache_cannot_be_negative);
            }

            if (minTiles >= maxTiles)
            {
                throw new ArgumentException(Resources.AsyncTileFetcher_Minimum_number_of_tiles_in_memory_cache_must_be_less_than_maximum);
            }

            this.provider   = provider;
            volatileCache   = new MemoryCache <byte[]>(minTiles, maxTiles);
            persistentCache = permaCache ?? NoopTileCache.Instance;
            threadPool      = new SmartThreadPool(10000, BruTileSettings.MaximumNumberOfThreads);
        }
        private static void GetRecursive(IDictionary <TileIndex, IFeature> resultTiles, ITileSchema schema,
                                         ITileCache <Feature> cache, Extent extent, IList <KeyValuePair <int, Resolution> > resolutions, int resolutionIndex)
        {
            if (resolutionIndex < 0 || resolutionIndex >= resolutions.Count)
            {
                return;
            }

            var tiles = schema.GetTileInfos(extent, resolutions[resolutionIndex].Key);

            foreach (var tileInfo in tiles)
            {
                var feature = cache.Find(tileInfo.Index);

                // Geometry can be null for some tile sources to indicate the tile is not present.
                // It is stored in the tile cache to prevent retries. It should not be returned to the
                // renderer.
                if (feature?.Geometry == null)
                {
                    // only continue the recursive search if this tile is within the extent
                    if (tileInfo.Extent.Intersects(extent))
                    {
                        GetRecursive(resultTiles, schema, cache, tileInfo.Extent.Intersect(extent), resolutions, resolutionIndex - 1);
                    }
                }
                else
                {
                    resultTiles[tileInfo.Index] = feature;
                }
            }
        }
Example #11
0
        public BingLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined 
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = new BingSchema();

            if (cache == null)
            {
                // Cache = new MemoryCache<byte[]>(1000, 100000);

                var localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                
                var assembly = Assembly.GetEntryAssembly();
                if (assembly == null)
                {
                    cache = new MemoryCache<byte[]>(1000, 100000);
                }
                else
                {
                    var assemblyInfo = AssemblyUtils.GetAssemblyInfo(assembly);
                    var cacheDirectoryPath = Path.Combine(Path.Combine(Path.Combine(localSettingsDirectoryPath, assemblyInfo.Company), assemblyInfo.Product), "cache_bing");
                    cache = new FileCache(cacheDirectoryPath, "jpg");
                }
            }
        }
Example #12
0
        protected BaseTileLoader(ITileCache tileCache)
        {
            _tileCache       = tileCache;
            MaxParallelTasks = 5;
#if DEBUG
            MaxParallelTasks = 1;
#endif
        }
Example #13
0
 public IList<IFeature> GetFeatures(BoundingBox box, double resolution, ITileSchema schema, ITileCache<Feature> memoryCache)
 {
     var dictionary = new Dictionary<TileIndex, IFeature>();
     var levelId = BruTile.Utilities.GetNearestLevel(schema.Resolutions, resolution);
     GetRecursive(dictionary, schema, memoryCache, box.ToExtent(), levelId);
     var sortedFeatures = dictionary.OrderByDescending(t => schema.Resolutions[t.Key.Level].UnitsPerPixel);
     return sortedFeatures.ToDictionary(pair => pair.Key, pair => pair.Value).Values.ToList();
 }
Example #14
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="provider">The tile provider</param>
 /// <param name="minTiles">min. number of tiles in memory cache</param>
 /// <param name="maxTiles">max. number of tiles in memory cache</param>
 /// <param name="permaCache">The perma cache</param>
 /// <param name="maxNumberOfThreads">The maximum number of threads used to get the tiles</param>
 internal TileFetcher(ITileProvider provider, int minTiles, int maxTiles, ITileCache <byte[]> permaCache,
                      int maxNumberOfThreads)
 {
     _provider      = provider;
     _volatileCache = new MemoryCache <byte[]>(minTiles, maxTiles);
     _permaCache    = permaCache ?? NoopCache.Instance;
     _threadPool    = new SmartThreadPool(10000, maxNumberOfThreads);
     AsyncMode      = BruTileLayerPlugin.Settings.UseAsyncMode;
 }
Example #15
0
//		private readonly Texture2D _thumb;

        public CachedOnlineTileMapProvider(IOnlineMapUrlProvider urlProvider, ITileCache cache = null) : base(
                urlProvider)
        {
            _cache = cache ?? new DummyTileCache();

//			_thumb = new Texture2D(TileSize, TileSize);
//			_thumb.SetPixels(Enumerable.Repeat(Color.clear, TileSize * TileSize).ToArray());
//			_thumb.Apply(true);
        }
Example #16
0
 public TileFetchDispatcher(
     ITileCache <Feature> tileCache,
     ITileSchema tileSchema,
     Func <TileInfo, Feature> fetchTileAsFeature,
     IFetchStrategy fetchStrategy = null)
 {
     _tileCache          = tileCache;
     _tileSchema         = tileSchema;
     _fetchTileAsFeature = fetchTileAsFeature;
     _fetchStrategy      = fetchStrategy ?? new MinimalFetchStrategy();
     _fetchMachine       = new FetchMachine(this);
 }
Example #17
0
        public SharpMapTileSource(ITileSchema schema, ITileCache <byte[]> cache, params ILayer[] layers)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (layers == null)
            {
                throw new ArgumentNullException("layers");
            }

            this.provider = new SharpMapTileProvider(schema, cache, layers);
        }
Example #18
0
        public static IEnumerable <Tile <T> > SelectTilesToRender(ITileCache <Tile <T> > cache, ITileSchema schema, Extent extent, double resolution)
        {
            var selection = new Dictionary <TileIndex, Tile <T> >();

            if (schema == null)
            {
                return(selection.Values);
            }

            SelectRecursive(selection, cache, schema, extent, BruTile.Utilities.GetNearestLevel(schema.Resolutions, resolution));

            return(SortOnLevel(selection, schema).Values);
        }
Example #19
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="tileSource">The tile source to use</param>
 /// <param name="tileCache">The tile cache to use</param>
 public BruTileLayer(ITileSource tileSource, ITileCache<byte[]> tileCache)
 {
     TileSource = tileSource;
     TileCache = tileCache;
     int epsgCode;
     if (int.TryParse(TileSource.Schema.Srs.Substring(5), out epsgCode))
     {
         _projection = new ProjectionInfo();
         _projection = ProjectionInfo.FromEpsgCode(epsgCode);
     }
     else
         _projection = KnownCoordinateSystems.Projected.World.WebMercator;
     LegendItemVisible = true;
 }
Example #20
0
        private void GetTileOnThread(object parameter)
        {
            object[] parameters = (object[])parameter;
            if (parameters.Length != 4)
            {
                throw new ArgumentException("Four parameters expected");
            }
            ITileProvider       tileProvider   = (ITileProvider)parameters[0];
            TileInfo            tileInfo       = (TileInfo)parameters[1];
            ITileCache <byte[]> bitmaps        = (ITileCache <byte[]>)parameters[2];
            AutoResetEvent      autoResetEvent = (AutoResetEvent)parameters[3];

            try
            {
                byte[] bytes  = tileProvider.GetTile(tileInfo);
                Bitmap bitmap = new Bitmap(new MemoryStream(bytes));
                bitmaps.Add(tileInfo.Index, bytes);
            }
            catch (WebException ex)
            {
                if (ShowErrorInTile)
                {
                    //an issue with this method is that one an error tile is in the memory cache it will stay even
                    //if the error is resolved. PDD.
                    var      width    = TileSource.Schema.GetTileWidth(tileInfo.Index.Level);
                    var      height   = TileSource.Schema.GetTileHeight(tileInfo.Index.Level);
                    Bitmap   bitmap   = new Bitmap(width, height);
                    Graphics graphics = Graphics.FromImage(bitmap);
                    graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.Black),
                                        new RectangleF(0, 0, width, height));
                    graphics.Dispose();

                    using (MemoryStream m = new MemoryStream())
                    {
                        bitmap.Save(m, ImageFormat.Png);
                        bitmaps.Add(tileInfo.Index, m.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                StackFrame CallStack = new StackFrame(1, true);
                Trace.WriteLine("Error: " + ex.Message + ", File: " + CallStack.GetFileName() + ", Line: " + CallStack.GetFileLineNumber());
            }
            finally
            {
                autoResetEvent.Set();
            }
        }
        public IList<IFeature> GetFeatures(BoundingBox box, double resolution, ITileSchema schema, ITileCache<Feature> memoryCache)
        {
            var tiles = schema.GetTileInfos(box.ToExtent(), resolution);
            var result = new List<IFeature>();
            foreach (var tileInfo in tiles)
            {
                var feature = memoryCache.Find(tileInfo.Index);

                if (feature != null)
                {
                    result.Add(feature);
                }
            }
            return result;
        }
Example #22
0
 public BingLayer()
 {
     if (cache == null)
     {
         //no cache so mem
         if (CacheLocation == null)
         {
             cache = new MemoryCache <byte[]>(1000, 100000);
         }
         else
         {
             cache = new FileCache(CacheLocation, "png");
         }
     }
 }
Example #23
0
        void IDisposable.Dispose()
        {
            if (_volatileCache == null)
            {
                return;
            }

            _volatileCache.Clear();
            _volatileCache = null;
            _provider      = null;
            _permaCache    = null;

            _threadPool.Dispose();
            _threadPool = null;
        }
Example #24
0
 public static void GetRecursive(IDictionary<TileIndex, IFeature> resultTiles, ITileSchema schema,
     ITileCache<Feature> cache, Extent extent, string levelId)
 {
     // to improve performance, convert the resolutions to a list so they can be walked up by
     // simply decrementing an index when the level index needs to change
     var resolutions = schema.Resolutions.OrderByDescending(pair => pair.Value.UnitsPerPixel).ToList();
     for (int i = 0; i < resolutions.Count; i++)
     {
         if (levelId == resolutions[i].Key)
         {
             GetRecursive(resultTiles, schema, cache, extent, resolutions, i);
             break;
         }
     }
 }
 public OpenStreetMapLayer()
 {
     if (cache == null)
     {
         if (CacheLocation == null)
         {
             cache = new MemoryCache <byte[]>(1000, 100000);
         }
         else
         {
             var cacheDirectoryPath = CacheLocation;
             cache = new FileCache(cacheDirectoryPath, "png");
         }
     }
 }
Example #26
0
        public static IEnumerable <Tile <T> > SelectTilesToRender(ITileCache <Tile <T> > cache, ITileSchema schema, Extent extent, double unitsPerPixel)
        {
            var selection = new Dictionary <TileIndex, Tile <T> >();

            if (schema == null)
            {
                return(selection.Values);
            }

            var levelId = Utilities.GetNearestLevel(schema.Resolutions, unitsPerPixel);

            SelectRecursive(selection, cache, schema, extent, levelId);

            return(SortOnLevel(selection).Values);
        }
Example #27
0
        public void Render(Viewport viewport, ITileSource tileSource, ITileCache<Tile<Image>> tileCache)
        {
            _canvas.Children.Clear();

            var level = Utilities.GetNearestLevel(tileSource.Schema.Resolutions, viewport.UnitsPerPixel);
            var tileInfos = tileSource.Schema.GetTileInfos(viewport.Extent, level);
            foreach (var tileInfo in tileInfos)
            {
                var tile = tileCache.Find(tileInfo.Index);
                if (tile != null)
                {
                    _canvas.Children.Add(tile.Image);
                    PositionImage(tile.Image, tileInfo.Extent, viewport);
                }
            }
        }
Example #28
0
        public BackgroundLayer(ITileSource tileSource, ITileCache <byte[]> tileCache)
        {
            TileSource = tileSource;
            TileCache  = tileCache ?? new MemoryCache <byte[]>(200, 300);
            if (int.TryParse(TileSource.Schema.Srs.Substring(5), out int epsgCode))
            {
                _projection = new ProjectionInfo();
                _projection = ProjectionInfo.FromEpsgCode(epsgCode);
            }
            else
            {
                _projection = KnownCoordinateSystems.Projected.World.WebMercator;
            }

            LegendItemVisible = true;
        }
Example #29
0
        public static void GetRecursive(IDictionary <TileIndex, IFeature> resultTiles, ITileSchema schema,
                                        ITileCache <Feature> cache, Extent extent, string levelId)
        {
            // to improve performance, convert the resolutions to a list so they can be walked up by
            // simply decrementing an index when the level index needs to change
            var resolutions = schema.Resolutions.OrderByDescending(pair => pair.Value.UnitsPerPixel).ToList();

            for (int i = 0; i < resolutions.Count; i++)
            {
                if (levelId == resolutions[i].Key)
                {
                    GetRecursive(resultTiles, schema, cache, extent, resolutions, i);
                    break;
                }
            }
        }
Example #30
0
        public Fetcher(ITileSource tileSource, ITileCache <Tile <T> > memoryCache)
        {
            if (tileSource == null)
            {
                throw new ArgumentException("TileProvider can not be null");
            }
            _tileSource = tileSource;

            if (memoryCache == null)
            {
                throw new ArgumentException("MemoryCache can not be null");
            }
            _memoryCache = memoryCache;

            StartFetchLoop();
        }
Example #31
0
        private void GetTileOnThread(object parameter)
        {
            object[] parameters = (object[])parameter;
            if (parameters.Length != 4)
            {
                throw new ArgumentException("Four parameters expected");
            }
            ITileProvider       tileProvider   = (ITileProvider)parameters[0];
            TileInfo            tileInfo       = (TileInfo)parameters[1];
            ITileCache <byte[]> bitmaps        = (ITileCache <byte[]>)parameters[2];
            AutoResetEvent      autoResetEvent = (AutoResetEvent)parameters[3];

            try
            {
                byte[] bytes = tileProvider.GetTile(tileInfo);
                //Bitmap bitmap = new Bitmap(new MemoryStream(bytes));
                bitmaps.Add(tileInfo.Index, bytes);
            }
            catch (WebException ex)
            {
                if (ShowErrorInTile)
                {
                    //an issue with this method is that one an error tile is in the memory cache it will stay even
                    //if the error is resolved. PDD.
                    Bitmap   bitmap   = new Bitmap(TileSource.Schema.Width, TileSource.Schema.Height);
                    Graphics graphics = Graphics.FromImage(bitmap);
                    graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.Black),
                                        new RectangleF(0, 0, TileSource.Schema.Width, TileSource.Schema.Height));
                    graphics.Dispose();

                    using (MemoryStream m = new MemoryStream())
                    {
                        bitmap.Save(m, ImageFormat.Png);
                        bitmaps.Add(tileInfo.Index, m.ToArray());
                    }
                }
            }
            catch (Exception ex)
            {
                //todo: log and use other ways to report to user.
            }
            finally
            {
                autoResetEvent.Set();
            }
        }
Example #32
0
        public void Render(Viewport viewport, ITileSource tileSource, ITileCache <Tile <Image> > tileCache)
        {
            _canvas.Children.Clear();

            var level     = Utilities.GetNearestLevel(tileSource.Schema.Resolutions, viewport.UnitsPerPixel);
            var tileInfos = tileSource.Schema.GetTileInfos(viewport.Extent, level);

            foreach (var tileInfo in tileInfos)
            {
                var tile = tileCache.Find(tileInfo.Index);
                if (tile != null)
                {
                    _canvas.Children.Add(tile.Image);
                    PositionImage(tile.Image, tileInfo.Extent, viewport);
                }
            }
        }
Example #33
0
        public BingLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined 
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = new BingSchema();

            if (cache == null)
            {
                //no cache so mem
                if (CacheLocation == null)
                {
                    cache = new MemoryCache<byte[]>(1000, 100000);
                }
                else
                {
                    cache = new FileCache(CacheLocation, "jpg");
                }
            }
        }
Example #34
0
        public BingLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = new BingSchema();

            if (cache == null)
            {
                //no cache so mem
                if (CacheLocation == null)
                {
                    cache = new MemoryCache <byte[]>(1000, 100000);
                }
                else
                {
                    cache = new FileCache(CacheLocation, "jpg");
                }
            }
        }
Example #35
0
        public OpenStreetMapLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = CreateTileSchema();

            if (cache == null)
            {
                if (CacheLocation == null)
                {
                    cache = new MemoryCache <byte[]>(1000, 100000);
                }
                else
                {
                    var cacheDirectoryPath = CacheLocation;
                    cache = new FileCache(cacheDirectoryPath, "png");
                }
            }
        }
Example #36
0
        protected virtual void Dispose(bool disposing)
        {
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                volatileCache.Clear();

                threadPool.Dispose();
                threadPool = null;

                volatileCache   = null;
                provider        = null;
                persistentCache = null;
            }

            IsDisposed = true;
        }
Example #37
0
        public SharpMapTileProvider(ITileSchema schema, ITileCache <byte[]> cache, params ILayer[] layers)
        {
            if (schema == null)
            {
                throw new ArgumentNullException("schema");
            }
            if (layers == null)
            {
                throw new ArgumentNullException("layers");
            }

            this.Schema = schema;
            this.cache  = cache ?? new NullCache();

            LayerCollection collection = new LayerCollection();

            foreach (ILayer layer in layers)
            {
                collection.Add(layer);
            }
            this.layers = collection;
        }
Example #38
0
        public OpenStreetMapLayer()
        {
            // Here we use a tile schema that is defined in code. There are a few predefined 
            // tile schemas in the BruTile.dll. In the usual case the schema should be parsed
            // from a tile service description.
            schema = CreateTileSchema();

            if (cache == null)
            {
                if (CacheLocation == null)
                {
                    cache = new MemoryCache<byte[]>(1000, 100000);
                }
                else
                {
                    var cacheDirectoryPath = CacheLocation;
                    cache = new FileCache(cacheDirectoryPath, "png");
                }
            }
        }
Example #39
0
        public IList <IFeature> GetFeatures(BoundingBox box, double resolution, ITileSchema schema, ITileCache <Feature> memoryCache)
        {
            var dictionary = new Dictionary <TileIndex, IFeature>();
            var levelId    = BruTile.Utilities.GetNearestLevel(schema.Resolutions, resolution);

            GetRecursive(dictionary, schema, memoryCache, box.ToExtent(), levelId);
            var sortedFeatures = dictionary.OrderByDescending(t => schema.Resolutions[t.Key.Level].UnitsPerPixel);

            return(sortedFeatures.ToDictionary(pair => pair.Key, pair => pair.Value).Values.ToList());
        }
 public BrutileServiceProvider(string name, ITileSource tileSource, ITileCache<byte[]> tileCache) : base(name)
 {
     TileCache = tileCache;
     TileSource = tileSource;
 }
Example #41
0
        private bool InitializeBrutileProvider()
        {
            if (this.TileServerName.Equals(Properties.Resources.BingHybrid, StringComparison.InvariantCultureIgnoreCase))
            {
                string token = String.Empty;
                string url = string.IsNullOrWhiteSpace(token)
                ? BingRequest.UrlBingStaging
                : BingRequest.UrlBing;

                TileSource = new BingTileSource(new BingRequest(url, string.Empty, BingMapType.Hybrid));
                TileCache = new MemoryCache<byte[]>(100, 200);

                return true;
            }

            if (this.TileServerName.Equals(Properties.Resources.GoogleSatellite, StringComparison.InvariantCultureIgnoreCase))
            {
                TileSource = new GoogleTileSource(GoogleMapType.GoogleSatellite);
                TileCache = new MemoryCache<byte[]>(100, 200);

                return true;
            }

            if (this.TileServerName.Equals(Properties.Resources.GoogleMap, StringComparison.InvariantCultureIgnoreCase))
            {
                TileSource = new GoogleTileSource(GoogleMapType.GoogleMap);
                TileCache = new MemoryCache<byte[]>(100, 200);

                return true;
            }

            if (this.TileServerName.Equals(Properties.Resources.YahooMap, StringComparison.InvariantCultureIgnoreCase))
            {
                /*
                TileSource = new YahooTileSource(YahooMapType.YahooMap);
                TileCache = new MemoryCache<byte[]>(100, 200);                
                return true;
                 */ 
            }

            if (this.TileServerName.Equals(Properties.Resources.YahooSatellite, StringComparison.InvariantCultureIgnoreCase))
            {
                /*
                TileSource = new YahooTileSource(YahooMapType.YahooSatellite);
                TileCache = new MemoryCache<byte[]>(100, 200);                
                return true;
                 */ 
            }

            if (this.TileServerName.Equals(Properties.Resources.WMSMap, StringComparison.InvariantCultureIgnoreCase))
            {
                TileSource = WmsTileSource.Create(WmsServerInfo);
                TileCache = new MemoryCache<byte[]>(100, 200);

                return true;
            }

            TileSource = null;
            TileCache = null;

            return false;
        }