model

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 16 Imported by: 0

README

TileRenderModel

=====================

TileRenderModel provides a model that consumes a set of interfaces to make displaying map tiles easy.

map

LatLon

A simple wrapper on a float64 latitude and longitude.

Tile

A Tile is a trio of integers defining an X, Y, and Z coordinate, where Z is a zoom, and X and Y vary between 0 and 2^Z-1. It provides helper functions for finding the tile at a lower zoom level that contains this tile, or the 4 child tiles contained within this tile at the next higher zoom level.

TileMapper

A TileMapper provides the functions necessary for converting between LatLons and Tiles.

Most usecases can just use tile.OSM for this.

TileProvider

A TileProvider renders a given Tile and returns an Image.

AdvancedTileProvider

A TileProvider that can also render a range of tiles.

StreamingTileProvider

A TileProvider that can render a range of tiles and return them down a channel.

FallbackTileProvider

An AdvancedTileProvider that can fall back to an alternate provider when a rendering fails.

TestTileProvider

Renders an image of a specified size with the tile coordinates drawn on it, for testing.

OSMTileProvider

The only concrete non-test provider currently. Accepts a Server URL for use to obtain tile images, replacing $X, $Y, and $Z in the URL with the tile coordinates.

CompositingTileProvider

Takes a list of TileProviders and renders them in order, compositing later images onto earlier ones in order.

TileCache

A LeastRecentlyUsed in-memory tile cache that fulfills the AdvancedTileProvider interface, takes a TileProvider to perform the actual rendering.

StreamingTileCache

Implements the StreamingTileProvider over a TileCache.

FallbackTileCache

Implements the FallbackTileProvider over a primary TileProvider and a fallback TileProvider, responding with fallback tiles and putting rendering requests in a queue to render in the background.

TileRenderModel

Takes a TileMapper and TileProvider and handles requesting and merging tiles into a single image to return to the RenderView.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var OSM = OSMTileMapper{256}

Functions

func GenericBoundsFromTiles

func GenericBoundsFromTiles(t TileMapper, a Tile, b Tile, rightbottom LatLon) (LatLon, LatLon)

GenericBoundsFromTiles returns the lat/lon pairs that encompass a set of tiles

func GenericTilesFromBounds

func GenericTilesFromBounds(t TileMapper, a LatLon, b LatLon, maxWidth uint, maxHeight uint, tileSize uint, maxZoomLevel uint) (Tile, Tile)

A generic, mechanical method for determining a proper zoom level and set of tiles for a given image dimension and coordinate range by iteration, such that the image resulting from rendering the given tiles and cutting to the specified lat and lon will be smaller in both dimensions than the maxWidth and maxHeight given

func SwapIfNeeded

func SwapIfNeeded(a Tile, b Tile) (Tile, Tile)

SwapIfNeeded is a utility function that ensures we have the upper left and bottom right tiles

Types

type AdvancedTileProvider

type AdvancedTileProvider interface {
	TileProvider

	RenderTileRange(a Tile, b Tile) []TileImage
}

type CompositingTileProvider

type CompositingTileProvider struct {
	// contains filtered or unexported fields
}

func NewCompositingTileProvider

func NewCompositingTileProvider(providers ...TileProvider) *CompositingTileProvider

func (*CompositingTileProvider) RenderTile

func (c *CompositingTileProvider) RenderTile(t Tile) image.Image

type FallbackTileCache

type FallbackTileCache struct {
	TileCache
	// contains filtered or unexported fields
}

FallbackTileCache provides a fixed size LRU cache, similar to TileCache, but takes two TileProviders, a primary and a fallback. The fallback should be one that renders instantly. The primary can be a slower render that takes as long as needed. RenderTileRange renders exclusively from cached images from the primary tile provider and fills uncached spaces with fallback renderings that are never cached. A separate goroutine renders the primary tiles into the cache from a queue.

func NewFallbackTileCache

func NewFallbackTileCache(provider TileProvider, fallbackProvider TileProvider, maxItems uint) *FallbackTileCache

func (*FallbackTileCache) GoRender

func (c *FallbackTileCache) GoRender()

GoRender is called by NewFallbackTileCache and renders tiles from the request queue and stores them in the cache

func (*FallbackTileCache) RenderTile

func (c *FallbackTileCache) RenderTile(t Tile) image.Image

RenderTile returns an image from Cache, or if not found requests it from the TileProvider and returns it

func (*FallbackTileCache) RenderTileRange

func (c *FallbackTileCache) RenderTileRange(a Tile, b Tile) []TileImage

Renders all tiles in the requested range and returns them This returns TileImages instead of merely images because the items are returned in an indeterminate order use the Tile to determine their position. a and b should be on the same zoom level

func (*FallbackTileCache) UsedFallback

func (c *FallbackTileCache) UsedFallback() bool

type FallbackTileProvider

type FallbackTileProvider interface {
	AdvancedTileProvider

	UsedFallback() bool
}

type LatLon

type LatLon struct {
	Lat float64
	Lon float64
}

type OSMTileMapper

type OSMTileMapper struct {
	TileSize uint
}

func (OSMTileMapper) BoundsFromTiles

func (o OSMTileMapper) BoundsFromTiles(a Tile, b Tile) (LatLon, LatLon)

func (OSMTileMapper) LatLon

func (o OSMTileMapper) LatLon(t Tile) LatLon

Calculates the lat/lon of the upper-left point of the given OSM Tile

func (OSMTileMapper) Tile

func (o OSMTileMapper) Tile(l LatLon, zoomLevel uint) Tile

Calculates the appropriate OSM Tile position that, at the given zoomLevel, contains the given lat/lon.

func (OSMTileMapper) TilesFromBounds

func (o OSMTileMapper) TilesFromBounds(a LatLon, b LatLon, maxWidth uint, maxHeight uint) (Tile, Tile)

type OSMTileProvider

type OSMTileProvider struct {
	ServerURL string
	// contains filtered or unexported fields
}

func NewOSMTileProvider

func NewOSMTileProvider(ServerURL string) *OSMTileProvider

func (*OSMTileProvider) RenderTile

func (o *OSMTileProvider) RenderTile(t Tile) image.Image

type StreamingTileCache

type StreamingTileCache struct {
	TileCache
}

StreamingTileCache just wraps the TileCache and implements the StreamingTileProvider interface, which return a channel and sends Tiles down it as they are rendered instead of waiting for a complete tile set.

func NewStreamingTileCache

func NewStreamingTileCache(provider TileProvider, maxItems uint) *StreamingTileCache

func (*StreamingTileCache) StreamTileRange

func (c *StreamingTileCache) StreamTileRange(a Tile, b Tile) chan TileImage

Renders all tiles in the requested range and returns them This returns TileImages instead of merely images because the items are returned in an indeterminate order use the Tile to determine their position. a and b should be on the same zoom level

type StreamingTileProvider

type StreamingTileProvider interface {
	TileProvider

	StreamTileRange(a Tile, b Tile) chan TileImage
}

type TestTileProvider

type TestTileProvider struct {
	Width  int
	Height int
}

func NewTestTileProvider

func NewTestTileProvider(width, height int) *TestTileProvider

func (*TestTileProvider) RenderTile

func (p *TestTileProvider) RenderTile(t Tile) image.Image

type Tile

type Tile struct {
	X uint
	Y uint
	Z uint
}

func ShiftToBottomRight

func ShiftToBottomRight(t Tile) Tile

func (Tile) CompareTo

func (t Tile) CompareTo(a Tile) int

func (Tile) GetChildTile

func (t Tile) GetChildTile(left bool, top bool) Tile

func (Tile) GetParentTile

func (t Tile) GetParentTile() Tile

func (Tile) IsInside

func (t Tile) IsInside(a Tile, b Tile) bool

type TileCache

type TileCache struct {
	// contains filtered or unexported fields
}

TileCache provides a fixed size LRU cache for Tiles that calls a supplied TileProvider when necessary, and handles maintaining the cache, freshening accessed tiles and expiring the Least Recently Used tiles as necessary.

func NewTileCache

func NewTileCache(provider TileProvider, maxItems uint) *TileCache

func (*TileCache) RenderTile

func (c *TileCache) RenderTile(t Tile) image.Image

RenderTile returns an image from Cache, or if not found requests it from the TileProvider and returns it

func (*TileCache) RenderTileRange

func (c *TileCache) RenderTileRange(a Tile, b Tile) []TileImage

Renders all tiles in the requested range and returns them This returns TileImages instead of merely images because the items are returned in an indeterminate order use the Tile to determine their position. a and b should be on the same zoom level

type TileImage

type TileImage struct {
	Tile Tile
	Img  image.Image
	// contains filtered or unexported fields
}

TileImage is a simple struct returned by Advanced and Streaming Tile Providers that wraps a Tile and an Image together since these methods return more than one tile. The populated flag allows identification of zero value structs.

func (TileImage) CompareTo

func (c TileImage) CompareTo(t Tile) int

type TileMapper

type TileMapper interface {
	LatLon(t Tile) LatLon
	Tile(l LatLon, Zoom uint) Tile
	TilesFromBounds(a LatLon, b LatLon, maxWidth uint, maxHeight uint) (Tile, Tile)
	BoundsFromTiles(a Tile, b Tile) (LatLon, LatLon)
}

type TileProvider

type TileProvider interface {
	RenderTile(t Tile) image.Image
}

type TileRenderModel

type TileRenderModel struct {
	rv.EmptyRenderModel

	RequestRender chan interface{}
	Rendering     bool
	NeedsRender   bool
	Img           image.Image
	// contains filtered or unexported fields
}

func NewTileRenderModel

func NewTileRenderModel(mapper TileMapper, provider TileProvider, leftTop LatLon, bottomRight LatLon) *TileRenderModel

func (*TileRenderModel) GoRender

func (m *TileRenderModel) GoRender()

func (*TileRenderModel) InnerRender

func (m *TileRenderModel) InnerRender()

func (*TileRenderModel) Render

func (m *TileRenderModel) Render() image.Image

func (*TileRenderModel) Start

func (m *TileRenderModel) Start()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL