Ejemplo n.º 1
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void OnRender(System.Drawing.Graphics g, IMap map)
        {
            MapTransform mapTransform = new MapTransform(new PointF((float)Map.Center.X, (float)Map.Center.Y), (float)Map.PixelSize, Map.Image.Width, Map.Image.Height);

            int level = BruTile.Utilities.GetNearestLevel(schema.Resolutions, Map.PixelSize);

            IList <TileInfo> tileInfos = schema.GetTilesInView(mapTransform.Extent, level);

            IRequest requestBuilder = new TmsRequest(new Uri("http://a.tile.openstreetmap.org"), "png");

            var graphics = Graphics.FromImage(Image);

            //log.DebugFormat("Downloading tiles:");
            foreach (var tileInfo in tileInfos)
            {
                var bytes = cache.Find(tileInfo.Index);

                if (bytes == default(byte[]))
                {
                    try
                    {
                        //log.DebugFormat("row: {0}, column: {1}, level: {2}", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                        var url = requestBuilder.GetUri(tileInfo);
                        bytes = FetchImage(url);
                        cache.Add(tileInfo.Index, bytes);
                    }
                    catch (WebException e)
                    {
                        //log once per 45 seconds max
                        if ((DateTime.Now - lastErrorLogged) > TimeSpan.FromSeconds(45))
                        {
                            log.Error("Can't fetch tiles from the server", e);
                            lastErrorLogged = DateTime.Now;
                        }
                    }
                }
                else
                {
                    //log.DebugFormat("row: {0}, column: {1}, level: {2} (cached)", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                }

                if (bytes == null)
                {
                    continue;
                }
                using (var bitmap = new Bitmap(new MemoryStream(bytes)))
                {
                    var rectangle = mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY,
                                                            tileInfo.Extent.MaxX, tileInfo.Extent.MaxY);
                    DrawTile(schema, graphics, bitmap, rectangle);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void OnRender(System.Drawing.Graphics g, IMap map)
        {
            MapTransform mapTransform = new MapTransform(new PointF((float)Map.Center.X, (float)Map.Center.Y), (float)Map.PixelSize, Map.Image.Width, Map.Image.Height);

            _tileSource = KnownTileSources.Create(KnownTileSource.BingHybrid, BingApiKey);
            string level = BruTile.Utilities.GetNearestLevel(_tileSource.Schema.Resolutions, Map.PixelSize);

            IEnumerable <TileInfo> tileInfos = Schema.GetTileInfos(mapTransform.Extent, level);

            //new BingRequest(BingRequest.UrlBing, string.Empty, BingMapType.Hybrid);

            using (var graphics = Graphics.FromImage(Image))
            {
                // log.DebugFormat("Downloading tiles:");
                foreach (var tileInfo in tileInfos)
                {
                    var bytes = cache.Find(tileInfo.Index);

                    if (bytes == default(byte[]))
                    {
                        try
                        {
                            // log.DebugFormat("row: {0}, column: {1}, level: {2}", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                            bytes = _tileSource.GetTile(tileInfo);
                            cache.Add(tileInfo.Index, bytes);
                        }
                        catch (WebException e)
                        {
                            log.Error("Can't fetch tiles from the server", e);
                        }
                    }
                    else
                    {
                        //log.DebugFormat("row: {0}, column: {1}, level: {2} (cached)", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                    }

                    if (bytes == null)
                    {
                        continue;
                    }
                    using (var bitmap = new Bitmap(new MemoryStream(bytes)))
                    {
                        var rectangle = mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY,
                                                                tileInfo.Extent.MaxX, tileInfo.Extent.MaxY);
                        DrawTile(Schema, level, graphics, bitmap, rectangle);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void OnRender(System.Drawing.Graphics g, Map map)
        {
            MapTransform mapTransform = new MapTransform(new PointF((float)Map.Center.X, (float)Map.Center.Y), (float)Map.PixelSize, Map.Image.Width, Map.Image.Height);

            int level = BruTile.Utilities.GetNearestLevel(schema.Resolutions, Map.PixelSize);

            IList <TileInfo> tileInfos = schema.GetTilesInView(mapTransform.Extent, level);

            IRequest requestBuilder = new BingRequest(BingRequest.UrlBing, string.Empty, MapType.Hybrid);

            var graphics = Graphics.FromImage(Image);

            // log.DebugFormat("Downloading tiles:");
            foreach (var tileInfo in tileInfos)
            {
                var bytes = cache.Find(tileInfo.Index);

                if (bytes == default(byte[]))
                {
                    try
                    {
                        // log.DebugFormat("row: {0}, column: {1}, level: {2}", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                        var url = requestBuilder.GetUri(tileInfo);
                        bytes = RequestHelper.FetchImage(url);
                        cache.Add(tileInfo.Index, bytes);
                    }
                    catch (WebException e)
                    {
                        log.Error("Can't fetch tiles from the server", e);
                    }
                }
                else
                {
                    log.DebugFormat("row: {0}, column: {1}, level: {2} (cached)", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                }

                if (bytes == null)
                {
                    continue;
                }
                using (var bitmap = new Bitmap(new MemoryStream(bytes)))
                {
                    var rectangle = mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY,
                                                            tileInfo.Extent.MaxX, tileInfo.Extent.MaxY);
                    DrawTile(schema, graphics, bitmap, rectangle);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Renders the layer
        /// </summary>
        /// <param name="g">Graphics object reference</param>
        /// <param name="map">Map which is rendered</param>
        public override void OnRender(System.Drawing.Graphics g, Map map)
        {
            MapTransform mapTransform = new MapTransform(new PointF((float)Map.Center.X, (float)Map.Center.Y), (float)Map.PixelSize, Map.Image.Width, Map.Image.Height);

            int level = BruTile.Utilities.GetNearestLevel(schema.Resolutions, Map.PixelSize);
            
            IList<TileInfo> tileInfos = schema.GetTilesInView(mapTransform.Extent, level);

            IRequest requestBuilder = new TmsRequest(new Uri("http://a.tile.openstreetmap.org"), "png");

            var graphics = Graphics.FromImage(Image);
            //log.DebugFormat("Downloading tiles:");
            foreach (var tileInfo in tileInfos)
            {
                var bytes = cache.Find(tileInfo.Index);

                if (bytes == default(byte[]))
                {
                    try
                    {
                        //log.DebugFormat("row: {0}, column: {1}, level: {2}", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                        var url = requestBuilder.GetUri(tileInfo);
                        bytes = RequestHelper.FetchImage(url);
                        cache.Add(tileInfo.Index, bytes);
                    }
                    catch (WebException e)
                    {
                        log.Error("Can't fetch tiles from the server", e);
                    }
                }
                else
                {
                    log.DebugFormat("row: {0}, column: {1}, level: {2} (cached)", tileInfo.Index.Row, tileInfo.Index.Col, tileInfo.Index.Level);
                }

                if (bytes == null) continue;
                using (var bitmap = new Bitmap(new MemoryStream(bytes)))
                {
                    var rectangle = mapTransform.WorldToMap(tileInfo.Extent.MinX, tileInfo.Extent.MinY,
                                                            tileInfo.Extent.MaxX, tileInfo.Extent.MaxY);
                    DrawTile(schema, graphics, bitmap, rectangle);
                }
            }
        }