Documentation
¶
Overview ¶
Package tiletea provides a Bubble Tea component for rendering an interactive slippy map in the terminal using the Kitty graphics protocol.
Index ¶
- Constants
- type GeomView
- func NewGeomView(overlays []maprender.Overlay, opts ...Option) *GeomView
- func NewGeomViewFromGeoJSON(data []byte, opts ...Option) (*GeomView, error)
- func NewGeomViewFromGeometry(g geom.Geometry, opts ...Option) *GeomView
- func NewGeomViewFromWKB(wkb []byte, opts ...Option) (*GeomView, error)
- func NewGeomViewFromWKT(wkt string, opts ...Option) (*GeomView, error)
- type Map
- func (m *Map) Center() (lat, lng float64)
- func (m *Map) FitOverlays() tea.Cmd
- func (m *Map) Init() tea.Cmd
- func (m *Map) Refresh() tea.Cmd
- func (m *Map) SetClickCallback(fn func(lat, lng float64))
- func (m *Map) SetIncremental(enabled bool)
- func (m *Map) SetMarker(lat, lng *float64)
- func (m *Map) SetOverlays(overlays ...maprender.Overlay)
- func (m *Map) SetStatusExtra(s string)
- func (m *Map) Update(msg tea.Msg) (tea.Model, tea.Cmd)
- func (m *Map) View() tea.View
- func (m *Map) Zoom() int
- type Option
- func WithAltScreen(enabled bool) Option
- func WithClickCallback(fn func(lat, lng float64)) Option
- func WithFitOverlays() Option
- func WithLogger(logger *slog.Logger) Option
- func WithMarker(lat, lng float64) Option
- func WithOverlays(overlays ...maprender.Overlay) Option
- func WithSourceMaxZoom(maxZoom int) Option
- func WithStyle(style *maprender.MapStyle) Option
- func WithStyleURL(url string) Option
- func WithTileCache(dir string, ttl time.Duration) Option
- func WithTileSource(url string) Option
- func WithTileURLTemplate(template string) Option
- func WithZIndex(z int) Option
Constants ¶
const ( // DefaultStyleURL is the Mapbox GL style fetched when none is configured. DefaultStyleURL = "https://tiles.openfreemap.org/styles/liberty" // DefaultSourceURL is the TileJSON endpoint used to resolve the tile URL // template and source zoom range. DefaultSourceURL = "https://tiles.openfreemap.org/planet" // DefaultTileURLTemplate is used when the tile source cannot be resolved. DefaultTileURLTemplate = "https://tiles.openfreemap.org/planet/{z}/{x}/{y}.pbf" // MinZoom and MaxZoom bound the zoom level. MinZoom = 0 MaxZoom = 18 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GeomView ¶
type GeomView struct {
// contains filtered or unexported fields
}
GeomView is a Bubble Tea model that renders geometry on an interactive map, fitted to the geometry's bounds. It is a thin wrapper around Map that parses GeoJSON, WKT, WKB, or a geom.Geometry into overlays and centers the view on them.
func NewGeomView ¶
NewGeomView creates a map view fitted to the given overlays. The map is centered and zoomed to the combined bounds of the overlays on first render.
func NewGeomViewFromGeoJSON ¶
NewGeomViewFromGeoJSON parses GeoJSON (a Geometry, Feature, or FeatureCollection) and creates a map view fitted to it.
func NewGeomViewFromGeometry ¶
NewGeomViewFromGeometry creates a map view fitted to a geom.Geometry.
func NewGeomViewFromWKB ¶
NewGeomViewFromWKB parses a WKB byte slice and creates a map view fitted to it.
func NewGeomViewFromWKT ¶
NewGeomViewFromWKT parses a WKT string and creates a map view fitted to it.
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
Map is a Bubble Tea model that renders an interactive slippy map. It can be used standalone or embedded in a larger application.
The zero value is not usable; construct one with New.
func New ¶
New creates a map component centered at the given coordinates and zoom.
The map style and tile source are fetched synchronously on construction, falling back to built-in defaults when the network is unavailable.
func (*Map) FitOverlays ¶
FitOverlays recenters and rezooms the map to fit the current overlays. It returns a command that triggers the re-render, or nil when there are no overlays or the viewport size is not yet known.
func (*Map) Refresh ¶
Refresh returns a command that re-renders the map with the current state (center, zoom, marker, overlays). Use it after mutating the map externally, e.g. from a click callback.
func (*Map) SetClickCallback ¶
SetClickCallback sets or clears (nil) the click callback. See WithClickCallback.
func (*Map) SetIncremental ¶
SetIncremental enables or disables incremental rendering for pans. It is enabled by default.
func (*Map) SetMarker ¶
SetMarker sets the optional marker location. A nil lat or lng clears the marker.
func (*Map) SetOverlays ¶
SetOverlays replaces the geometry overlays drawn on top of the map. The overlays are applied on the next render.
func (*Map) SetStatusExtra ¶
SetStatusExtra sets an optional extra segment displayed at the end of the status line. An empty string removes it.
type Option ¶
type Option func(*Map)
Option configures a Map.
func WithAltScreen ¶
WithAltScreen enables or disables the alternate screen buffer. It is enabled by default.
func WithClickCallback ¶
WithClickCallback registers fn to be invoked with the WGS84 latitude and longitude whenever the user clicks (left button) on the map.
fn is called synchronously during the Map's Update, so it should be quick and non-blocking.
func WithFitOverlays ¶
func WithFitOverlays() Option
WithFitOverlays centers and zooms the map to fit the overlays on the first render. After the initial fit, the user can pan and zoom freely.
func WithLogger ¶
WithLogger sets the logger used for render and debug output. A nil logger is ignored.
func WithMarker ¶
WithMarker places a marker at the given coordinates.
func WithOverlays ¶
WithOverlays appends geometry overlays drawn on top of the map. Overlays are drawn in WGS84 (lon-lat) coordinates and accept GeoJSON/WKT/WKB-parsed geometry via the maprender.OverlayFrom* helpers.
func WithSourceMaxZoom ¶
WithSourceMaxZoom sets the source's maximum zoom, used for overzoom when a tile URL template is supplied directly.
func WithStyleURL ¶
WithStyleURL overrides the URL used to fetch the map style.
func WithTileCache ¶
WithTileCache configures the on-disk tile cache. An empty dir uses the default cache directory (~/.cache/maprender). A non-positive ttl disables expiry; a positive ttl expires entries older than ttl.
func WithTileSource ¶
WithTileSource overrides the TileJSON endpoint used to resolve the tile URL template.
func WithTileURLTemplate ¶
WithTileURLTemplate supplies the tile URL template directly, bypassing the TileJSON lookup. Use WithSourceMaxZoom to enable overzoom in this case.
func WithZIndex ¶
WithZIndex sets the Kitty graphics z-index used to draw the map image. Negative values draw the image under text (the default); z=0 draws it at the text layer so it covers previously drawn text.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
browse
command
Command browse renders an interactive terminal map, demonstrating the tiletea component.
|
Command browse renders an interactive terminal map, demonstrating the tiletea component. |
|
geom
command
Command geom renders an interactive terminal map fitted to a geometry overlay, demonstrating the tiletea.GeomView component.
|
Command geom renders an interactive terminal map fitted to a geometry overlay, demonstrating the tiletea.GeomView component. |
