Web Tiles

Trabajando con baldosas XYZ

La baldosa XYZ (“Slippy Map”) es un enfoque para construir mapas en la web. El mapa mundial se divide en partes llamadas baldosas. Todas las baldosas se almacenan en servicios de baldosas Web Mapping Service como Openstreetmaps, Google Hybrid, Bing, OpenCycleMap, Thunderforest, etc. Y la biblioteca Aspose.GIS C# le permite trabajar con las baldosas XYZ.

Renderizar una baldosa xyz

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
var mapPath = Path.Combine(RunExamples.GetDataDir(), "out_osm_tile.png");
// we use the osm tile server
string url = "http://tile.openstreetmap.org/{z}/{x}/{y}.png";
using (var layer = Drivers.XyzTiles.OpenLayer(new XyzConnection(url)))
{
// print tile info
var tile = layer.GetTile(2, 3, 1);
Console.WriteLine($"CellX: {tile.CellX}, CellY: {tile.CellY}" );
Console.WriteLine($"Path: {tile.AsPath()}");
// render tile
var resampling = new RasterMapResampling() { Height = 256, Width = 256 };
using (var map = new Map(800, 800))
{
var raster = tile.AsRaster();
map.Add(new RasterMapLayer(raster){Resampling = resampling});
map.Render(mapPath, Renderers.Png);
}
Console.WriteLine($"Rendered Map: {mapPath}");
}

osm xyz tile

Renderizar baldosas xyz por extensión

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
var mapPath = Path.Combine(RunExamples.GetDataDir(), "out_osm_tiles.png");
// we use the osm tile server
string url = "http://tile.openstreetmap.org/{z}/{x}/{y}.png";
using (var layer = Drivers.XyzTiles.OpenLayer(new XyzConnection(url)))
{
// print tiles info
var extent = new Extent(-90, -40, 90, 40) {SpatialReferenceSystem = SpatialReferenceSystem.Wgs84};
var tiles = layer.GetTiles(2, extent).ToList();
// render tiles
var resampling = new RasterMapResampling() { Height = 800, Width = 800 };
using (var map = new Map(800, 800))
{
foreach (var tile in tiles)
{
var raster = tile.AsRaster();
map.Add(new RasterMapLayer(raster) { Resampling = resampling });
}
map.Render(mapPath, Renderers.Png);
}
Console.WriteLine($"Rendered Map: {mapPath}");
}

osm xyz tiles

Abrir baldosa xyz desde una carpeta

// For complete examples and data files, please go to https://github.com/aspose-gis/Aspose.GIS-for-.NET
string url = "C://tiles/{z}/{x}/{y}.png";
using (var layer = Drivers.XyzTiles.OpenLayer(new XyzConnection(url)))
{
// print tile info
var tile = layer.GetTile(0, 0, 0);
Console.WriteLine($"CellX: {tile.CellX}, CellY: {tile.CellY}");
Console.WriteLine($"Path: {tile.AsPath()}");
}