maps

package
v0.0.0-...-a4b7981 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 16 Imported by: 0

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

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

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

func LoadImage

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

LoadImage loads an image from a file

func LocationToTileID

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

LocationToTileID converts a lat/lon location into a tile ID

func MercatorLocationToPixel

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

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

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

func MercatorPixelToLocation

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

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

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

SaveImageJPG writes an image instance to a jpg file

func SaveImagePNG

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

SaveImagePNG writes an image instance to a png file

func TileIDToLocation

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

TileIDToLocation converts a tile ID to a lat/lon location

func WrapTileID

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

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

type DrawConfig struct {
	Vertical   Justify
	Horizontal Justify
}

DrawConfig configures image drawing

type FileCache

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

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

NewFileCache creates a new file cache instance

func (*FileCache) Fetch

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

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

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

Interpolate function to be passed to generic line interpolator

type Justify

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

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

func (*Maps) GetEnclosingTiles

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

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

func (m *Maps) SetCache(c Cache)

SetCache binds a cache into the map instance

type Tile

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

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

NewTile creates a tile with a base RGBA object

func StitchTiles

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

func (t *Tile) Clone() Tile

Clone helper clones a tile instance with a new base image

func (*Tile) DrawGlobalXY

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

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

DrawLine uses InterpolateLocations to draw a line between two points

func (*Tile) DrawLocalXY

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

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

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

func (*Tile) FlattenAltitudes

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

func (*Tile) GetAltitude

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

func (*Tile) GetHighestAltitude

func (t *Tile) GetHighestAltitude() float64

func (*Tile) InterpolateAltitudes

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

func (*Tile) InterpolateGlobalXY

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

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

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

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

LocationToPixel translates a global location to a pixel on the tile

func (*Tile) PixelToLocation

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