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)
- func ParseLabelOffset(s string) (float64, error)
- type Area
- type Circle
- type Context
- func (m *Context) AddArea(area *Area)deprecated
- func (m *Context) AddCircle(circle *Circle)deprecated
- func (m *Context) AddMarker(marker *Marker)deprecated
- func (m *Context) AddObject(object MapObject)
- func (m *Context) AddOverlay(overlay *TileProvider)
- func (m *Context) AddPath(path *Path)deprecated
- func (m *Context) Attribution() string
- func (m *Context) ClearAreas()
- func (m *Context) ClearCircles()
- func (m *Context) ClearMarkers()
- func (m *Context) ClearObjects()
- func (m *Context) ClearOverlays()
- func (m *Context) ClearPaths()
- 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) SetMaxZoom(n int)
- func (m *Context) SetOnline(online bool)
- 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 ImageMarker
- func (m *ImageMarker) Bounds() s2.Rect
- func (m *ImageMarker) Draw(gc *gg.Context, trans *Transformer)
- func (m *ImageMarker) ExtraMarginPixels() (float64, float64, float64, float64)
- func (m *ImageMarker) SetImage(img image.Image)
- func (m *ImageMarker) SetOffsetX(offset float64)
- func (m *ImageMarker) SetOffsetY(offset float64)
- type MapObject
- type Marker
- type Path
- type Tile
- type TileCache
- type TileCacheStaticPath
- type TileFetcher
- type TileProvider
- func NewTileProviderArcgisWorldImagery() *TileProvider
- func NewTileProviderCartoDark() *TileProvider
- func NewTileProviderCartoLight() *TileProvider
- func NewTileProviderNone() *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
func Luminance ¶
Luminance computes the luminance (~ brightness) of the given color. Range: 0.0 for black to 1.0 for white.
func ParseColorString ¶
ParseColorString parses hex color strings (i.e. `0xRRGGBB`, `#RRGGBB`, `0xRRGGBBAA`, `#RRGGBBAA`), and names colors (e.g. 'black', 'blue', ...)
func ParseLabelOffset ¶
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) Bounds ¶
Bounds returns the geographical boundary rect (excluding the actual pixel dimensions).
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) Bounds ¶
Bounds returns the geographical boundary rect (excluding the actual pixel dimensions).
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) AddOverlay ¶
func (m *Context) AddOverlay(overlay *TileProvider)
AddOverlay adds an overlay to the Context
func (*Context) Attribution ¶
Attribution returns the current attribution string - either the overridden version (using OverrideAttribution) or the one set by the selected TileProvider.
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) ClearMarkers ¶
func (m *Context) ClearMarkers()
ClearMarkers removes all markers from the Context
func (*Context) ClearObjects ¶
func (m *Context) ClearObjects()
ClearObjects removes all objects 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) 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) SetMaxZoom ¶
SetMaxZoom sets the upper zoom level limit when using dynamic zoom
func (*Context) SetOnline ¶
SetOnline enables/disables online TileFetcher will only fetch tiles from cache if online = false
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 ImageMarker ¶
type ImageMarker struct { MapObject Position s2.LatLng Img image.Image OffsetX float64 OffsetY float64 }
ImageMarker represents an image marker on the map
func NewImageMarker ¶
NewImageMarker creates a new ImageMarker
func ParseImageMarkerString ¶
func ParseImageMarkerString(s string) ([]*ImageMarker, error)
ParseImageMarkerString parses a string and returns an array of image markers
func (*ImageMarker) Bounds ¶
func (m *ImageMarker) Bounds() s2.Rect
Bounds returns single point rect containing the marker's geographical position.
func (*ImageMarker) Draw ¶
func (m *ImageMarker) Draw(gc *gg.Context, trans *Transformer)
Draw draws the object in the given graphical context.
func (*ImageMarker) ExtraMarginPixels ¶
func (m *ImageMarker) ExtraMarginPixels() (float64, float64, float64, float64)
ExtraMarginPixels return the marker's left, top, right, bottom pixel extent.
func (*ImageMarker) SetImage ¶
func (m *ImageMarker) SetImage(img image.Image)
SetImage sets the marker's image
func (*ImageMarker) SetOffsetX ¶
func (m *ImageMarker) SetOffsetX(offset float64)
SetOffsetX sets the marker's x offset
func (*ImageMarker) SetOffsetY ¶
func (m *ImageMarker) SetOffsetY(offset float64)
SetOffsetY sets the marker's y offset
type MapObject ¶
type MapObject interface { // Bounds returns the geographical boundary rect (excluding the actual pixel dimensions). Bounds() s2.Rect // ExtraMarginPixels returns the left, top, right, bottom pixel margin of the object. ExtraMarginPixels() (float64, float64, float64, float64) // Draw draws the object in the given graphical context. 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 LabelXOffset float64 LabelYOffset float64 }
Marker represents a marker on the map
func ParseMarkerString ¶
ParseMarkerString parses a string and returns an array of markers
func (*Marker) Bounds ¶
Bounds returns single point rect containing the marker's geographical position.
func (*Marker) Draw ¶
func (m *Marker) Draw(gc *gg.Context, trans *Transformer)
Draw draws the object in the given graphical context.
func (*Marker) ExtraMarginPixels ¶
ExtraMarginPixels return the marker's left, top, right, bottom pixel extent.
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) Bounds ¶
Bounds returns the geographical boundary rect (excluding the actual pixel dimensions).
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, online bool) *TileFetcher
NewTileFetcher creates a new Tilefetcher struct
func (*TileFetcher) Fetch ¶
func (t *TileFetcher) Fetch(tile *Tile) 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 NewTileProviderNone ¶
func NewTileProviderNone() *TileProvider
NewTileProviderNone creates a TileProvider struct to omit background tiles entirely
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.
func (*Transformer) XYToLatLng ¶
func (t *Transformer) XYToLatLng(x float64, y float64) s2.LatLng
XYToLatLng transforms image x, y coordinates to a latitude longitude pair.