Esempio n. 1
0
        public MainForm(ITileProvider floorTileProvider, ITileProvider objectTileProvider)
        {
            this.floorTileProvider = floorTileProvider;
            this.objectTileProvider = objectTileProvider;
            //			tileBrowserForm = new TileBrowserForm(floorTileProvider, objectTileProvider);
            mapView = new MapView(this);
            Controls.Add(mapView);
            Text = "Aesir";
            DataBindings.Add(new Binding("Size", settings, "FormSize", true,
                DataSourceUpdateMode.OnPropertyChanged));
            DataBindings.Add(new Binding("Location", settings, "FormLocation", true,
                DataSourceUpdateMode.OnPropertyChanged));
            MainMenu menu = new MainMenu();
            MenuItem[] fileItems = new MenuItem[] {
                new MenuItem("New"),
                new MenuItem("Open"),
                new MenuItem("Save")
            };
            menu.MenuItems.Add(new MenuItem("&File", fileItems));
            Menu = menu;
            StatusBarPanel panel = new StatusBarPanel();
            panel.BorderStyle = StatusBarPanelBorderStyle.Sunken;
            panel.AutoSize = StatusBarPanelAutoSize.Spring;
            panel.Text = "Ready";
            statusBar.Panels.Add(panel);
            statusBar.ShowPanels = true;
            Controls.Add(statusBar);
            //tileBrowserForm.Show();

            toolStrip.Renderer = new ToolStripSystemRenderer();
            Label label = new Label();
            label.Text = "LOL";
            toolStrip.Items.Add(new ToolStripControlHost(label));
            toolStrip.Items.Add(new ToolStripButton("Pencil"));
            toolStrip.Items.Add(new ToolStripButton("Line"));
            toolStrip.Items.Add(new ToolStripButton("Square"));
            Controls.Add(toolStrip);

            testForm = new Form();
            FloorTileBrowser shit = new FloorTileBrowser(floorTileProvider);
            shit.Dock = DockStyle.Fill;
            testForm.Controls.Add(shit);
            testForm.Show();
            // TEMP: stuff
            /*mapView.PaintWorldOverlay += delegate(object sender, PaintEventArgs args) {
                Console.WriteLine(mapView.VectorToTile(mousePosition));
                args.Graphics.DrawRectangle(Pens.Blue, new Rectangle((Point)(mapView.VectorToTile(mousePosition) * (Vector)Tile.Size), Tile.Size));
            };
            mapView.MouseMove += delegate(object sender, MouseEventArgs args) {
                mousePosition = (Vector)args.Location;
                mapView.Refresh();
            };*/
        }
Esempio n. 2
0
 private WmsTileSource(ITileProvider tileProvider, ITileSchema tileSchema) : base(tileProvider, tileSchema)
 {
 }
Esempio n. 3
0
 public FetchOnThread(ITileProvider tileProvider, TileInfo tileInfo, FetchTileCompletedEventHandler fetchTileCompleted)
 {
     _tileProvider = tileProvider;
     _tileInfo = tileInfo;
     _fetchTileCompleted = fetchTileCompleted;
 }
Esempio n. 4
0
 public YahooTileSource(YahooRequest request, IPersistentCache<byte[]> persistentCache = null)
 {
     _tileSchema = new SphericalMercatorInvertedWorldSchema();
     _tileProvider = new WebTileProvider(request, persistentCache);
 }
Esempio n. 5
0
 public DfaTileSource(string url)
 {
     Schema = new SphericalMercatorWorldSchema();
     //Schema.Resolutions.
     Provider = new WebTileProvider(new TmsRequest(new Uri(url), "png"));
 }
Esempio n. 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="cancelToken"></param>
        /// <param name="tileProvider"></param>
        /// <param name="tileInfo"></param>
        /// <param name="bitmaps"></param>
        /// <param name="retry"></param>
        /// <returns>true if thread finished without getting cancellation signal, false = cancelled</returns>
        private bool GetTileOnThread(CancellationToken cancelToken, ITileProvider tileProvider, TileInfo tileInfo, MemoryCache<Bitmap> bitmaps, bool retry)
        {
            byte[] bytes;
            try
            {
                if (cancelToken.IsCancellationRequested)
                    cancelToken.ThrowIfCancellationRequested();


                //We may have gotten the tile from another thread now..
                if (bitmaps.Find(tileInfo.Index) != null)
                {
                    return true;
                }

                if (Logger.IsDebugEnabled)
                    Logger.DebugFormat("Calling gettile on provider for tile {0},{1},{2}", tileInfo.Index.Level, tileInfo.Index.Col, tileInfo.Index.Row);

                bytes = tileProvider.GetTile(tileInfo);
                if (cancelToken.IsCancellationRequested)
                    cancelToken.ThrowIfCancellationRequested();

                using (var ms = new MemoryStream(bytes))
                {
                    Bitmap bitmap = new Bitmap(ms);
                    bitmaps.Add(tileInfo.Index, bitmap);
                    if (_fileCache != null && !_fileCache.Exists(tileInfo.Index))
                    {
                        AddImageToFileCache(tileInfo, bitmap);
                    }


                    if (cancelToken.IsCancellationRequested)
                        cancelToken.ThrowIfCancellationRequested();
                    OnMapNewTileAvaliable(tileInfo, bitmap);
                }
                return true;
            }
            catch (WebException ex)
            {
                if (Logger.IsDebugEnabled)
                    Logger.DebugFormat("Exception downloading tile {0},{1},{2} {3}", tileInfo.Index.Level, tileInfo.Index.Col, tileInfo.Index.Row, ex.Message);
                
                if (retry)
                {
                    return GetTileOnThread(cancelToken, tileProvider, tileInfo, bitmaps, false);
                }
                else
                {
                    if (_showErrorInTile)
                    {
                        var tileWidth = _source.Schema.GetTileWidth(tileInfo.Index.Level);
                        var tileHeight = _source.Schema.GetTileHeight(tileInfo.Index.Level);
                        //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 bitmap = new Bitmap(tileWidth, tileHeight);
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.Black),
                                new RectangleF(0, 0, tileWidth, tileHeight));
                        }
                        //Draw the Timeout Tile
                        OnMapNewTileAvaliable(tileInfo, bitmap);
                        //With timeout we don't add to the internal cache
                        //bitmaps.Add(tileInfo.Index, bitmap);
                    }
                    return true;
                }
            }
            catch (System.OperationCanceledException tex)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.InfoFormat("TileAsyncLayer - Thread aborting: {0}", Thread.CurrentThread.Name);
                    Logger.InfoFormat(tex.Message);
                }
                return false;
            }
            catch (Exception ex)
            {
                Logger.Warn("TileAsyncLayer - GetTileOnThread Exception", ex);
                //This is not due to cancellation so return true
                return true;
            }
        }
Esempio n. 7
0
 public WmsTileSource(ITileProvider provider, ITileSchema schema)
 {
     _provider = provider;
     _schema = schema;
 }
Esempio n. 8
0
        private void GetTileOnThread(object parameter)
        {
            object[] parameters = (object[])parameter;
            if (parameters.Length != 5)
            {
                throw new ArgumentException("Five parameters expected");
            }
            ITileProvider tileProvider = (ITileProvider)parameters[0];
            TileInfo      tileInfo     = (TileInfo)parameters[1];
            //MemoryCache<Bitmap> bitmaps = (MemoryCache<Bitmap>)parameters[2];
            Dictionary <TileIndex, Bitmap> bitmaps = (Dictionary <TileIndex, Bitmap>)parameters[2];
            AutoResetEvent autoResetEvent          = (AutoResetEvent)parameters[3];
            bool           retry = (bool)parameters[4];

            var setEvent = true;

            try
            {
                byte[] bytes  = tileProvider.GetTile(tileInfo);
                Bitmap bitmap = new Bitmap(new MemoryStream(bytes));
                bitmaps.Add(tileInfo.Index, bitmap);
                if (_fileCache != null)
                {
                    AddImageToFileCache(tileInfo, bitmap);
                }
            }
            catch (WebException ex)
            {
                if (retry)
                {
                    GetTileOnThread(new object[] { tileProvider, tileInfo, bitmaps, autoResetEvent, false });
                    setEvent = false;
                    return;
                }
                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 schema = (TileSchema)_source.Schema;
                    var bitmap = new Bitmap(schema.Width, schema.Height);
                    using (IGraphics graphics = Graphics.FromImage(bitmap).G())
                    {
                        graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12),
                                            new SolidBrush(Color.Black),
                                            new RectangleF(0, 0, schema.Width, schema.Height));
                    }
                    bitmaps.Add(tileInfo.Index, bitmap);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            finally
            {
                if (setEvent)
                {
                    autoResetEvent.Set();
                }
            }
        }
 public SuperMapTileSource(string serviceUrl, string mapName, uint tileSize, string format, double[] scales, Utility.MapParameter mapParameter)
 {
     _tileProvider = new iServerProvider(serviceUrl, mapName, tileSize, format, scales ,mapParameter);
     _tileSchema = new iServerSchema(serviceUrl, mapName, tileSize, format, scales);
 }
Esempio n. 10
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="tileProvider">The tile provider</param>
 /// <param name="tileSchema">The tile schema</param>
 public TileSource(ITileProvider tileProvider, ITileSchema tileSchema)
 {
     _provider = tileProvider;
     Schema    = tileSchema;
 }
Esempio n. 11
0
        private void GetTileOnThread(CancellationToken cancelToken, ITileProvider tileProvider, TileInfo tileInfo, MemoryCache<Bitmap> bitmaps, bool retry)
        {
            byte[] bytes;
            try
            {
                if (cancelToken.IsCancellationRequested)
                    cancelToken.ThrowIfCancellationRequested();

                bytes = tileProvider.GetTile(tileInfo);
                if (cancelToken.IsCancellationRequested)
                    cancelToken.ThrowIfCancellationRequested();

                Bitmap bitmap = new Bitmap(new MemoryStream(bytes));
                bitmaps.Add(tileInfo.Index, bitmap);
                if (_fileCache != null && !_fileCache.Exists(tileInfo.Index))
                {
                    AddImageToFileCache(tileInfo, bitmap);
                }

                if (cancelToken.IsCancellationRequested)
                    cancelToken.ThrowIfCancellationRequested();
                OnMapNewTileAvaliable(tileInfo, bitmap);
            }
            catch (WebException ex)
            {
                if (retry)
                {
                    GetTileOnThread(cancelToken, tileProvider, tileInfo, bitmaps, false);
                }
                else
                {
                    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 bitmap = new Bitmap(_source.Schema.Width, _source.Schema.Height);
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12), new SolidBrush(Color.Black),
                                new RectangleF(0, 0, _source.Schema.Width, _source.Schema.Height));
                        }
                        //Draw the Timeout Tile
                        OnMapNewTileAvaliable(tileInfo, bitmap);

                        //With timeout we don't add to the internal cache
                        //bitmaps.Add(tileInfo.Index, bitmap);
                    }
                }
            }
            catch (ThreadAbortException tex)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.InfoFormat("TileAsyncLayer - Thread aborting: {0}", Thread.CurrentThread.Name);
                    Logger.InfoFormat(tex.Message);
                }
            }
            catch (Exception ex)
            {
                Logger.Warn("TileAsyncLayer - GetTileOnThread Exception", ex);
            }
        }
Esempio n. 12
0
 private WmscTileSource(ITileSchema tileSchema, ITileProvider tileProvider)
     : base(tileProvider, tileSchema)
 {
 }
Esempio n. 13
0
        private void GetTileOnThread(object parameter)
        {
            object[] parameters = (object[])parameter;
            if (parameters.Length != 6)
            {
                throw new ArgumentException("Six parameters expected");
            }
            ITileProvider tileProvider = (ITileProvider)parameters[0];
            TileInfo      tileInfo     = (TileInfo)parameters[1];
            //MemoryCache<Bitmap> bitmaps = (MemoryCache<Bitmap>)parameters[2];
            var            bitmaps        = (ConcurrentDictionary <TileIndex, Bitmap>)parameters[2];
            AutoResetEvent autoResetEvent = (AutoResetEvent)parameters[3];
            bool           retry          = (bool)parameters[4];
            var            takenFromCache = (IDictionary <TileIndex, bool>)parameters[5];

            var setEvent = true;

            try
            {
                byte[] bytes  = tileProvider.GetTile(tileInfo);
                Bitmap bitmap = new Bitmap(new MemoryStream(bytes));
                bitmaps.TryAdd(tileInfo.Index, bitmap);

                // this bitmap will later be memory cached
                takenFromCache.Add(tileInfo.Index, false);

                // add to persistent cache if enabled
                if (_fileCache != null)
                {
                    AddImageToFileCache(tileInfo, bitmap);
                }
            }
            catch (WebException ex)
            {
                if (retry)
                {
                    GetTileOnThread(new object[] { tileProvider, tileInfo, bitmaps, autoResetEvent, false, takenFromCache });
                    setEvent = false;
                    return;
                }
                if (_showErrorInTile)
                {
                    try
                    {
                        //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 tileWidth  = _source.Schema.GetTileWidth(tileInfo.Index.Level);
                        var tileHeight = _source.Schema.GetTileHeight(tileInfo.Index.Level);
                        var bitmap     = new Bitmap(tileWidth, tileHeight);
                        using (var graphics = Graphics.FromImage(bitmap))
                        {
                            graphics.DrawString(ex.Message, new Font(FontFamily.GenericSansSerif, 12),
                                                new SolidBrush(Color.Black),
                                                new RectangleF(0, 0, tileWidth, tileHeight));
                        }
                        bitmaps.TryAdd(tileInfo.Index, bitmap);
                    }
                    catch (Exception e)
                    {
                        // we don't want fatal exceptions here!
                        Logger.Error(e);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.Message);
            }
            finally
            {
                if (setEvent)
                {
                    autoResetEvent.Set();
                }
            }
        }
Esempio n. 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>
 internal TileFetcher(ITileProvider provider, int minTiles, int maxTiles, ITileCache <byte[]> permaCache)
     : this(provider, minTiles, maxTiles, permaCache, BruTileLayerPlugin.Settings.MaximumNumberOfThreads)
 {
 }
 // Methods
 public ArcGISTileCompactSource(string Url)
 {
     this.provider = new ArcGISTileCompactProvider(Url);
     this.schema = new ArcGISTileCompactSchema(Url);
 }
        /// <summary>
        /// Loads the image by tileposition
        /// </summary>
        public void LoadImage(ITileProvider tileProvider)
        {
            var tileX = this.TileX;
            var tileY = this.TileY;
            var localZoom = (int)Math.Pow(2, this.Zoom);
            var currentZoom = this.Zoom;

            while (currentZoom > MaxZoom)
            {
                currentZoom--;
                tileX /= 2;
                tileY /= 2;
            }

            while (tileX < 0)
            {
                tileX += localZoom;
            }

            while (tileY < 0)
            {
                tileY += localZoom;
            }

            while (tileX >= localZoom)
            {
                tileX -= localZoom;
            }

            while (tileY >= localZoom)
            {
                tileY -= localZoom;
            }

            var image = new Image();
            image.Opacity = 0.0;
            Canvas.SetZIndex(image, Zoom);

            TileImage = image;

            var uri = tileProvider.GetTileUri(Zoom, tileX, tileY);
            var source = new BitmapImage(uri);

            source.ImageOpened += SourceOnImageOpened;
            image.Source = source;
        }
Esempio n. 17
0
 public TileSource(ITileProvider tileProvider, ITileSchema tileSchema)
 {
     Provider = tileProvider;
     Schema = tileSchema;
 }
Esempio n. 18
0
 public FetchOnThread(ITileProvider tileProvider, TileInfo tileInfo, FetchTileCompletedEventHandler fetchTileCompleted)
 {
     _tileProvider       = tileProvider;
     _tileInfo           = tileInfo;
     _fetchTileCompleted = fetchTileCompleted;
 }