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
- func Keep(a fyne.App, maximumBytes int64) store.Store
- func MemoryLimit() int64
- type Controls
- type Coordinate
- type Features
- type Here
- type Map
- func (m *Map) Attribution() string
- func (m *Map) Center() Position
- func (m *Map) ClearHere()
- func (m *Map) Close()
- func (m *Map) CoordinateAt(at fyne.Position) Coordinate
- func (m *Map) CreateRenderer() fyne.WidgetRenderer
- func (m *Map) CreditHeight() float32
- func (m *Map) DoubleTapped(event *fyne.PointEvent)
- func (m *Map) DragEnd()
- func (m *Map) Dragged(event *fyne.DragEvent)
- func (m *Map) FocusGained()
- func (m *Map) FocusLost()
- func (m *Map) Following() bool
- func (m *Map) Locate(latitude, longitude float64) fyne.Position
- func (m *Map) MouseDown(*desktop.MouseEvent)
- func (m *Map) MouseUp(*desktop.MouseEvent)
- func (m *Map) MoveTo(p Position)
- func (m *Map) PanBy(dx, dy float64)
- func (m *Map) Retry()
- func (m *Map) Scrolled(event *fyne.ScrollEvent)
- func (m *Map) SetFeatures(features Features) error
- func (m *Map) SetFollowing(on bool)
- func (m *Map) SetHere(h Here)
- func (m *Map) SetMarkers(markers ...Marker) error
- func (m *Map) SetTracks(tracks ...Track) error
- func (m *Map) Status() Status
- func (m *Map) Tapped(event *fyne.PointEvent)
- func (m *Map) Telemetry() (engine.Telemetry, bool)
- func (m *Map) TypedKey(event *fyne.KeyEvent)
- func (m *Map) TypedRune(rune)
- func (m *Map) View() engine.View
- func (m *Map) ZoomBy(levels float64)
- type Marker
- type MarkerShape
- type Notice
- type Observer
- type Options
- type Panel
- func (p *Panel) CreateRenderer() fyne.WidgetRenderer
- func (*Panel) DoubleTapped(*fyne.PointEvent)
- func (*Panel) DragEnd()
- func (*Panel) Dragged(*fyne.DragEvent)
- func (*Panel) MouseDown(*desktop.MouseEvent)
- func (*Panel) MouseUp(*desktop.MouseEvent)
- func (*Panel) Scrolled(*fyne.ScrollEvent)
- func (*Panel) Tapped(*fyne.PointEvent)
- type Position
- type SearchBox
- func (s *SearchBox) Cancel()
- func (s *SearchBox) CreateRenderer() fyne.WidgetRenderer
- func (*SearchBox) DoubleTapped(*fyne.PointEvent)
- func (*SearchBox) DragEnd()
- func (*SearchBox) Dragged(*fyne.DragEvent)
- func (*SearchBox) MouseDown(*desktop.MouseEvent)
- func (*SearchBox) MouseUp(*desktop.MouseEvent)
- func (*SearchBox) Scrolled(*fyne.ScrollEvent)
- func (s *SearchBox) Tapped(*fyne.PointEvent)
- func (s *SearchBox) Text() string
- type State
- type Status
- type Track
Constants ¶
const PanelPadding = style.Gap12
PanelPadding is the space NewPanel leaves between a panel's edge and its content.
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 ¶
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 (*Controls) Add ¶ added in v0.8.0
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
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
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
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
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 ¶
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 ¶
Attribution credits the authors of the map's data. It is empty until the map has started. Show it with 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 ¶
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) FocusGained ¶
func (m *Map) FocusGained()
func (*Map) Following ¶ added in v0.12.0
Following reports whether the map follows the device's position.
func (*Map) Locate ¶
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 ¶
MoveTo shows another position. A map following the device's position stops following it.
func (*Map) PanBy ¶
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
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
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
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
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
SetTracks replaces the tracks, leaving markers alone. No arguments clears the tracks. Invalid input leaves the map unchanged.
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 ¶
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.
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 (*Notice) CreateRenderer ¶
func (n *Notice) CreateRenderer() fyne.WidgetRenderer
func (*Notice) Tell ¶ added in v0.12.0
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 (*Panel) CreateRenderer ¶
func (p *Panel) CreateRenderer() fyne.WidgetRenderer
func (*Panel) DoubleTapped ¶
func (*Panel) DoubleTapped(*fyne.PointEvent)
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 ¶
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 ¶ added in v0.2.2
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
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) 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.
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 // in place of its picture. Unavailable )
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.
Source Files
¶
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. |