Documentation
¶
Overview ¶
Package maps provides configuration types and HTTP handlers for web maps using Leaflet and Protomaps.
Index ¶
- Constants
- func AssignMapConfigHandler(opts *AssignMapConfigHandlerOptions, mux *http.ServeMux, map_cfg_uri string) error
- func MapConfigHandler(cfg *MapConfig) http.Handler
- func ProtomapsFileHandlerFromPath(path string, prefix string) (string, http.Handler, error)
- type AssignMapConfigHandlerOptions
- type InitialBounds
- type InitialView
- type LeafletConfig
- type LeafletStyle
- type MapConfig
- type ProtomapsConfig
Constants ¶
const LEAFLET_OSM_TILE_URL = "https://tile.openstreetmap.org/{z}/{x}/{y}.png"
LEAFLET_OSM_TILE_URL is the URL template for OpenStreetMap's standard raster tile layer.
const PROTOMAPS_API_TILE_URL = "https://api.protomaps.com/tiles/v3/{z}/{x}/{y}.mvt?key={key}"
PROTOMAPS_API_TILE_URL is the URL template for the Protomaps hosted tiles API, where "{key}" is replaced by an API key.
Variables ¶
This section is empty.
Functions ¶
func AssignMapConfigHandler ¶
func AssignMapConfigHandler(opts *AssignMapConfigHandlerOptions, mux *http.ServeMux, map_cfg_uri string) error
AssignMapConfigHandler derives a new `MapConfig` and corresponding `http.Handler` instance from 'opts' and assigns it to 'mux' at 'map_cfg_uri'. If the config has a custom tile handler it is also assigned to 'mux' at the config's tile URL.
func MapConfigHandler ¶
MapConfigHandler returns a new `http.Handler` that will return a JSON-encoded version of 'cfg'.
func ProtomapsFileHandlerFromPath ¶
ProtomapsFileHandlerFromPath takes a path and creates a http.FileServer handler instance for the files in its root directory. The handler is returned with a relative URI for the filename in 'path' to be assigned to a net/http ServeMux instance. If 'prefix' is not empty it is stripped from request paths and prepended to the returned URI.
Types ¶
type AssignMapConfigHandlerOptions ¶
type AssignMapConfigHandlerOptions struct {
// A string label indicating the map provider to use. Valid options are: leaflet, protomaps.
MapProvider string
// A valid Leaflet tile layer URI.
MapTileURI string
// A comma-separated string indicating the map's initial view. Valid options are: 'LON,LAT', 'LON,LAT,ZOOM' or 'MINX,MINY,MAXX,MAXY'.
InitialView string
// A custom Leaflet style definition for geometries. This may either be a JSON-encoded string or a path on disk.
LeafletStyle string
// A custom Leaflet style definition for points. This may either be a JSON-encoded string or a path on disk.
LeafletPointStyle string
// Zero or more (GeoJSON Feature) properties to use to construct a label for a feature's popup menu when it is clicked on.
LeafletLabelProperties []string
// A dictionary defining Leaflet label pane names and their z-index values.
LeafletPanes map[string]int
// A valid Protomaps theme label.
ProtomapsTheme string
// ProtomapsMaxDataZoom is the maximum zoom (tile) level for data in a PMTiles database.
ProtomapsMaxDataZoom int
}
AssignMapConfigHandlerOptions defines configuration options for the `AssignMapConfigHandler` and `MapConfigFromOptions` functions.
type InitialBounds ¶
type InitialBounds [4]float64
InitialBounds is the initial (minx, miny, maxx, maxy) bounding box of a map.
func (*InitialBounds) String ¶
func (v *InitialBounds) String() string
String returns the bounds as a comma-separated "minx,miny,maxx,maxy" string.
type InitialView ¶
type InitialView [2]float64
InitialView is the initial (longitude, latitude) centre point of a map.
func (*InitialView) String ¶
func (v *InitialView) String() string
String returns the view as a comma-separated "lon,lat" string.
type LeafletConfig ¶
type LeafletConfig struct {
// A `LeafletStyle` instance used to style geometries
Style *LeafletStyle `json:"style,omitempty"`
// A `LeafletStyle` instance used to style Point geometries
PointStyle *LeafletStyle `json:"point_style,omitempty"`
// Zero or more (GeoJSON Feature) properties to use to construct a label for a feature's popup menu when it is clicked on.
LabelProperties []string `json:"label_properties,omitempty"`
// A dictionary defining Leaflet label pane names and their z-index values.
Panes map[string]int `json:"panes,omitempty"`
}
LeafletConfig defines configuration details for maps using Leaflet.
type LeafletStyle ¶
type LeafletStyle struct {
// Color is the stroke colour.
Color string `json:"color,omitempty"`
// FillColor is the fill colour.
FillColor string `json:"fillColor,omitempty"`
// Weight is the stroke width in pixels.
Weight float64 `json:"weight,omitempty"`
// Opacity is the stroke opacity.
Opacity float64 `json:"opacity,omitempty"`
// Radius is the radius of point markers.
Radius float64 `json:"radius,omitempty"`
// FillOpacity is the fill opacity.
FillOpacity float64 `json:"fillOpacity,omitempty"`
// Custom flags for runtime style configuration
Custom any `json:"custom,omitempty"`
}
LeafletStyle is a struct containing details for decorating GeoJSON features and markers.
func UnmarshalLeafletStyle ¶
func UnmarshalLeafletStyle(raw string) (*LeafletStyle, error)
UnmarshalLeafletStyle derives a `LeafletStyle` instance from 'raw'. If 'raw' starts with "{" then it is treated as a JSON-encoded string, otherwise it is treated as a local path on disk.
func UnmarshalStyleFromReader ¶
func UnmarshalStyleFromReader(r io.Reader) (*LeafletStyle, error)
UnmarshalStyleFromReader derives a `LeafletStyle` instance from the body of 'r'.
func UnmarshalStyleFromString ¶
func UnmarshalStyleFromString(raw string) (*LeafletStyle, error)
UnmarshalStyleFromString derives a `LeafletStyle` instance from 'raw'.
type MapConfig ¶
type MapConfig struct {
// A valid map provider label.
Provider string `json:"provider"`
// A valid Leaflet tile layer URI.
TileURL string `json:"tile_url"`
// A custom http.Handler to use with `TileURL`. Used for PMTiles-based tiles.
TileURLHandler http.Handler `json:"tile_url_handler,omitempty"`
// Optional Protomaps configuration details
Protomaps *ProtomapsConfig `json:"protomaps,omitempty"`
// Optional Leaflet configuration details
Leaflet *LeafletConfig `json:"leaflet,omitempty"`
// The initial view (lon, lat) for the map (optional).
InitialView *InitialView `json:"initial_view,omitempty"`
// The initial zoom level for the map (optional).
InitialZoom int `json:"initial_zoom,omitempty"`
// The initial bounds (minx, miny, maxx, maxy) for the map (optional).
InitialBounds *InitialBounds `json:"initial_bounds,omitempty"`
}
MapConfig defines common configuration details for maps.
func MapConfigFromOptions ¶
func MapConfigFromOptions(opts *AssignMapConfigHandlerOptions) (*MapConfig, error)
MapConfigFromOptions derives a new `MapConfig` instance from 'opts'.
type ProtomapsConfig ¶
type ProtomapsConfig struct {
// A valid Protomaps theme label
Theme string `json:"theme"`
// MaxDataZoom is the maximum zoom (tile) level for data in a PMTiles database
MaxDataZoom int `json:"max_data_zoom,omitempty"`
// PaintRules are optional custom Protomaps paint rules.
PaintRules []map[string]any `json:"paintRules"`
// LabelRules are optional custom Protomaps label rules.
LabelRules []map[string]any `json:"labelRules"`
}
ProtomapsConfig defines configuration details for maps using Protomaps.




