Ejemplo n.º 1
0
        public void GetUriTest()
        {
            // arrange
            var request = new BingRequest(
                "http://t{s}.tiles.virtualearth.net/tiles/r{quadkey}.jpeg?g={apiversion}&token={userkey}",
                "pindakaas", "555", new [] { "000", "111" });
            var tileInfo = new TileInfo {
                Index = new TileIndex(3, 4, "5")
            };

            // act
            request.GetUri(tileInfo); // to test the internal server node counter
            var url = request.GetUri(tileInfo);

            // assert
            Assert.True(url.ToString() == "http://t111.tiles.virtualearth.net/tiles/r00211.jpeg?g=555&token=pindakaas");
        }
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);

            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.º 3
0
        public void GetUriMultiThreadedTest()
        {
            // arrange
            var request = new BingRequest(
                "http://t{s}.tiles.virtualearth.net/tiles/r{quadkey}.jpeg?g={apiversion}&token={userkey}",
                "pindakaas", "555", new[] { "000", "111" });
            var tileInfo = new TileInfo {
                Index = new TileIndex(3, 4, "5")
            };
            var urls = new ConcurrentBag <Uri>(); // List is not thread save

            // act
            var requests = new List <Func <Uri> >();

            for (var i = 0; i < 100; i++)
            {
                requests.Add(() => request.GetUri(tileInfo));
            }
            Parallel.ForEach(requests, r => urls.Add(r()));

            // assert
            Assert.True(urls.FirstOrDefault(u => u.ToString() == "http://t111.tiles.virtualearth.net/tiles/r00211.jpeg?g=555&token=pindakaas") != null);
        }