tilemap

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TileSize is the size of map tiles in pixels
	TileSize = 256
	// MaxZoomLevel is the maximum zoom level supported
	MaxZoomLevel = 19
)
View Source
const PanSpeed = 50

PanSpeed in pixels per frame

Variables

This section is empty.

Functions

This section is empty.

Types

type PanDirection

type PanDirection int

PanDirection represents a direction to pan the map

const (
	PanLeft PanDirection = iota
	PanRight
	PanUp
	PanDown
)

type TileKey

type TileKey struct {
	Zoom int
	X    int
	Y    int
}

TileKey uniquely identifies a map tile

type TileMap

type TileMap struct {
	// View state
	CenterLat    float64
	CenterLon    float64
	Zoom         int
	ScreenWidth  int
	ScreenHeight int
	// contains filtered or unexported fields
}

TileMap manages the slippy map tile system

func New

func New(screenWidth, screenHeight int, lat, lon float64, zoom int) *TileMap

New creates a new TileMap instance

func (*TileMap) CalculateVisibleTileRange

func (tm *TileMap) CalculateVisibleTileRange() (TileRange, float64, float64)

CalculateVisibleTileRange determines which tiles are needed for the current view

func (*TileMap) Draw

func (tm *TileMap) Draw(screen *ebiten.Image, debugMode bool) TileRange

Draw renders the visible tiles to the screen

func (*TileMap) Pan

func (tm *TileMap) Pan(dir PanDirection)

Pan moves the map center in the specified direction by a fixed number of pixels

func (*TileMap) PanBy

func (tm *TileMap) PanBy(dx, dy float64)

PanBy moves the map by pixel offsets dx,dy are in screen pixels, positive dx moves map west (view east), positive dy moves map south (view north)

func (*TileMap) ScreenToWorld

func (tm *TileMap) ScreenToWorld(screenX, screenY float64) (tileX, tileY float64)

ScreenToWorld converts screen coordinates to tile coordinates

func (*TileMap) ZoomAtPoint

func (tm *TileMap) ZoomAtPoint(zoomIn bool, screenX, screenY float64)

ZoomAtPoint zooms the map while keeping the given world point at the same screen location

func (*TileMap) ZoomIn

func (tm *TileMap) ZoomIn()

ZoomIn increases the zoom level if not at max zoom

func (*TileMap) ZoomOut

func (tm *TileMap) ZoomOut()

ZoomOut decreases the zoom level if not at minimum zoom

type TileRange

type TileRange struct {
	MinX, MaxX int
	MinY, MaxY int
}

TileRange defines the range of tiles needed to cover the viewport

Jump to

Keyboard shortcuts

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