Code Monkey home page Code Monkey logo

brutile's Introduction

Status
Build Build status
NuGet NuGet Status

BruTile

BruTile is a .NET Standard 1.1 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 or Mapsui or write your own code to display tiles.

What BruTile does is:

  1. Helps to construct a tile source, an object that has all information about a tile service.
  2. Helps to calculate which tiles you need, given a certain map extent and a map resolution (units per pixel).
  3. Helps you fetch those tiles.

BruTile is a .NET Standard library

BruTile 2.0 supports .NET Standard. The Profiles by NuGet package:

Library Targeted Framework
BruTile .NET Standard 1.1
BruTile.MbTiles .NET Standard 1.1
BruTile.Desktop .NET Standard 1.6
BruTile.Desktop.DbCache .NET Standard 2.0

All the above libraries additionally target .Net Framework 4.5

Demo

For a demo showing various data sources download the source code and run BruTile.Demo in the Samples folder

Getting Started

1) Create an app and add the BruTile NuGet package

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 

2) Create a tile source

// This is an example that creates the OpenStreetMap tile source:
var tileSource = new HttpTileSource(new GlobalSphericalMercator(0, 18),
    "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
    new[] {"a", "b", "c"}, "OSM");

3) Calculate which tiles you need

// the extent of the visible map changes but lets start with the whole world
var extent = new Extent(-20037508, -20037508, 20037508, 20037508);
var screenWidthInPixels = 400; // The width of the map on screen in pixels
var resolution = extent.Width / screenWidthInPixels;
var tileInfos = tileSource.Schema.GetTileInfos(extent, resolution);

4) Fetch the tiles from the service

foreach (var tileInfo in tileInfos)
{
    var tile = tileSource.GetTile(tileInfo);

    Console.WriteLine(
        $"tile col: {tileInfo.Index.Col}, " +
        $"tile row: {tileInfo.Index.Row}, " +
        $"tile level: {tileInfo.Index.Level} , " +
        $"tile size {tile.Length}");
}

This will be the 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

5) Try other tile sources

// You can easily create an ITileSource for a number of predefined tile servers
// with single line statements like:
var tileSource1 = KnownTileSources.Create(); // The default is OpenStreetMap
var tileSource2 = KnownTileSources.Create(KnownTileSource.BingAerial);
var tileSource3 = KnownTileSources.Create(KnownTileSource.BingHybrid);
var tileSource4 = KnownTileSources.Create(KnownTileSource.StamenTonerLite);
var tileSource5 = KnownTileSources.Create(KnownTileSource.EsriWorldShadedRelief);

The predefined tile sources are defined in a single file. Take a look at that file here to learn how you could create any tile source.

The above code can also be found in the BruTile sample called BruTile.GettingStarted in the Samples folder of this repository.

Supported tile service protocols:

Roadmap

  • Stability is currently our primary focus.

Projects that use BruTile

License

Apache 2.0

brutile's People

Contributors

ahuarte47 avatar bertt avatar bradh avatar charlenni avatar dobauer avatar fobermaier avatar harmens avatar joecooper avatar josh-cooley avatar kellison avatar mogikanin avatar pauldendulk avatar plamen-i avatar scottdewald avatar starnutoditopo avatar stephdms avatar tebben avatar waffle-iron avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.