maps

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2020 License: MIT Imports: 16 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// D2R helper for converting degrees to radians
	D2R = math.Pi / 180
	// R2D helper for converting radians to degrees
	R2D = 180 / math.Pi
)
View Source
const (
	SizeStandard uint64 = 256
	SizeHighDPI  uint64 = 512
)

Variables

Center preconfigured centering helper

Functions

func GetEnclosingTileIDs added in v0.3.0

func GetEnclosingTileIDs(a, b base.Location, level uint64) (uint64, uint64, uint64, uint64)

GetEnclosingTileIDs fetches a pair of tile IDs enclosing the provided pair of points

func HeightToPixel added in v0.4.1

func HeightToPixel(alt float64) (uint8, uint8, uint8)

func LoadImage added in v0.3.0

func LoadImage(file string) (image.Image, *image.Config, error)

LoadImage loads an image from a file

func LocationToTileID added in v0.3.0

func LocationToTileID(loc base.Location, level uint64) (uint64, uint64)

LocationToTileID converts a lat/lon location into a tile ID

func MercatorLocationToPixel added in v0.4.1

func MercatorLocationToPixel(lat, lng float64, zoom, size uint64) (float64, float64)

MercatorLocationToPixel converts a lat/lng/zoom location (in degrees) to a pixel location in the global space

func MercatorLocationToTileID added in v0.4.1

func MercatorLocationToTileID(lat, lng float64, zoom, size uint64) (uint64, uint64)

MercatorLocationToTileID builds on MercatorLocationToPixel to fetch the TileID of a given location

func MercatorPixelToLocation added in v0.4.1

func MercatorPixelToLocation(x, y float64, zoom, size uint64) (float64, float64)

MercatorPixelToLocation converts a given (global) pixel location and zoom level to a lat and lng (in degrees)

func PixelToHeight added in v0.4.1

func PixelToHeight(r, g, b uint8) float64

PixelToHeight Converts a pixel to a height value for mapbox terrain tiles Equation from https://www.mapbox.com/blog/terrain-rgb/

func SaveImageJPG added in v0.3.0

func SaveImageJPG(img image.Image, file string) error

SaveImageJPG writes an image instance to a jpg file

func SaveImagePNG added in v0.3.0

func SaveImagePNG(img image.Image, file string) error

SaveImagePNG writes an image instance to a png file

func TileIDToLocation added in v0.3.0

func TileIDToLocation(x, y float64, level uint64) base.Location

TileIDToLocation converts a tile ID to a lat/lon location

func WrapTileID added in v0.3.0

func WrapTileID(x, y, level uint64) (uint64, uint64)

WrapTileID wraps tile IDs by level for api requests eg. Tile (X:16, Y:10, level:4 ) will become (X:0, Y:10, level:4)

Types

type Cache added in v0.3.0

type Cache interface {
	Save(mapID MapID, x, y, level uint64, format MapFormat, highDPI bool, img image.Image) error
	Fetch(mapID MapID, x, y, level uint64, format MapFormat, highDPI bool) (image.Image, *image.Config, error)
}

Cache interface defines an abstract tile cache This can be used to limit the number of API calls required to fetch previously fetched tiles

type DrawConfig added in v0.4.1

type DrawConfig struct {
	Vertical   Justify
	Horizontal Justify
}

DrawConfig configures image drawing

type FileCache added in v0.3.0

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

FileCache is a simple file-based caching implementation for map tiles This does not implement any mechanisms for deletion / removal, and as such is not suitable for production use

func NewFileCache added in v0.3.0

func NewFileCache(basePath string) (*FileCache, error)

NewFileCache creates a new file cache instance

func (*FileCache) Fetch added in v0.3.0

func (fc *FileCache) Fetch(mapID MapID, x, y, level uint64, format MapFormat, highDPI bool) (image.Image, *image.Config, error)

Fetch fetches an image from the file cache if possible

func (*FileCache) Save added in v0.3.0

func (fc *FileCache) Save(mapID MapID, x, y, level uint64, format MapFormat, highDPI bool, img image.Image) error

Save saves an image to the file cache

type Interpolate added in v0.4.1

type Interpolate func(pixel color.Color) color.Color

Interpolate function to be passed to generic line interpolator

type Justify added in v0.4.1

type Justify string

Justify sets image offsets for drawing

const (
	JustifyTop    Justify = "top"
	JustifyLeft   Justify = "left"
	JustifyCenter Justify = "center"
	JustifyBottom Justify = "bottom"
	JustifyRight  Justify = "right"
)

Constant justification types

type MapFormat

type MapFormat string

MapFormat specifies the format in which to return the map tiles

const (
	MapFormatPng        MapFormat = "png"    // true color PNG
	MapFormatPng32      MapFormat = "png32"  // 32 color indexed PNG
	MapFormatPng64      MapFormat = "png64"  // 64 color indexed PNG
	MapFormatPng128     MapFormat = "png128" // 128 color indexed PNG
	MapFormatPng256     MapFormat = "png256" // 256 color indexed PNG
	MapFormatPngRaw     MapFormat = "pngraw" // Raw PNG (only for MapIDTerrainRGB)
	MapFormatJpg70      MapFormat = "jpg70"  // 70% quality JPG
	MapFormatJpg80      MapFormat = "jpg80"  // 80% quality JPG
	MapFormatJpg90      MapFormat = "jpg90"  // 90% quality JPG
	MapFormatVectorTile MapFormat = "mvt"    // Vector Tile
)

Map formats

type MapID

type MapID string

MapID selects which map to fetch from the API

const (
	MapIDStreets          MapID = "mapbox.streets"
	MapIDLight            MapID = "mapbox.light"
	MapIDDark             MapID = "mapbox.dark"
	MapIDSatellite        MapID = "mapbox.satellite"
	MapIDStreetsSatellite MapID = "mapbox.streets-satellite"
	MapIDWheatpaste       MapID = "mapbox.wheatpaste"
	MapIDStreetsBasic     MapID = "mapbox.streets-basic"
	MapIDComic            MapID = "mapbox.comic"
	MapIDOutdoors         MapID = "mapbox.outdoors"
	MapIDRunBikeHike      MapID = "mapbox.run-bike-hike"
	MapIDPencil           MapID = "mapbox.pencil"
	MapIDPirates          MapID = "mapbox.pirates"
	MapIDEmerald          MapID = "mapbox.emerald"
	MapIDHighContrast     MapID = "mapbox.high-contrast"
	MapIDTerrainRGB       MapID = "mapbox.terrain-rgb"
)

Map IDs

type Maps

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

Maps api wrapper instance

func NewMaps

func NewMaps(base *base.Base) *Maps

NewMaps Create a new Maps API wrapper

func (*Maps) FastGetEnclosingTiles added in v0.4.1

func (m *Maps) FastGetEnclosingTiles(mapID MapID, a, b base.Location, level uint64, format MapFormat, highDPI bool) ([][]Tile, error)

func (*Maps) GetEnclosingTiles added in v0.3.0

func (m *Maps) GetEnclosingTiles(mapID MapID, a, b base.Location, level uint64, format MapFormat, highDPI bool) ([][]Tile, error)

GetEnclosingTiles fetches a 2d array of the tiles enclosing a given point

func (*Maps) GetTile added in v0.3.0

func (m *Maps) GetTile(mapID MapID, x, y, z uint64, format MapFormat, highDPI bool) (*Tile, error)

GetTile fetches the map tile for the specified location

func (*Maps) SetCache added in v0.3.0

func (m *Maps) SetCache(c Cache)

SetCache binds a cache into the map instance

type Tile added in v0.4.1

type Tile struct {
	draw.Image
	Level uint64 // Tile zoom level
	Size  uint64 // Tile size
	X, Y  uint64 // Tile X and Y postions (Web Mercurator projection)
}

Tile is a wrapper around an image that includes positioning data

func NewTile added in v0.4.1

func NewTile(x, y, level, size uint64, src image.Image) Tile

NewTile creates a tile with a base RGBA object

func StitchTiles added in v0.3.0

func StitchTiles(images [][]Tile) Tile

StitchTiles combines a 2d array of image tiles into a single larger image Note that all images must have the same dimensions for this to work

func (*Tile) Clone added in v0.4.3

func (t *Tile) Clone() Tile

Clone helper clones a tile instance with a new base image

func (*Tile) DrawGlobalXY added in v0.4.1

func (t *Tile) DrawGlobalXY(src image.Image, x, y int, config DrawConfig) error

DrawGlobalXY draws the provided image at the global X/Y coordinates

func (*Tile) DrawLine added in v0.4.1

func (t *Tile) DrawLine(loc1, loc2 base.Location, c color.Color)

DrawLine uses InterpolateLocations to draw a line between two points

func (*Tile) DrawLocalXY added in v0.4.1

func (t *Tile) DrawLocalXY(src image.Image, x, y int, config DrawConfig) error

DrawLocalXY draws the provided image at the local X/Y coordinates

func (*Tile) DrawLocation added in v0.4.1

func (t *Tile) DrawLocation(src image.Image, loc base.Location, config DrawConfig)

DrawLocation draws the provided image at the provided lat lng

func (*Tile) DrawPoint added in v0.4.1

func (t *Tile) DrawPoint(loc base.Location, size uint64, c color.Color) error

func (*Tile) FlattenAltitudes added in v0.4.1

func (t *Tile) FlattenAltitudes(maxHeight float64) Tile

func (*Tile) GetAltitude added in v0.4.1

func (t *Tile) GetAltitude(loc base.Location) (float64, error)

func (*Tile) GetHighestAltitude added in v0.4.1

func (t *Tile) GetHighestAltitude() float64

func (*Tile) InterpolateAltitudes added in v0.4.1

func (t *Tile) InterpolateAltitudes(loc1, loc2 base.Location) []float64

func (*Tile) InterpolateGlobalXY added in v0.4.1

func (t *Tile) InterpolateGlobalXY(x1, y1, x2, y2 int, interpolate Interpolate) error

InterpolateGlobalXY interpolates a line between two global points and calls the interpolate function on each point

func (*Tile) InterpolateLocalXY added in v0.4.1

func (t *Tile) InterpolateLocalXY(x1, y1, x2, y2 int, interpolate Interpolate)

InterpolateLocalXY interpolates a line between two local points and calls the interpolate function on each point

func (*Tile) InterpolateLocations added in v0.4.1

func (t *Tile) InterpolateLocations(loc1, loc2 base.Location, interpolate Interpolate) error

InterpolateLocations interpolates a line between two locations and calls the interpolate function on each point

func (*Tile) LocationToPixel added in v0.4.1

func (t *Tile) LocationToPixel(loc base.Location) (float64, float64, error)

LocationToPixel translates a global location to a pixel on the tile

func (*Tile) PixelToLocation added in v0.4.1

func (t *Tile) PixelToLocation(x, y float64) (*base.Location, error)

PixelToLocation translates a pixel location in the tile into a global location

Jump to

Keyboard shortcuts

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