mapview

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package mapview provides a pannable/zoomable image widget for displaying large maps inside a viewport. It owns a camera.Camera and uses CPU scaling to draw the visible sub-region of the source image.

This is a UI widget — it does not touch wgpu or the GPU render pipeline. For GPU-accelerated vector rendering (polygons, polylines), see the render package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DrawCache

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

DrawCache draws an image through a camera onto a widget.Canvas, scaling only the visible sub-region on the CPU (the toolkit Canvas only supports translation, not scaling). The scaled output and source sub-region buffers are reused between frames so panning — which keeps the destination size constant — does not allocate every frame.

func (*DrawCache) Draw

func (c *DrawCache) Draw(canvas widget.Canvas, src image.Image, cam *camera.Camera, vp geometry.Size)

Draw renders the portion of src visible through cam into vp-sized local pixels on canvas. It clips nothing itself; the caller is expected to have already clipped to the widget bounds.

type MapView

type MapView struct {
	widget.WidgetBase
	// contains filtered or unexported fields
}

MapView is a GUI widget that displays a large map image inside a viewport and lets the user pan (left-drag) and zoom (mouse wheel, toward the cursor). It is deliberately small: it is just a widget that owns a camera.Camera and uses it to draw an ui.ImageAsset. It is not a general camera framework, and it knows nothing about countries, provinces, units or any other map content.

Typical use:

mapImage, _ := app.Images().Load("assets/world.png")
root := ui.Row(sidePanel, mapview.New(mapImage))

func New

func New(asset *ui.ImageAsset) *MapView

New creates a pannable/zoomable map widget for the given asset. The asset must be loaded via ImageManager.Load; the widget never performs I/O.

func (*MapView) Camera

func (m *MapView) Camera() *camera.Camera

Camera returns the camera driving this view. It is exposed so callers can read or drive the view programmatically (e.g. center on a location).

func (*MapView) Children

func (m *MapView) Children() []widget.Widget

Children: leaf widget.

func (*MapView) Draw

func (m *MapView) Draw(_ widget.Context, canvas widget.Canvas)

Draw clips to its bounds, then draws the visible portion of the map scaled according to the camera.

func (*MapView) Event

func (m *MapView) Event(_ widget.Context, e event.Event) bool

Event handles the mouse wheel to zoom toward the cursor. Pointer drags are handled by the gesture DragRecognizer (see GestureHitTest), not here.

func (*MapView) GestureHitTest

func (m *MapView) GestureHitTest(_ geometry.Point) []gesture.Recognizer

GestureHitTest reports a pan drag recognizer so the map can be dragged with the left mouse button. MapView is a leaf, so it always claims the pointer.

func (*MapView) IsViewportClip

func (m *MapView) IsViewportClip() bool

IsViewportClip tells the dirty-region collector to use this widget's bounds as the dirty region and not recurse into the (potentially huge) content.

func (*MapView) Layout

Layout fills the allotted space (a viewport wants to be as large as it is given) and, on first layout, establishes an initial overview of the map.

func (*MapView) LocalToWorld

func (m *MapView) LocalToWorld(p geometry.Point) geometry.Point

LocalToWorld converts a point in this widget's local pixels to world coordinates (image-pixel space).

func (*MapView) Mount

func (m *MapView) Mount(_ widget.Context)

Mount registers the widget as an active user of its asset.

func (*MapView) OnPointer

func (m *MapView) OnPointer(fn func(local, world geometry.Point)) *MapView

OnPointer registers a callback invoked with the pointer position over the map, expressed both in widget-local pixels and in world (map) coordinates. It fires on hover and during drag. It is optional and intended for diagnostics/overlays (the coordinate-conversion hook from the design).

func (*MapView) Overview

func (m *MapView) Overview() *MapView

Overview re-centers the camera on the map and picks a zoom that shows the whole map (the same initial behavior as first layout).

func (*MapView) Unmount

func (m *MapView) Unmount()

Unmount unregisters the widget, freeing the asset for release when no other users remain.

func (*MapView) WorldToLocal

func (m *MapView) WorldToLocal(p geometry.Point) geometry.Point

WorldToLocal converts a world point to this widget's local pixels.

func (*MapView) ZoomRange

func (m *MapView) ZoomRange(min, max float32) *MapView

ZoomRange overrides the allowed zoom limits for this map.

Jump to

Keyboard shortcuts

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