slippy

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2022 License: MIT Imports: 13 Imported by: 1

README

Slippy GoDoc

Draw OpenStreetMap tiles in pixel

m := slippy.New(slippy.Options{
	Zoom:   10,
	Center: slippy.C(43.174366, -79.231511),
	Bounds: win.Bounds(),
})

for !win.Closed() {
	m.FetchAsync()
	m.Draw(win, pixel.IM)
	win.Update()
}

Documentation

Index

Constants

View Source
const (
	MaxZ         = 23
	MinLat       = -85.05112878
	MaxLat       = 85.05112878
	MinLon       = -180
	MaxLon       = 180
	EarthRadiusM = 6378137
	TileSize     = 256
)

Earth Parameters

Variables

View Source
var UserAgent = "Slippy/Go-Test"

Functions

func BlankTile

func BlankTile() image.Image

func FetchImage

func FetchImage(url string) (image.Image, error)

func V

func V(lat, lon float64, zoom int) pixel.Vec

V converts a lat lon into a vec

Types

type Coord

type Coord [2]float64

Coord is a simple struct for hold WGS-84 Lat Lon coordinates in degrees

func C

func C(lat, lon float64) Coord

C that have been clipped to Max/Min Lat/Lon This can be used as a constructor to assert bad values will be clipped

func FromVec

func FromVec(v pixel.Vec, zoom int) Coord

FromVec converts a vec into a coordinate

func (Coord) Lat

func (c Coord) Lat() float64

Lat returns the latitude

func (Coord) Lon

func (c Coord) Lon() float64

Lon returns the longitude

func (Coord) String

func (c Coord) String() string

String returns a string representation of the coordinate

func (Coord) Tile

func (c Coord) Tile(zoom int) Tile

Tile returns the tile which contains the coordinate

func (Coord) Vec

func (c Coord) Vec(zoom int) pixel.Vec

Vec gets the vec of the coord at the zoom level

type ImageTile

type ImageTile struct {
	Tile
	Sprite *pixel.Sprite
	Frame  pixel.Rect
	Loaded bool
}

func NewImageTile

func NewImageTile(t Tile, bounds pixel.Rect) ImageTile

func (ImageTile) Draw

func (t ImageTile) Draw(tg pixel.Target, m pixel.Matrix)

func (*ImageTile) Fetch

func (t *ImageTile) Fetch() error

func (ImageTile) Offset

func (t ImageTile) Offset() pixel.Vec

func (*ImageTile) SetPicture

func (t *ImageTile) SetPicture(pic *pixel.PictureData)

type Loader

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

func NewLoader

func NewLoader() *Loader

func (*Loader) Cancel

func (p *Loader) Cancel()

func (*Loader) Fetch

func (p *Loader) Fetch(t Tile) (*pixel.PictureData, error)

func (*Loader) Picture

func (l *Loader) Picture(t Tile) (*pixel.PictureData, bool)

func (*Loader) Prefetch

func (l *Loader) Prefetch(t Tile)

type Map

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

Map draws a slippy map onto a pixel target

func New

func New(opts Options) *Map

New creates a new map instance

func (*Map) Bounds

func (m *Map) Bounds() pixel.Rect

Bounds returns the map view bounds

func (*Map) Center

func (m *Map) Center() Coord

Center returns the coordinate of the center of the map

func (*Map) CenterVec

func (m *Map) CenterVec() pixel.Vec

CenterVec returns the vec that corresponds to the coordinate of the center of the map

func (*Map) Coord

func (m *Map) Coord(v pixel.Vec) Coord

Coord returns the pixels coordinate assuming the camera is at 0,0 and the map was drawn with the identify matrix

func (*Map) Draw

func (m *Map) Draw(tg pixel.Target, mt pixel.Matrix)

func (*Map) FetchAsync

func (m *Map) FetchAsync()

FetchAsync

func (*Map) FetchSync

func (m *Map) FetchSync() error

FetchSync the tile imagery

func (*Map) Push

func (m *Map) Push(p Pusher, coords ...Coord)

Push is a convinience method for pushing coordinates into an imdraw.IMDraw

func (*Map) SetBounds

func (m *Map) SetBounds(bounds pixel.Rect)

SetBounds sets the map view bounds

func (*Map) SetCenter

func (m *Map) SetCenter(center Coord)

SetCenter sets the center of the map to the provided coordinate

func (*Map) SetCenterVec

func (m *Map) SetCenterVec(center pixel.Vec)

SetCenterVec sets the center of the map view to the coordinate which corresponds to the provided vec

func (*Map) SetOptions

func (m *Map) SetOptions(opts Options)

SetOptions updates the map options

func (*Map) SetZoom

func (m *Map) SetZoom(zoom int)

SetZoom sets the zoom level

func (*Map) Vec

func (m *Map) Vec(c Coord) pixel.Vec

Vec returns the coordinate's pixel assuming the camera is at 0,0 and the map was drawn with the identify matrix

func (*Map) Visible

func (m *Map) Visible(c Coord) bool

Visible checks if a coordinate is contained withing the currently visible map view

func (*Map) Zoom

func (m *Map) Zoom() int

Zoom returns the zoom level

type Options

type Options struct {
	Center Coord
	Zoom   int
	Bounds pixel.Rect
}

Options contains configuration options for a map

type Pusher

type Pusher interface {
	Push(pts ...pixel.Vec)
}

type Tile

type Tile struct {
	X, Y, Z int
}

Tile is a simple struct for holding the XYZ coordinates for use in mapping

func (Tile) Rect

func (t Tile) Rect() pixel.Rect

Rect returns a rectangle of the tile

func (Tile) String

func (t Tile) String() string

String returns the string representation of the tile

func (Tile) Vec

func (t Tile) Vec() pixel.Vec

Vec returns a vector for the bottom left corner of the tile

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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