Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

TextureTileLayer

Brian Kircher edited this page Apr 23, 2021 · 4 revisions

The texture source used to render the map can be configured via the TextureTileLayer system. The map calls into a layer to request the textures relevant for the given view. The layer is responsible for requesting and providing texture data on a per-tile basis.

The tile system is described in more detail here.

A default implementation is provided by the DefaultTextureTileLayer which uses Bing Maps imagery.

HttpTextureTileLayer

A common scenario is to request tiles from a remote server, where tiles are indexed by a tile coordinate or quadkey.

The HttpTextureTileLayer makes requesting these tiles simpler by taking a URL with placeholders for these identifiers.

Supported tile formats are PNG and JPG.

Example URLs

The appropriate placeholders should be chosen based on what the service expects.

Placeholders URL
X, Y, and Zoom http://www.example.com/{x}/{y}/{zoomlevel}.jpg
Quadkey https://www.example.com/{quadkey}.png
Subdomain http://www.{subdomain}.example.com/{quadkey}.jpg

The {zoomlevel} placeholder can be aliased by {zoom} or {z}.

Placeholders are case insensitive.

Implementing a custom TextureTileLayer

If a different data source is required or the HttpTextureTileLayer does not work with a certain tile format, a custom implementation can be created by extending from the TextureTileLayer.

In general, texture data can be provided from a variety of sources:

  • Remote servers
  • Local disk
  • Textures generated procedurally

The layer implementation must provide a GetTexture method.

public class FooTextureTileLayer : TextureTileLayer
{
    public override async Task<TextureTile> GetTexture(TileId tileId, CancellationToken cancellationToken = default)
    {
        // Request, load, and/or process data asynchronously...

        // For PNG/JPG...
        return TextureTile.FromImageData(/*...*/);

        // For GPU consumable format (RGB24, RGBA32, etc...)
        return TextureTile.FromRawData(/*...*/);
    }
}

Note: GetTexture is called asynchronously-- not on the Unity thread. So web requests or file IO can be performed here without impacting framerate.

Stacking layers

Moreover, TextureTileLayers can be stacked. This allows for different texture sources to be overlaid on top of one another, e.g. a transparent weather texture can be overlaid on-top of the DefaultTextureTileLayer's base imagery.

As shown above, the order of the layers can be configured through the MapRenderer's Editor UI. Layers can be dragged up or down the list to rearrange the priority.

Below the weather texture source is overlaid on the base map imagery.

Up to 4 texture tile layers can be applied to the map.

Transparency is represented in the alpha channel of the texture and assumed to not to be premultiplied into the color channels.


Clone this wiki locally