mapview

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 39 Imported by: 0

README

Map

A vector map you can pan, zoom and search, with markers and GPX/GeoJSON tracks. It needs no web view and is sized for phones. It runs on Linux and Android and needs OpenGL ES 3.

import "code.rbel.co/rubiojr/fade/components/mapview"

Use it in a Fade window

package main

import (
    "log"

    "fyne.io/fyne/v2"
    "fyne.io/fyne/v2/app"
    "fyne.io/fyne/v2/container"
    "fyne.io/fyne/v2/layout"

    "code.rbel.co/rubiojr/fade/components/mapview"
    "code.rbel.co/rubiojr/fade/components/mapview/oms"
    "code.rbel.co/rubiojr/fade/components/window"
    "code.rbel.co/rubiojr/fade/style"
)

func main() {
    a := app.NewWithID("com.example.places")
    a.Settings().SetTheme(style.NewTheme())

    server, err := oms.New("https://oms.rbel.co", oms.Options{
        Store: mapview.Keep(a, 256<<20),
    })
    if err != nil {
        log.Fatal(err)
    }
    madrid := mapview.Position{Latitude: 40.4168, Longitude: -3.7038, Zoom: 12}
    m := mapview.New(server, mapview.Options{Start: madrid})

    controls := mapview.NewControls(m)
    controls.SetHome(madrid)
    over := container.NewBorder(nil,
        container.NewHBox(mapview.NewNotice(m), layout.NewSpacer(), controls),
        nil, nil)

    w := window.New(a, "Places")
    w.SetContent(container.NewStack(m, container.New(layout.NewCustomPaddedLayout(12, 48, 12, 12), over)))
    w.SetOnClosed(m.Close)
    w.Resize(fyne.NewSize(420, 800))
    w.ShowAndRun()
}

Drag to pan. Pinch, scroll or double tap to zoom. Tap the map, then use the arrow keys and +/-. A map let go while it moves coasts to rest, and a zoom moves through the levels to its own.

Pinch needs a touch screen and Wayland. The zoom follows the fingers and settles on the nearest quarter level when they lift.

Create, use and close a map on Fyne's UI goroutine. Close it when its window or page goes away: a map holds its memory until then.

examples/mapdemo is a complete application with search, an Add bookmark button and a saved-bookmark list.

Parts

Part Job
Map The map. MoveTo, ZoomBy and PanBy change what it shows; Center reads it
Controls Zoom in, zoom out and, after SetHome, a home button. Add puts your own buttons above them
Notice A spinner while the map starts, waits for a busy server or tries again after a failure; the problem when part of the view could not be drawn. Tell shows a message of your own there for a while
SearchBox A search field on one surface. It searches when the user pauses or presses Return
Panel A card for your own controls. Pointer input on it doesn't move the map

A search box reports what to search for; the search is yours:

box := mapview.NewSearchBox("Search places")
box.OnSearch = func(text string) { go find(text) }
box.OnCleared = hideResults

A panel pads its content by 12 px. Set Padding to zero for content that is a card itself, such as a boxed list of results.

Buttons added to the controls look like the zoom buttons. Give them an icon and no text:

locate := button.NewIcon(icons.Raw("mark-location"), showMe)
controls.Add(locate)

OnMoved and OnStatus report changes. Locate converts latitude and longitude to a position in the widget; CoordinateAt does the reverse.

The map shows its attribution in small print in the bottom right corner. CreditHeight tells how much room it takes, so your controls can stay above it. To show Attribution somewhere else, set Options.NoCredit.

Markers and bookmarks

Use Marker for places, bookmarks or waypoints. Markers follow the map and stay the same size as you zoom. Labels are optional; long labels are shortened.

err := m.SetMarkers(
    mapview.Marker{Latitude: 40.4138, Longitude: -3.6921, Label: "Prado"},
    mapview.Marker{Latitude: 40.4153, Longitude: -3.6844, Label: "Retiro"},
)
if err != nil {
    return err
}
m.OnMarkerTapped = func(index int) { showPlace(index) }

SetMarkers replaces the markers; m.SetMarkers() clears them. The callback receives the marker's index in that order. For overlapping markers, the last marker is on top and is picked first. With no marker callback, taps go to OnTapped.

To drop a marker with a tap:

m.OnTapped = func(at mapview.Coordinate) {
    if err := m.SetMarkers(mapview.Marker{
        Latitude: at.Latitude, Longitude: at.Longitude, Label: "Bookmark",
    }); err != nil {
        showError(err)
    }
}

Keep a slice in your application to accumulate bookmarks, edit them or save them between sessions. Set Marker.Color to override the theme's accent. The default Shape is mapview.Dot. Use Shape: mapview.Pin for a teardrop whose tip points to the coordinate, useful for bookmarks and waypoints.

Your position

SetHere draws where the device is: a dot, in a halo as wide as the accuracy when that is wider than the dot. Feed it from your location source, such as gogps:

for fix := range session.Fixes() {
    fyne.Do(func() {
        m.SetHere(mapview.Here{Latitude: fix.Latitude, Longitude: fix.Longitude, Accuracy: fix.Accuracy})
    })
}

SetFollowing(true) keeps the position in the middle of the map as it moves. Dragging the map or calling MoveTo ends that, zooming doesn't; OnFollowing reports both, for a button that shows the state. ClearHere takes the position off the map.

Tracks and files

Read GPX or GeoJSON from an io.Reader, then apply the returned features:

features, err := mapview.ReadGPX(reader) // or mapview.ReadGeoJSON(reader)
if err != nil {
    return err
}
if err := m.SetFeatures(features); err != nil {
    return err
}

The readers can run in a worker goroutine; apply the result on the UI goroutine with fyne.Do. They leave closing the reader to you. SetFeatures replaces both markers and tracks. It leaves the map's position and zoom alone.

  • GPX: waypoints become markers; routes and tracks become tracks. Names and separate track segments are preserved. Elevation, times and extensions are ignored.
  • GeoJSON: Point/MultiPoint become markers; LineString/MultiLineString become tracks. Feature, FeatureCollection and GeometryCollection are supported. A string properties.name supplies a label or name. Coordinates use GeoJSON's [longitude, latitude] order; extra ordinates are ignored. Null feature geometries are skipped; unsupported geometries, including polygons, return an error.

You can also supply coordinates directly:

err := m.SetTracks(mapview.Track{
    Name: "Walk",
    Segments: [][]mapview.Coordinate{{
        {Latitude: 40.4138, Longitude: -3.6921},
        {Latitude: 40.4153, Longitude: -3.6844},
    }},
    Width: 4,
})
if err != nil {
    return err
}

SetTracks replaces only tracks; m.SetTracks() clears them. Each segment is a separate line; segments with fewer than two points draw nothing. Set Color to override the accent and Width for a stroke of 0–64 logical units (0 uses 4). Track names are metadata, not map labels. Tracks draw below markers and attribution.

Setters copy their input and reject invalid data without changing the map. The limits are 1,000 markers, 1,000 tracks, 10,000 segments and 100,000 track points; names and labels may contain up to 4,096 bytes. Readers accept files up to 16 MiB; GeoJSON allows 32 nested levels and 10,000 objects. Coordinates must be finite, with latitude in −90…90 and longitude in −180…180; the view clips polar latitudes to Web Mercator's range (about ±85.05°).

Map data

oms.Client reads vector tiles, fonts and place search from an OMS server:

places, err := server.Search(ctx, "gas station", &oms.Near{Latitude: 40.74, Longitude: -4.06}, 6)

Search uses the network. Call it from a goroutine and return to the UI with fyne.Do.

Downloads are kept in a store.Store. mapview.Keep picks a directory in the user's cache for your application. store.OpenDir and store.NewMemory give you the choice, and anything with Get and Put works as a store. Set oms.Options.Offline to use stored data only.

Another tile server works through source.Source: three methods that return OpenMapTiles vector tiles and SDF glyphs. When the server asks to wait, return a source.BusyError with the time it gives: the map stops asking until then and loads the rest on its own.

Devices

A map sizes itself for the device it runs on. Its memory budgets follow the device's memory, and a view too big for them, a 4K screen at scale 1 say, is drawn with coarser tiles. On a phone or tablet the picture has narrower margins, tiles load without previews, and big pictures are antialiased with two samples rather than four, which phone GPUs draw many times slower.

mapview.MemoryLimit() is a soft limit for the whole program that leaves the map room:

debug.SetMemoryLimit(mapview.MemoryLimit())

Requirements

The map is drawn with OpenGL ES 3 and runs on Linux and Android. Building an application with a map needs cgo and the EGL development library (mesa-libEGL-devel on Fedora, libegl-dev on Debian, mesa-dev on Alpine). On Android the NDK has it; build with -tags egl, and a PKG_CONFIG that answers nothing, since the OpenGL bindings ask pkg-config for a library the NDK links anyway.

On a device without a driver for it, the map shows a message in place of its picture and Map.Status() reports mapview.Unavailable.

Limits

  • Linux and Android only.
  • One style, OpenFreeMap Liberty, in its light colors. It doesn't follow the dark scheme.
  • North is up. There is no rotation or tilt.
  • Labels in Latin script only.
  • No routing or track editing. Supply paths with SetTracks, GPX or GeoJSON.

Documentation

Overview

Package mapview is a map widget: a vector map that is panned by dragging and zoomed by scrolling, double tapping or the keyboard.

The map uses the OpenFreeMap Liberty style and is drawn with OpenGL ES 3, on Linux and Android. It needs no web view and no network access beyond its data, and it is sized to run on phones. On a device that cannot draw it, the map says so in place of its picture.

A Map reads vector tiles and glyphs from a source.Source. oms.Client is one, for an oms server; it keeps what it downloads in a store.Store, so a map that was seen once opens without a network. Controls, Notice, SearchBox and Panel are Fade surfaces to lay over a map.

SetMarkers and SetTracks add places and paths that follow the view. ReadGPX and ReadGeoJSON read waypoints and tracks into Features for SetFeatures. OnTapped reports coordinates for placing a marker interactively.

See README.md in this directory for an example.

Index

Constants

View Source
const PanelPadding = style.Gap12

PanelPadding is the space NewPanel leaves between a panel's edge and its content.

View Source
const (

	// SearchPause is how long a search box waits for the next key before it
	// searches.
	SearchPause = 300 * time.Millisecond
)

Search box geometry: a search entry without a frame of its own, on one opaque surface with the card's corners and shadow.

Variables

This section is empty.

Functions

func Keep

func Keep(a fyne.App, maximumBytes int64) store.Store

Keep returns a store for an application's map data of at most maximumBytes: a directory named map in the user's cache directory for the application, or where there is none, as on phones, in the application's own storage. Without a directory that works the data is kept in memory, up to 32 MiB, while the application runs.

func MemoryLimit added in v0.12.2

func MemoryLimit() int64

MemoryLimit is a soft limit for runtime/debug.SetMemoryLimit that leaves a map what it may need on this device.

Types

type Controls

type Controls struct {
	widget.BaseWidget

	ZoomIn, ZoomOut, Home *button.Button
	// contains filtered or unexported fields
}

Controls are the buttons of a map: zoom in, zoom out and, once SetHome was called, back to that position. They are circular buttons in a column, to be laid over a corner of the map, each on a surface of its own that keeps it legible over any map. A button that cannot do anything, such as zoom in at the closest zoom, is disabled. Add puts buttons of the application's own above them.

func NewControls

func NewControls(m *Map) *Controls

NewControls creates the controls of a map.

func (*Controls) Add added in v0.8.0

func (c *Controls) Add(buttons ...*button.Button)

Add puts buttons above the zoom buttons, in the order given and below any added before, each on a surface like theirs. They become circular and flat: give them an icon and no text. Enabling them is up to you.

func (*Controls) CreateRenderer

func (c *Controls) CreateRenderer() fyne.WidgetRenderer

func (*Controls) SetHome

func (c *Controls) SetHome(p Position)

SetHome shows a button that returns the map to a position.

type Coordinate added in v0.6.0

type Coordinate struct {
	Latitude, Longitude float64
}

Coordinate is a WGS84 latitude and longitude in degrees.

type Features added in v0.6.0

type Features struct {
	Markers []Marker
	Tracks  []Track
}

Features holds a map's markers and tracks, including those read from a file. Applications own their data; Map setters take a copy. A map accepts up to 1,000 markers, 1,000 tracks, 10,000 segments and 100,000 track coordinates. Labels and names may contain up to 4,096 bytes each.

func ReadGPX added in v0.6.0

func ReadGPX(r io.Reader) (Features, error)

ReadGPX reads GPX waypoints, routes and tracks. Track segment breaks and names are preserved; elevation, times and extensions are ignored. It accepts at most 16 MiB and the same feature limits as SetFeatures. It can run off the UI goroutine and does not close r. An error returns no partial features.

func ReadGeoJSON added in v0.6.0

func ReadGeoJSON(r io.Reader) (Features, error)

ReadGeoJSON reads Point, MultiPoint, LineString and MultiLineString geometries, including Feature, FeatureCollection and GeometryCollection wrappers. A string properties.name supplies a marker label or track name. Null feature geometries are skipped; unsupported geometries return an error. Coordinates are GeoJSON's [longitude, latitude] order; extra ordinates are ignored.

It accepts at most 16 MiB, 32 levels of nesting and the same feature limits as SetFeatures. It can run off the UI goroutine and does not close r. An error returns no partial features.

type Here added in v0.12.0

type Here struct {
	Latitude, Longitude float64
	// Accuracy is the radius in metres of the circle the device is believed
	// to be in, zero when unknown.
	Accuracy float64
}

Here is where the device is, as its location service reports it.

type Map

type Map struct {
	widget.BaseWidget

	// OnMoved reports every change of the position.
	OnMoved func(Position)
	// OnFollowing reports the map starting or ceasing to follow the
	// device's position; see SetFollowing.
	OnFollowing func(bool)
	// OnStatus reports every change of the status.
	OnStatus func(Status)
	// OnTapped reports a single tap in geographic coordinates. A handled marker
	// tap calls OnMarkerTapped instead. Double taps still zoom.
	OnTapped func(Coordinate)
	// OnMarkerTapped reports the index of a tapped marker in SetMarkers order.
	OnMarkerTapped func(int)
	// Observer is optional.
	Observer Observer
	// contains filtered or unexported fields
}

Map shows a map that can be dragged and zoomed. Drag to pan; pinch, scroll, double tap or use the plus and minus keys to zoom; the arrow keys pan.

The widget never draws the base map itself. It shows the engine's latest picture, which is larger than the widget, and answers a drag by moving that picture: one textured rectangle for the GPU. A picture that shows something new fades in over the one before. Markers are placed for the current view. Tracks are a picture of their own, larger than the widget too, that a drag moves and that is drawn again beside the user interface. While a drag lasts it asks for drafts, which are coarse and quick, before the picture on screen runs out; when the drag ends it asks for a full picture.

A flick crosses a draft's whole margin in the time the draft takes to arrive. Drafts are therefore asked for ahead of the finger: centred where the view will be when they arrive, judged from the speed of the drag and from how long the last drafts took. A map let go while it moves coasts on and slows down, asking for drafts as under a finger.

A pinch magnifies or reduces the picture on screen and passes through every zoom on its way. Pictures are drawn for zoom steps only, so the zoom settles on the nearest step when the fingers are lifted. A double tap, the scroll wheel, the keys and the controls move through the zooms to theirs as well.

A draft is as sharp as a full picture. A pinch, or a zoom on its way, gets drafts of its own zoom as fast as they can be drawn, so the map and its labels keep their sizes. Only a fast drag gets coarser ones.

Create, use and close a map on the Fyne goroutine.

func New

func New(from source.Source, options Options) *Map

New shows the data of a source, for example an oms.Client. The map starts reading at once and draws when it has a size. Close it when its window closes.

func (*Map) Attribution

func (m *Map) Attribution() string

Attribution credits the authors of the map's data. It is empty until the map has started. Show it with the map.

func (*Map) Center

func (m *Map) Center() Position

Center returns the position at the centre of the map.

func (*Map) ClearHere added in v0.12.0

func (m *Map) ClearHere()

ClearHere takes the position off the map and stops following it.

func (*Map) Close

func (m *Map) Close()

Close stops the map and frees its memory. A closed map keeps its last picture and draws no more.

func (*Map) CoordinateAt added in v0.6.0

func (m *Map) CoordinateAt(at fyne.Position) Coordinate

CoordinateAt returns the place at a position relative to the map's top left. It is the inverse of Locate, within the Web Mercator latitude range.

func (*Map) CreateRenderer

func (m *Map) CreateRenderer() fyne.WidgetRenderer

func (*Map) CreditHeight

func (m *Map) CreditHeight() float32

CreditHeight is the room the attribution takes at the bottom of the map, so that controls laid over the map can stay clear of it.

func (*Map) DoubleTapped

func (m *Map) DoubleTapped(event *fyne.PointEvent)

func (*Map) DragEnd

func (m *Map) DragEnd()

func (*Map) Dragged

func (m *Map) Dragged(event *fyne.DragEvent)

func (*Map) FocusGained

func (m *Map) FocusGained()

func (*Map) FocusLost

func (m *Map) FocusLost()

func (*Map) Following added in v0.12.0

func (m *Map) Following() bool

Following reports whether the map follows the device's position.

func (*Map) Locate

func (m *Map) Locate(latitude, longitude float64) fyne.Position

Locate returns where a place shows, relative to the map's top left corner. The place may lie outside the map. Use it with OnMoved to keep something of the application's on its place. Built-in markers follow the map themselves.

func (*Map) MouseDown added in v0.3.0

func (m *Map) MouseDown(*desktop.MouseEvent)

MouseDown follows the fingers, if one of them pressed. A press stops a map that coasts.

func (*Map) MouseUp added in v0.3.0

func (m *Map) MouseUp(*desktop.MouseEvent)

func (*Map) MoveTo

func (m *Map) MoveTo(p Position)

MoveTo shows another position. A map following the device's position stops following it.

func (*Map) PanBy

func (m *Map) PanBy(dx, dy float64)

PanBy moves the content by logical units: a positive dx moves the map to the right.

func (*Map) Retry

func (m *Map) Retry()

Retry asks again at once for what failed: for the tiles of an incomplete view, or for the source of a map that could not start. A map does both by itself after a wait; call Retry when there is reason to expect better, as when the network comes back.

func (*Map) Scrolled

func (m *Map) Scrolled(event *fyne.ScrollEvent)

func (*Map) SetFeatures added in v0.6.0

func (m *Map) SetFeatures(features Features) error

SetFeatures replaces all markers and tracks. Empty Features clears them. Invalid input leaves the map unchanged. It does not move or zoom the map.

func (*Map) SetFollowing added in v0.12.0

func (m *Map) SetFollowing(on bool)

SetFollowing keeps the device's position in the middle of the map as it moves, from the next SetHere or at once when the position is known. Following ends when the user drags the map or the application calls MoveTo; zooming keeps it. OnFollowing reports both.

func (*Map) SetHere added in v0.12.0

func (m *Map) SetHere(h Here)

SetHere shows where the device is: a dot, in a halo as wide as the accuracy when that is wider than the dot. A map that follows the position moves there.

func (*Map) SetMarkers added in v0.6.0

func (m *Map) SetMarkers(markers ...Marker) error

SetMarkers replaces the markers, leaving tracks alone. No arguments clears the markers. OnMarkerTapped reports an index in this order, with the last marker on top. Invalid input leaves the map unchanged.

func (*Map) SetTracks added in v0.6.0

func (m *Map) SetTracks(tracks ...Track) error

SetTracks replaces the tracks, leaving markers alone. No arguments clears the tracks. Invalid input leaves the map unchanged.

func (*Map) Status

func (m *Map) Status() Status

Status returns the state of the map.

func (*Map) Tapped

func (m *Map) Tapped(event *fyne.PointEvent)

Tapped gives the map the keyboard and reports the place or marker tapped.

func (*Map) Telemetry

func (m *Map) Telemetry() (engine.Telemetry, bool)

Telemetry reports the engine's work so far. It reports false before the map has started and after it was closed. It may be called from any goroutine.

func (*Map) TypedKey

func (m *Map) TypedKey(event *fyne.KeyEvent)

TypedKey pans with the arrow keys and zooms with plus and minus.

func (*Map) TypedRune

func (m *Map) TypedRune(rune)

func (*Map) View

func (m *Map) View() engine.View

View returns the region the widget shows, in the engine's terms.

func (*Map) ZoomBy

func (m *Map) ZoomBy(levels float64)

ZoomBy changes the zoom by levels around the centre of the widget, at once.

type Marker added in v0.6.0

type Marker struct {
	Latitude, Longitude float64
	Label               string
	Color               color.Color
	Shape               MarkerShape
}

Marker marks a place, bookmark or waypoint. Label is optional. A nil Color uses the theme's accent. Markers keep their size when the map zooms.

type MarkerShape added in v0.6.0

type MarkerShape int

MarkerShape is the appearance and geographic anchor of a marker.

const (
	// Dot is a circle centered on the coordinate and is the default shape.
	Dot MarkerShape = iota
	// Pin is a teardrop whose tip points to the coordinate.
	Pin
)

type Notice

type Notice struct {
	widget.BaseWidget

	Message, Detail *label.Label
	// contains filtered or unexported fields
}

Notice says what a map is waiting for and what went wrong, on a panel to be laid over the map. While the map starts, waits for a busy server or tries again after it could not start, it shows a spinner. When a view stayed incomplete it names the problem. Otherwise it is hidden: a map that the device cannot draw says so itself. Tell shows a message of the application's in the same place.

func NewNotice

func NewNotice(m *Map) *Notice

NewNotice creates the notice of a map.

func (*Notice) CreateRenderer

func (n *Notice) CreateRenderer() fyne.WidgetRenderer

func (*Notice) MinSize

func (n *Notice) MinSize() fyne.Size

MinSize is that of the panel, so a hidden part takes no room.

func (*Notice) Tell added in v0.12.0

func (n *Notice) Tell(message, detail string, d time.Duration)

Tell shows a message of the application's, with a detail or none, in place of what the map's status calls for: that something it does with the map went wrong, say. It stays for d, or until Tell is called again; a zero d keeps it until Tell("", "", 0) takes it away. Call it on the Fyne goroutine.

type Observer

type Observer interface {
	// Reported: the engine's loading state changed.
	Reported(status engine.Status)
	// Requested: the widget asked the engine for a view, as a draft when
	// moving is true.
	Requested(view engine.View, scale float64, moving bool)
	// Presented: a picture went on screen.
	Presented(picture engine.Picture)
	// Dragged: one drag event moved the picture. slack is how far the widget
	// is from the nearest edge of the picture; negative means it shows past it.
	Dragged(slack float64)
	DragEnded()
}

Observer is told what a map does, for measurement. Every method runs on the Fyne goroutine and must return quickly.

type Options

type Options struct {
	Start Position
	// NoCredit leaves the attribution off the map, for an application that
	// shows Map.Attribution somewhere else.
	NoCredit bool
}

Options configure a map. The zero value opens on the whole world. A map sizes itself for the device it runs on.

type Panel

type Panel struct {
	widget.BaseWidget
	// Padding is the space between the panel's edge and its content. Set it
	// to zero for content that is a card itself, such as a boxed list, so
	// that it shows one frame and not two.
	Padding float32
	// contains filtered or unexported fields
}

Panel is an opaque surface for controls laid over a map, such as a search field. It looks like a card: popover background, 12 px corners and the card shadow. Pointer input on it stays with it and does not move the map beneath. The shadow extends beyond the panel, so leave room around it.

func NewPanel

func NewPanel(content fyne.CanvasObject) *Panel

NewPanel wraps content in a panel.

func (*Panel) CreateRenderer

func (p *Panel) CreateRenderer() fyne.WidgetRenderer

func (*Panel) DoubleTapped

func (*Panel) DoubleTapped(*fyne.PointEvent)

func (*Panel) DragEnd

func (*Panel) DragEnd()

func (*Panel) Dragged

func (*Panel) Dragged(*fyne.DragEvent)

func (*Panel) MouseDown

func (*Panel) MouseDown(*desktop.MouseEvent)

func (*Panel) MouseUp

func (*Panel) MouseUp(*desktop.MouseEvent)

func (*Panel) Scrolled

func (*Panel) Scrolled(*fyne.ScrollEvent)

func (*Panel) Tapped

func (*Panel) Tapped(*fyne.PointEvent)

type Position

type Position struct {
	Latitude, Longitude float64
	Zoom                float64
}

Position is a place and how closely it is seen. Zoom runs from engine.MinZoom, the whole world, to engine.MaxZoom, a street.

type SearchBox struct {
	widget.BaseWidget

	// Entry is the field inside the box, for its text and placeholder. The
	// box owns its callbacks.
	Entry *entry.Entry
	// OnSearch receives the text without surrounding space, on the Fyne
	// goroutine. It must not block: search in a goroutine.
	OnSearch func(text string)
	// OnCleared runs when the text becomes empty.
	OnCleared func()
	// Pause is the wait for the next key. Zero means SearchPause.
	Pause time.Duration
	// contains filtered or unexported fields
}

SearchBox is a search field to lay over a map. It is one surface, legible over any map, with a search icon, the text and a button that clears it. Pointer input on it does not reach the map beneath.

It searches while the user types: OnSearch runs when the user pauses or presses Return, and OnCleared when the text is emptied.

func NewSearchBox added in v0.2.2

func NewSearchBox(placeholder string) *SearchBox

NewSearchBox creates a search box with a placeholder.

func (*SearchBox) Cancel added in v0.2.2

func (s *SearchBox) Cancel()

Cancel drops a search that was waiting for a pause. Call it when the box goes away.

func (*SearchBox) CreateRenderer added in v0.2.2

func (s *SearchBox) CreateRenderer() fyne.WidgetRenderer

func (*SearchBox) DoubleTapped added in v0.2.2

func (*SearchBox) DoubleTapped(*fyne.PointEvent)

func (*SearchBox) DragEnd added in v0.2.2

func (*SearchBox) DragEnd()

func (*SearchBox) Dragged added in v0.2.2

func (*SearchBox) Dragged(*fyne.DragEvent)

func (*SearchBox) MouseDown added in v0.2.2

func (*SearchBox) MouseDown(*desktop.MouseEvent)

func (*SearchBox) MouseUp added in v0.2.2

func (*SearchBox) MouseUp(*desktop.MouseEvent)

func (*SearchBox) Scrolled added in v0.2.2

func (*SearchBox) Scrolled(*fyne.ScrollEvent)

func (*SearchBox) Tapped added in v0.2.2

func (s *SearchBox) Tapped(*fyne.PointEvent)

Tapped moves the keyboard to the field, also from the box's edge.

func (*SearchBox) Text added in v0.2.2

func (s *SearchBox) Text() string

Text returns the text without surrounding space.

type State

type State int

State says how far a map is.

const (
	// Starting: the map is reading its source. Nothing is drawn yet.
	Starting State = iota
	// Loading: the view is being drawn and may still change.
	Loading
	// Ready: the view is complete.
	Ready
	// Incomplete: part of the view could not be drawn. Tiles that failed to
	// load are asked for again by themselves.
	Incomplete
	// Failed: the map could not start. It tries again by itself.
	Failed
	// Waiting: the server asked to wait. Loading resumes by itself.
	Waiting
	// Unavailable: the device cannot draw the map. The map says so itself,
	// in place of its picture.
	Unavailable
)

type Status

type Status struct {
	State   State
	Problem string
}

Status is the state of a map and, when something went wrong, what.

type Track added in v0.6.0

type Track struct {
	Name     string
	Segments [][]Coordinate
	// Color defaults to the theme's accent. Width is in logical units;
	// zero uses 4. Valid widths run from 0 to 64.
	Color color.Color
	Width float32
}

Track is a line with optional breaks. Each segment is drawn separately; successive coordinates within a segment are joined by the shortest path across the date line. Name is descriptive and is not drawn on the map.

Directories

Path Synopsis
Package engine turns a map view into pictures.
Package engine turns a map view into pictures.
Package gpu renders vecmap scenes with OpenGL ES 3 in an offscreen context.
Package gpu renders vecmap scenes with OpenGL ES 3 in an offscreen context.
Package oms reads map data from an oms server: vector tiles, glyphs and place search.
Package oms reads map data from an oms server: vector tiles, glyphs and place search.
Package render defines the image output shared by map renderers.
Package render defines the image output shared by map renderers.
Package source describes where a map gets its data.
Package source describes where a map gets its data.
Package store keeps downloaded map data, such as tiles and fonts, so a map opens quickly and works without a network.
Package store keeps downloaded map data, such as tiles and fonts, so a map opens quickly and works without a network.

Jump to

Keyboard shortcuts

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