internal void BeginGetTiles(TileLayer tileLayer, IEnumerable<Tile> tiles)
        {
            var imageTileSource = tileLayer.TileSource as ImageTileSource;

            foreach (var tile in tiles)
            {
                try
                {
                    ImageSource image = null;

                    if (imageTileSource != null)
                    {
                        image = imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel, tile.Rotation);
                    }
                    else
                    {
                        var uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel, tile.Rotation);

                        if (uri != null)
                        {
                            image = new BitmapImage(uri);
                        }
                    }

                    tile.SetImageSource(image, tileLayer.AnimateTileOpacity);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading tile image failed: {0}", ex.Message);
                }
            }
        }
        public void BeginLoadTiles(TileLayer tileLayer, IEnumerable<Tile> tiles)
        {
            if (tiles.Any())
            {
                // get current TileLayer property values in UI thread
                var dispatcher = tileLayer.Dispatcher;
                var tileSource = tileLayer.TileSource;
                var imageTileSource = tileSource as ImageTileSource;

                if (imageTileSource != null && !imageTileSource.IsAsync) // call LoadImage in UI thread with low priority
                {
                    foreach (var tile in tiles)
                    {
                        dispatcher.BeginInvoke(new Action<Tile>(t => t.SetImage(LoadImage(imageTileSource, t))), DispatcherPriority.Background, tile);
                    }
                }
                else
                {
                    var tileList = tiles.ToList(); // evaluate immediately
                    var sourceName = tileLayer.SourceName;
                    var maxDownloads = tileLayer.MaxParallelDownloads;

                    Task.Run(() => GetTiles(tileList, dispatcher, tileSource, sourceName, maxDownloads));
                }
            }
        }
Esempio n. 3
0
        private void TileLayerPropertyChanged(TileLayer tileLayer)
        {
            if (tileLayer != null)
            {
                if (TileLayers == null)
                {
                    TileLayers = new TileLayerCollection();
                }

                if (TileLayers.Count == 0)
                {
                    TileLayers.Add(tileLayer);
                }
                else if (TileLayers[0] != tileLayer)
                {
                    TileLayers[0] = tileLayer;
                }
            }

            if (tileLayer != null && tileLayer.Background != null)
            {
                if (storedBackground == null)
                {
                    storedBackground = Background;
                }

                Background = tileLayer.Background;
            }
            else if (storedBackground != null)
            {
                Background       = storedBackground;
                storedBackground = null;
            }

            if (tileLayer != null && tileLayer.Foreground != null)
            {
                if (storedForeground == null)
                {
                    storedForeground = Foreground;
                }

                Foreground = tileLayer.Foreground;
            }
            else if (storedForeground != null)
            {
                Foreground       = storedForeground;
                storedForeground = null;
            }
        }
Esempio n. 4
0
        internal void BeginGetTiles(TileLayer tileLayer, IEnumerable <Tile> tiles)
        {
            if (tiles.Any())
            {
                // get current TileLayer property values in UI thread
                var dispatcher     = tileLayer.Dispatcher;
                var tileSource     = tileLayer.TileSource;
                var sourceName     = tileLayer.SourceName;
                var maxDownloads   = tileLayer.MaxParallelDownloads;
                var animateOpacity = tileLayer.AnimateTileOpacity;

                ThreadPool.QueueUserWorkItem(o =>
                                             GetTiles(tiles.ToList(), dispatcher, tileSource, sourceName, maxDownloads, animateOpacity));
            }
        }
        public void BeginLoadTiles(TileLayer tileLayer, IEnumerable <Tile> tiles)
        {
            var tileSource      = tileLayer.TileSource;
            var imageTileSource = tileSource as ImageTileSource;
            var sourceName      = tileLayer.SourceName;
            var useCache        = Cache != null && !string.IsNullOrEmpty(sourceName);

            foreach (var tile in tiles)
            {
                try
                {
                    if (imageTileSource != null)
                    {
                        tile.SetImage(imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel));
                    }
                    else
                    {
                        var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);

                        if (uri == null)
                        {
                            tile.SetImage(null);
                        }
                        else if (!useCache)
                        {
                            tile.SetImage(new BitmapImage(uri));
                        }
                        else
                        {
                            pendingTiles.Enqueue(new PendingTile(tile, uri));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading tile image failed: {0}", ex.Message);
                }

                var newTaskCount = Math.Min(pendingTiles.Count, tileLayer.MaxParallelDownloads) - taskCount;

                while (newTaskCount-- > 0)
                {
                    Interlocked.Increment(ref taskCount);

                    Task.Run(async() => await LoadPendingTiles(tileSource, sourceName));
                }
            }
        }
        public void BeginLoadTiles(TileLayer tileLayer, IEnumerable<Tile> tiles)
        {
            var tileSource = tileLayer.TileSource;
            var imageTileSource = tileSource as ImageTileSource;
            var sourceName = tileLayer.SourceName;
            var useCache = Cache != null && !string.IsNullOrEmpty(sourceName);

            foreach (var tile in tiles)
            {
                try
                {
                    if (imageTileSource != null)
                    {
                        tile.SetImage(imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel));
                    }
                    else
                    {
                        var uri = tileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);

                        if (uri == null)
                        {
                            tile.SetImage(null);
                        }
                        else if (!useCache)
                        {
                            tile.SetImage(new BitmapImage(uri));
                        }
                        else
                        {
                            pendingTiles.Enqueue(new PendingTile(tile, uri));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading tile image failed: {0}", ex.Message);
                }

                var newTaskCount = Math.Min(pendingTiles.Count, tileLayer.MaxParallelDownloads) - taskCount;

                while (newTaskCount-- > 0)
                {
                    Interlocked.Increment(ref taskCount);

                    Task.Run(async () => await LoadPendingTiles(tileSource, sourceName));
                }
            }
        }
        private async Task LoadCachedImage(TileLayer tileLayer, Tile tile, Uri uri, BitmapImage bitmap)
        {
            var cacheKey = string.Format(@"{0}\{1}\{2}\{3}{4}",
                tileLayer.SourceName, tile.ZoomLevel, tile.XIndex, tile.Y, Path.GetExtension(uri.LocalPath));

            var buffer = await Cache.GetAsync(cacheKey) as IBuffer;

            if (buffer != null)
            {
                await LoadImageFromBuffer(buffer, bitmap);
                //Debug.WriteLine("Loaded cached image {0}", cacheKey);
            }
            else
            {
                DownloadAndCacheImage(uri, bitmap, cacheKey);
            }
        }
Esempio n. 8
0
 private void TileLayerPropertyChanged(TileLayer tileLayer)
 {
     if (tileLayer != null)
     {
         if (TileLayers == null)
         {
             TileLayers = new ObservableCollection <TileLayer>(new TileLayer[] { tileLayer });
         }
         else if (TileLayers.Count == 0)
         {
             TileLayers.Add(tileLayer);
         }
         else if (TileLayers[0] != tileLayer)
         {
             TileLayers[0] = tileLayer;
         }
     }
 }
Esempio n. 9
0
        private async Task LoadCachedImage(TileLayer tileLayer, Tile tile, Uri uri, BitmapImage bitmap)
        {
            var cacheKey = string.Format(@"{0}\{1}\{2}\{3}{4}",
                                         tileLayer.SourceName, tile.ZoomLevel, tile.XIndex, tile.Y, Path.GetExtension(uri.LocalPath));

            var buffer = await Cache.GetAsync(cacheKey) as IBuffer;

            if (buffer != null)
            {
                await LoadImageFromBuffer(buffer, bitmap);

                //Debug.WriteLine("Loaded cached image {0}", cacheKey);
            }
            else
            {
                DownloadAndCacheImage(uri, bitmap, cacheKey);
            }
        }
Esempio n. 10
0
        internal void BeginGetTiles(TileLayer tileLayer, IEnumerable <Tile> tiles)
        {
            var imageTileSource = tileLayer.TileSource as ImageTileSource;

            foreach (var tile in tiles)
            {
                try
                {
                    ImageSource image = null;

                    if (imageTileSource != null)
                    {
                        image = imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel);
                    }
                    else
                    {
                        var uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel);

                        if (uri != null)
                        {
                            if (Cache == null || string.IsNullOrEmpty(tileLayer.SourceName))
                            {
                                image = new BitmapImage(uri);
                            }
                            else
                            {
                                var bitmap = new BitmapImage();
                                image = bitmap;

                                Task.Run(async() => await LoadCachedImage(tileLayer, tile, uri, bitmap));
                            }
                        }
                    }

                    tile.SetImageSource(image, tileLayer.AnimateTileOpacity);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading tile image failed: {0}", ex.Message);
                }
            }
        }
        internal void BeginGetTiles(TileLayer tileLayer, IEnumerable<Tile> tiles)
        {
            var imageTileSource = tileLayer.TileSource as ImageTileSource;

            foreach (var tile in tiles)
            {
                try
                {
                    ImageSource image = null;

                    if (imageTileSource != null)
                    {
                        image = imageTileSource.LoadImage(tile.XIndex, tile.Y, tile.ZoomLevel, tile.Rotation);
                    }
                    else
                    {
                        var uri = tileLayer.TileSource.GetUri(tile.XIndex, tile.Y, tile.ZoomLevel, tile.Rotation);

                        if (uri != null)
                        {
                            if (Cache == null || string.IsNullOrEmpty(tileLayer.SourceName))
                            {
                                image = new BitmapImage(uri);
                            }
                            else
                            {
                                var bitmap = new BitmapImage();
                                image = bitmap;

                                Task.Run(async () => await LoadCachedImage(tileLayer, tile, uri, bitmap));
                            }
                        }
                    }

                    tile.SetImageSource(image, tileLayer.AnimateTileOpacity);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Loading tile image failed: {0}", ex.Message);
                }
            }
        }
Esempio n. 12
0
 private void SetTileLayer(TileLayer tileLayer)
 {
     SetCurrentValue(TileLayerProperty, tileLayer);
 }
Esempio n. 13
0
        private void TileLayerPropertyChanged(TileLayer tileLayer)
        {
            if (tileLayer != null)
            {
                if (TileLayers == null)
                {
                    TileLayers = new TileLayerCollection();
                }

                if (TileLayers.Count == 0)
                {
                    TileLayers.Add(tileLayer);
                }
                else if (TileLayers[0] != tileLayer)
                {
                    TileLayers[0] = tileLayer;
                }
            }

            if (tileLayer != null && tileLayer.Background != null)
            {
                if (storedBackground == null)
                {
                    storedBackground = Background;
                }

                Background = tileLayer.Background;
            }
            else if (storedBackground != null)
            {
                Background = storedBackground;
                storedBackground = null;
            }

            if (tileLayer != null && tileLayer.Foreground != null)
            {
                if (storedForeground == null)
                {
                    storedForeground = Foreground;
                }

                Foreground = tileLayer.Foreground;
            }
            else if (storedForeground != null)
            {
                Foreground = storedForeground;
                storedForeground = null;
            }
        }
Esempio n. 14
0
 private void SetTileLayer(TileLayer tileLayer)
 {
     TileLayer = tileLayer;
 }
        internal void BeginGetTiles(TileLayer tileLayer, IEnumerable<Tile> tiles)
        {
            if (tiles.Any())
            {
                // get current TileLayer property values in UI thread
                var tileSource = tileLayer.TileSource;
                var imageTileSource = tileSource as ImageTileSource;
                var animateOpacity = tileLayer.AnimateTileOpacity;
                var dispatcher = tileLayer.Dispatcher;

                if (imageTileSource != null && !imageTileSource.IsAsync) // call LoadImage in UI thread
                {
                    var setImageAction = new Action<Tile>(t => t.SetImageSource(LoadImage(imageTileSource, t), animateOpacity));

                    foreach (var tile in tiles)
                    {
                        dispatcher.BeginInvoke(setImageAction, DispatcherPriority.Background, tile); // with low priority
                    }
                }
                else
                {
                    var tileList = tiles.ToList();
                    var sourceName = tileLayer.SourceName;
                    var maxDownloads = tileLayer.MaxParallelDownloads;

                    ThreadPool.QueueUserWorkItem(o =>
                        GetTiles(tileList, dispatcher, tileSource, sourceName, animateOpacity, maxDownloads));
                }
            }
        }
        public void CancelLoadTiles(TileLayer tileLayer)
        {
            PendingTile pendingTile;

            while (pendingTiles.TryDequeue(out pendingTile)) ; // no Clear method
        }
Esempio n. 17
0
 private void TileLayerPropertyChanged(TileLayer tileLayer)
 {
     if (tileLayer != null)
     {
         if (TileLayers == null)
         {
             TileLayers = new ObservableCollection<TileLayer>(new TileLayer[] { tileLayer });
         }
         else if (TileLayers.Count == 0)
         {
             TileLayers.Add(tileLayer);
         }
         else if (TileLayers[0] != tileLayer)
         {
             TileLayers[0] = tileLayer;
         }
     }
 }
 public void CancelLoadTiles(TileLayer tileLayer)
 {
 }