- Notifications
You must be signed in to change notification settings - Fork122
BruTile is a .NET library to access tile services like those of OpenStreetMap, MapBox or GeodanMaps.
License
BruTile/BruTile
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Status | |
---|---|
Build | |
NuGet BruTile | |
NuGet BruTile.MbTiles |
BruTile is a .NET Standard 2.0 library to access tile services like OpenStreetMap and Bing. Such tile services store pre-rendered tiles for a certain area and for various levels of detail. BruTile helps to determine which tiles to fetch for a certain viewport of a map.BruTile returns tiles as raw image streams and has no dependency on a specific client platform. BruTile does not display those tiles. You need to use a mapping library like SharpMap, ArcBruTile orMapsui or write your own code to display tiles.
What BruTile does is:
- Helps to construct a tile source, an object that has all information about a tile service.
- Helps to calculate which tiles you need, given a certain map extent and a map resolution (units per pixel).
- Helps you fetch those tiles.
BruTile V4 consists of 2 nugets that support .NET Standard 2.0.
Library | Targeted Framework |
---|---|
BruTile | .NET Standard 2.0 |
BruTile.MbTiles | .NET Standard 2.0 |
- Support for .NET Framework 4.5 has been removed (also the samples and tests have moved to .NET Core).
- BruTile.Desktop and BruTile.Desktop.DbCache have been deleted and their content has moved to the BruTile nuget.
For a demo showing various data sources download the source code and run BruTile.Demo in the Samples folder
Create a .NET Console app in Visual Studio. The the BruTile NuGet package. Use the package manager tools in Visual Studio or add it from the package manager console:
PM> install-package BruTile
// This is an example that creates the OpenStreetMap tile source:vartileSource=newHttpTileSource(newGlobalSphericalMercator(0,18),"http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",new[]{"a","b","c"},"OSM");
// the extent of the visible map changes but lets start with the whole worldvarextent=newExtent(-20037508,-20037508,20037508,20037508);varscreenWidthInPixels=400;// The width of the map on screen in pixelsvarresolution=extent.Width/screenWidthInPixels;vartileInfos=tileSource.Schema.GetTileInfos(extent,resolution);
Console.WriteLine("Show tile info");foreach(vartileInfointileInfos){vartile=awaittileSource.GetTileAsync(tileInfo);Console.WriteLine($"tile col:{tileInfo.Index.Col}, "+$"tile row:{tileInfo.Index.Row}, "+$"tile level:{tileInfo.Index.Level} , "+$"tile size{tile.Length}");}
Output:
tile col: 0, tile row: 0, tile level: 1 , tile size 11276 tile col: 0, tile row: 1, tile level: 1 , tile size 3260 tile col: 1, tile row: 0, tile level: 1 , tile size 10679 tile col: 1, tile row: 1, tile level: 1 , tile size 4009
// You can easily create an ITileSource for a number of predefined tile servers// with single line statements like:vartileSource1=KnownTileSources.Create();// The default is OpenStreetMapvartileSource2=KnownTileSources.Create(KnownTileSource.BingAerial);vartileSource3=KnownTileSources.Create(KnownTileSource.BingHybrid);vartileSource4=KnownTileSources.Create(KnownTileSource.StamenTonerLite);vartileSource5=KnownTileSources.Create(KnownTileSource.EsriWorldShadedRelief);
The predefined tile sources are defined in a single file. Take a look at that filehere to learn how you could create any tile source.
varmbtilesTilesource=newMbTilesTileSource(newSQLiteConnectionString("Resources/world.mbtiles",false));varmbTilesTile=awaitmbtilesTilesource.GetTileAsync(newTileInfo{Index=newTileIndex(0,0,0)});Console.WriteLine($"This is a byte array of an image file loaded from MBTiles with size:{mbTilesTile.Length}");
Output:
This is a byte array of an image file loaded from MBTiles with size: 27412
The above code can also be found in the BruTile sample called BruTile.GettingStarted in the Samples folder of this repository.
- WMTS
- TMS
- OSM (Like TMS with inverted y-axis)
- WMS (tiled requests to a regular WMS)
- ArcGIS Tile Server
- WMS-C
- Stability is currently our primary focus.
- ArcBruTile a plugin for ArcGIS
- SharpMap a GIS library
- Mapsui a MapComponent for Xamarin.Android. Xamarin.iOS, UWP and WPF
- DotSpatial a GIS library that is used inHydroDesktop
About
BruTile is a .NET library to access tile services like those of OpenStreetMap, MapBox or GeodanMaps.