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(); }
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())); }
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"); }
/// <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); } } }
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(); }