Ejemplo n.º 1
0
        public QuantizedMeshTileSource(string url, string ext = "terrain")
        {
            var request = new TmsRequest(new Uri(url), ext);

            Provider = new WebTileProvider(request, fetchTile: FetchTile);
            Schema   = new GlobalSphericalMercator();
        }
Ejemplo n.º 2
0
        public MapBoxVectorTileSource(string url, string ext = "pbf")
        {
            var request = new TmsRequest(new Uri(url), ext);

            Provider = new WebTileProvider(request, fetchTile: FetchTile);
            Schema   = new GlobalSphericalMercator();
        }
Ejemplo n.º 3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            MapTransform mapTransform = new MapTransform(new PointF(0, 0), 50000f, this.Width, this.Height);

            // 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.
            ITileSchema schema = CreateTileSchema();

            int level = Utilities.GetNearestLevel(schema.Resolutions, mapTransform.Resolution);
            IList <TileInfo> infos = schema.GetTilesInView(mapTransform.Extent, level);

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

            Graphics graphics = Graphics.FromImage(buffer);

            foreach (TileInfo info in infos)
            {
                Uri        url    = requestBuilder.GetUri(info);
                byte[]     bytes  = RequestHelper.FetchImage(url);
                Bitmap     bitmap = new Bitmap(new MemoryStream(bytes));
                RectangleF extent = mapTransform.WorldToMap(info.Extent.MinX, info.Extent.MinY, info.Extent.MaxX, info.Extent.MaxY);
                extent = DrawTile(schema, graphics, bitmap, extent);
            }

            this.Invalidate();
        }
 public GeodanWorldTmsTileSource()
 {
     const string url = "http://geoserver.nl/tiles/tilecache.aspx/1.0.0/world_GM/";
     var parameters = new Dictionary<string, string>();
     parameters.Add("seriveparam", "world_GM");
     parameters.Add("uid", "4c6b3b161be3a2eb513b66b09a70f18d");
     var request = new TmsRequest(new Uri(url), "png", parameters);
     Provider = new WebTileProvider(request);
     Schema = new GlobalSphericalMercator(YAxis.TMS);
 }
Ejemplo n.º 5
0
        public GeodanWorldTmsTileSource()
        {
            const string url        = "http://geoserver.nl/tiles/tilecache.aspx/1.0.0/world_GM/";
            var          parameters = new Dictionary <string, string>();

            parameters.Add("seriveparam", "world_GM");
            parameters.Add("uid", "4c6b3b161be3a2eb513b66b09a70f18d");
            var request = new TmsRequest(new Uri(url), "png", parameters);

            Provider = new WebTileProvider(request);
            Schema   = new SphericalMercatorWorldSchema();
        }
Ejemplo n.º 6
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.º 7
0
        public void WhenInitializedWithServerNodesShouldReturnCorrectUri()
        {
            // arrange
            var request  = new TmsRequest("http://{S}.tileserver.com", "png", new[] { "a", "b" });
            var tileInfo = new TileInfo {
                Index = new TileIndex(1, 2, 3)
            };

            // act
            var uri = request.GetUri(tileInfo);

            // assert
            Assert.True(new [] { "http://a.tileserver.com/3/1/2.png", "http://b.tileserver.com/3/1/2.png" }.Contains(uri.ToString()));
        }
Ejemplo n.º 8
0
        public void WhenInitializedShouldReturnCorrectUri()
        {
            // arrange
            var request  = new TmsRequest("http://tileserver.com", "png");
            var tileInfo = new TileInfo {
                Index = new TileIndex(1, 2, 3)
            };

            // act
            var uri = request.GetUri(tileInfo);

            // assert
            Assert.AreEqual(uri.ToString(), "http://tileserver.com/3/1/2.png");
        }
Ejemplo n.º 9
0
        private void Form1Load(object sender, EventArgs e)
        {
            var transform = new Transform(new PointF(629816f, 6805085f), 1222.992452344f, Width, Height);

            var schema = CreateTileSchema();
            var tiles  = schema.GetTilesInView(transform.Extent, Utilities.GetNearestLevel(schema.Resolutions, transform.Resolution));

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

            var graphics = Graphics.FromImage(buffer);

            foreach (var tile in tiles)
            {
                var    url    = requestBuilder.GetUri(tile);
                byte[] bytes  = RequestHelper.FetchImage(url);
                var    bitmap = new Bitmap(new MemoryStream(bytes));
                graphics.DrawImage(bitmap, transform.WorldToView(tile.Extent.MinX, tile.Extent.MinY, tile.Extent.MaxX, tile.Extent.MaxY));
            }

            Invalidate();
        }
Ejemplo n.º 10
0
        private void Form1Load(object sender, EventArgs e)
        {
            var viewport = new Viewport(new PointF(629816f, 6805085f), 1222.992452344f, Width, Height);

            var schema = CreateTileSchema();
            var tiles  = schema.GetTileInfos(viewport.Extent, Utilities.GetNearestLevel(schema.Resolutions, viewport.UnitsPerPixel));

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

            var graphics = Graphics.FromImage(_buffer);

            foreach (var tile in tiles)
            {
                var url         = requestBuilder.GetUri(tile);
                var bytes       = RequestHelper.FetchImage(url);
                var bitmap      = new Bitmap(new MemoryStream(bytes));
                var destination = viewport.WorldToScreen(tile.Extent.MinX, tile.Extent.MinY, tile.Extent.MaxX, tile.Extent.MaxY);
                graphics.DrawImage(bitmap, RoundToPixel(destination));
            }
            Invalidate();
        }
Ejemplo n.º 11
0
        private void Form1Load(object sender, EventArgs e)
        {
            var viewport = new Viewport(new PointF(629816f, 6805085f), 1222.992452344f, Width, Height);

            var schema = CreateTileSchema();
            var tiles = schema.GetTileInfos(viewport.Extent, Utilities.GetNearestLevel(schema.Resolutions, viewport.UnitsPerPixel));

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

            var graphics = Graphics.FromImage(_buffer);
            foreach (var tile in tiles)
            {
                var url = requestBuilder.GetUri(tile);
                byte[] bytes = RequestHelper.FetchImage(url);
                var bitmap = new Bitmap(new MemoryStream(bytes));
                var destination = viewport.WorldToScreen(tile.Extent.MinX, tile.Extent.MinY, tile.Extent.MaxX, tile.Extent.MaxY);
                graphics.DrawImage(bitmap, RoundToPixel(destination));
            }
            Invalidate();
        }