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 ¶
- type DrawCache
- type MapView
- func (m *MapView) Camera() *camera.Camera
- func (m *MapView) Children() []widget.Widget
- func (m *MapView) Draw(_ widget.Context, canvas widget.Canvas)
- func (m *MapView) Event(_ widget.Context, e event.Event) bool
- func (m *MapView) GestureHitTest(_ geometry.Point) []gesture.Recognizer
- func (m *MapView) IsViewportClip() bool
- func (m *MapView) Layout(_ widget.Context, c geometry.Constraints) geometry.Size
- func (m *MapView) LocalToWorld(p geometry.Point) geometry.Point
- func (m *MapView) Mount(_ widget.Context)
- func (m *MapView) OnPointer(fn func(local, world geometry.Point)) *MapView
- func (m *MapView) Overview() *MapView
- func (m *MapView) Unmount()
- func (m *MapView) WorldToLocal(p geometry.Point) geometry.Point
- func (m *MapView) ZoomRange(min, max float32) *MapView
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 ¶
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) Draw ¶
Draw clips to its bounds, then draws the visible portion of the map scaled according to the camera.
func (*MapView) Event ¶
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 ¶
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 ¶
LocalToWorld converts a point in this widget's local pixels to world coordinates (image-pixel space).
func (*MapView) OnPointer ¶
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 ¶
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 ¶
WorldToLocal converts a world point to this widget's local pixels.