Documentation ¶
Overview ¶
Package sm (~ static maps) renders static map images from OSM tiles with markers, paths, and filled areas.
Index ¶
- func CanDisplay(pos s2.LatLng) bool
- func CreateBBox(nwlat float64, nwlng float64, selat float64, selng float64) (*s2.Rect, error)
- func GetTileProviders() map[string]*TileProvider
- func Luminance(col color.Color) float64
- func ParseColorString(s string) (color.Color, error)
- type Area
- type Circle
- type Context
- func (m *Context) AddArea(area *Area)
- func (m *Context) AddCircle(circle *Circle)
- func (m *Context) AddCustomObject(object MapObject)
- func (m *Context) AddMarker(marker *Marker)
- func (m *Context) AddOverlay(overlay *TileProvider)
- func (m *Context) AddPath(path *Path)
- func (m *Context) ClearAreas()
- func (m *Context) ClearCircles()
- func (m *Context) ClearCustomObjects()
- func (m *Context) ClearMarkers()
- func (m *Context) ClearOverlays()
- func (m *Context) ClearPaths()
- func (m *Context) DetermineBounds() s2.Rect
- func (m *Context) OverrideAttribution(attribution string)
- func (m *Context) Render() (image.Image, error)
- func (m *Context) RenderWithBounds() (image.Image, s2.Rect, error)
- func (m *Context) RenderWithTransformer() (image.Image, *Transformer, error)
- func (m *Context) SetBackground(col color.Color)
- func (m *Context) SetBoundingBox(bbox s2.Rect)
- func (m *Context) SetCache(cache TileCache)
- func (m *Context) SetCenter(center s2.LatLng)
- func (m *Context) SetSize(width, height int)
- func (m *Context) SetTileProvider(t *TileProvider)
- func (m *Context) SetUserAgent(a string)
- func (m *Context) SetZoom(zoom int)
- func (m *Context) Transformer() (*Transformer, error)
- type MapObject
- type Marker
- type Path
- type TileCache
- type TileCacheStaticPath
- type TileFetcher
- type TileProvider
- func NewTileProviderArcgisWorldImagery() *TileProvider
- func NewTileProviderCartoDark() *TileProvider
- func NewTileProviderCartoLight() *TileProvider
- func NewTileProviderOpenCycleMap() *TileProvider
- func NewTileProviderOpenStreetMaps() *TileProvider
- func NewTileProviderOpenTopoMap() *TileProvider
- func NewTileProviderStamenTerrain() *TileProvider
- func NewTileProviderStamenToner() *TileProvider
- func NewTileProviderThunderforestLandscape() *TileProvider
- func NewTileProviderThunderforestOutdoors() *TileProvider
- func NewTileProviderThunderforestTransport() *TileProvider
- func NewTileProviderWikimedia() *TileProvider
- type Transformer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CanDisplay ¶
CanDisplay checks if pos is generally displayable (i.e. its latitude is in [-85,85])
func CreateBBox ¶
CreateBBox creates a bounding box from a north-western point (lat/lng in degrees) and a south-eastern point (lat/lng in degrees). Note that you can create a bounding box wrapping over the antimeridian at lng=+-/180° by nwlng > selng.
func GetTileProviders ¶
func GetTileProviders() map[string]*TileProvider
GetTileProviders returns a map of all available TileProviders
Types ¶
type Area ¶
type Area struct { MapObject Positions []s2.LatLng Color color.Color Fill color.Color Weight float64 }
Area represents a area or area on the map
func ParseAreaString ¶
ParseAreaString parses a string and returns an area
func (*Area) ExtraMarginPixels ¶
type Circle ¶
type Circle struct { MapObject Position s2.LatLng Color color.Color Fill color.Color Weight float64 Radius float64 // in m. }
Circle represents a circle on the map
func ParseCircleString ¶
ParseCircleString parses a string and returns an array of circles
func (*Circle) ExtraMarginPixels ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context holds all information about the map image that is to be rendered
func (*Context) AddCustomObject ¶
AddCustomObject adds a custom object to the Context
func (*Context) AddOverlay ¶
func (m *Context) AddOverlay(overlay *TileProvider)
AddOverlay adds an overlay to the Context
func (*Context) ClearAreas ¶
func (m *Context) ClearAreas()
ClearAreas removes all areas from the Context
func (*Context) ClearCircles ¶
func (m *Context) ClearCircles()
ClearCircles removes all circles from the Context
func (*Context) ClearCustomObjects ¶
func (m *Context) ClearCustomObjects()
ClearCustomObjects removes all custom objects from the Context
func (*Context) ClearMarkers ¶
func (m *Context) ClearMarkers()
ClearMarkers removes all markers from the Context
func (*Context) ClearOverlays ¶
func (m *Context) ClearOverlays()
ClearOverlays removes all overlays from the Context
func (*Context) ClearPaths ¶
func (m *Context) ClearPaths()
ClearPaths removes all paths from the Context
func (*Context) DetermineBounds ¶
func (*Context) OverrideAttribution ¶
OverrideAttribution sets a custom attribution string (or none if empty)
Pay attention you might be violating the terms of usage for the selected map provider - only use the function if you are aware of this!
func (*Context) Render ¶
Render actually renders the map image including all map objects (markers, paths, areas)
func (*Context) RenderWithBounds ¶
RenderWithBounds actually renders the map image including all map objects (markers, paths, areas). The returned image covers requested area as well as any tiles necessary to cover that area, which may be larger than the request.
Specific bounding box of returned image is provided to support image registration with other data
func (*Context) RenderWithTransformer ¶
func (m *Context) RenderWithTransformer() (image.Image, *Transformer, error)
RenderWithTransformer actually renders the map image including all map objects (markers, paths, areas). The returned image covers requested area as well as any tiles necessary to cover that area, which may be larger than the request.
A Transformer is returned to support image registration with other data.
func (*Context) SetBackground ¶
SetBackground sets the background color (used as a fallback for areas without map tiles)
func (*Context) SetBoundingBox ¶
SetBoundingBox sets the bounding box
func (*Context) SetTileProvider ¶
func (m *Context) SetTileProvider(t *TileProvider)
SetTileProvider sets the TileProvider to be used
func (*Context) SetUserAgent ¶
SetUserAgent sets the HTTP user agent string used when downloading map tiles
func (*Context) Transformer ¶
func (m *Context) Transformer() (*Transformer, error)
Transformer returns an initialized Transformer instance.
type MapObject ¶
type MapObject interface { Bounds() s2.Rect ExtraMarginPixels() float64 Draw(dc *gg.Context, trans *Transformer) }
MapObject is the interface for all objects on the map
type Marker ¶
type Marker struct { MapObject Position s2.LatLng Color color.Color Size float64 Label string LabelColor color.Color }
Marker represents a marker on the map
func ParseMarkerString ¶
ParseMarkerString parses a string and returns an array of markers
func (*Marker) ExtraMarginPixels ¶
func (*Marker) SetLabelColor ¶
SetLabelColor sets the color of the marker's text label
type Path ¶
Path represents a path or area on the map
func ParsePathString ¶
ParsePathString parses a string and returns a path
func (*Path) ExtraMarginPixels ¶
type TileCache ¶
type TileCache interface { // Root path to store cached tiles in with no trailing slash. Path() string // Permission to set when creating missing cache directories. Perm() os.FileMode }
TileCache provides cache information to the tile fetcher
type TileCacheStaticPath ¶
type TileCacheStaticPath struct {
// contains filtered or unexported fields
}
TileCacheStaticPath provides a static path to the tile fetcher.
func NewTileCache ¶
func NewTileCache(rootPath string, perm os.FileMode) *TileCacheStaticPath
NewTileCache stores cache files in a static path.
func NewTileCacheFromUserCache ¶
func NewTileCacheFromUserCache(perm os.FileMode) *TileCacheStaticPath
NewTileCacheFromUserCache stores cache files in a user-specific cache directory.
func (*TileCacheStaticPath) Perm ¶
func (c *TileCacheStaticPath) Perm() os.FileMode
Perm instructs the permission to set when creating missing cache directories.
type TileFetcher ¶
type TileFetcher struct {
// contains filtered or unexported fields
}
TileFetcher downloads map tile images from a TileProvider
func NewTileFetcher ¶
func NewTileFetcher(tileProvider *TileProvider, cache TileCache) *TileFetcher
NewTileFetcher creates a new Tilefetcher struct
func (*TileFetcher) Fetch ¶
func (t *TileFetcher) Fetch(zoom, x, y int) (image.Image, error)
Fetch download (or retrieves from the cache) a tile image for the specified zoom level and tile coordinates
func (*TileFetcher) SetUserAgent ¶
func (t *TileFetcher) SetUserAgent(a string)
SetUserAgent sets the HTTP user agent string used when downloading map tiles
type TileProvider ¶
type TileProvider struct { Name string Attribution string IgnoreNotFound bool TileSize int URLPattern string // "%[1]s" => shard, "%[2]d" => zoom, "%[3]d" => x, "%[4]d" => y Shards []string }
TileProvider encapsulates all infos about a map tile provider service (name, url scheme, attribution, etc.)
func NewTileProviderArcgisWorldImagery ¶
func NewTileProviderArcgisWorldImagery() *TileProvider
NewTileProviderArcgisWorldImagery creates a TileProvider struct for Arcgis' WorldImagery tiles
func NewTileProviderCartoDark ¶
func NewTileProviderCartoDark() *TileProvider
NewTileProviderCartoDark creates a TileProvider struct for Carto's tile service (dark variant)
func NewTileProviderCartoLight ¶
func NewTileProviderCartoLight() *TileProvider
NewTileProviderCartoLight creates a TileProvider struct for Carto's tile service (light variant)
func NewTileProviderOpenCycleMap ¶
func NewTileProviderOpenCycleMap() *TileProvider
NewTileProviderOpenCycleMap creates a TileProvider struct for OpenCycleMap's tile service
func NewTileProviderOpenStreetMaps ¶
func NewTileProviderOpenStreetMaps() *TileProvider
NewTileProviderOpenStreetMaps creates a TileProvider struct for OSM's tile service
func NewTileProviderOpenTopoMap ¶
func NewTileProviderOpenTopoMap() *TileProvider
NewTileProviderOpenTopoMap creates a TileProvider struct for opentopomap's tile service
func NewTileProviderStamenTerrain ¶
func NewTileProviderStamenTerrain() *TileProvider
NewTileProviderStamenTerrain creates a TileProvider struct for stamens' 'terrain' tile service
func NewTileProviderStamenToner ¶
func NewTileProviderStamenToner() *TileProvider
NewTileProviderStamenToner creates a TileProvider struct for stamens' 'toner' tile service
func NewTileProviderThunderforestLandscape ¶
func NewTileProviderThunderforestLandscape() *TileProvider
NewTileProviderThunderforestLandscape creates a TileProvider struct for thundeforests's 'landscape' tile service
func NewTileProviderThunderforestOutdoors ¶
func NewTileProviderThunderforestOutdoors() *TileProvider
NewTileProviderThunderforestOutdoors creates a TileProvider struct for thundeforests's 'outdoors' tile service
func NewTileProviderThunderforestTransport ¶
func NewTileProviderThunderforestTransport() *TileProvider
NewTileProviderThunderforestTransport creates a TileProvider struct for thundeforests's 'transport' tile service
func NewTileProviderWikimedia ¶
func NewTileProviderWikimedia() *TileProvider
NewTileProviderWikimedia creates a TileProvider struct for Wikimedia's tile service
type Transformer ¶
type Transformer struct {
// contains filtered or unexported fields
}
Transformer implements coordinate transformation from latitude longitude to image pixel coordinates.
func (*Transformer) LatLngToXY ¶
func (t *Transformer) LatLngToXY(ll s2.LatLng) (float64, float64)
LatLngToXY transforms a latitude longitude pair into image x, y coordinates.
func (*Transformer) Rect ¶
func (t *Transformer) Rect() (bbox s2.Rect)
Rect returns an s2.Rect bounding box around the set of tiles described by Transformer.