maps

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: BSD-3-Clause Imports: 11 Imported by: 4

README

go-http-maps

Go package providing opinionated HTTP middleware for web-based map tiles.

Important

This is work in progress. Documentation is incomplete.

Until then have a look at app/server/server.go, templates/html/map.html and static/javascript/aaronland.map.init.js for an example of working code.

tools

server

An example HTTP server demonstrating the use of the go-http-maps package.

$> ./bin/server -h
  -initial-latitude float
    	The starting latitude to position the map at. (default 37.61799)
  -initial-longitude float
    	The start longitude to position the map at. (default -122.370943)
  -initial-zoom int
    	The starting zoom level to position the map at. (default 12)
  -leaflet-enable-draw
    	Enable the Leaflet.Draw plugin.
  -leaflet-enable-fullscreen
    	Enable the Leaflet.Fullscreen plugin.
  -leaflet-enable-hash
    	Enable the Leaflet.Hash plugin. (default true)
  -leaflet-tile-url string
    	A valid Leaflet 'tileLayer' layer URL. Only necessary if -map-provider is "leaflet".
  -map-provider string
    	The name of the map provider to use. Valid options are: leaflet, protomaps, tangram
  -nextzen-apikey string
    	A valid Nextzen API key. Only necessary if -map-provider is "tangram".
  -nextzen-style-url string
    	A valid URL for loading a Tangram.js style bundle. Only necessary if -map-provider is "tangram". (default "/tangram/refill-style.zip")
  -nextzen-tile-url string
    	A valid Nextzen tile URL template for loading map tiles. Only necessary if -map-provider is "tangram". (default "https://tile.nextzen.org/tilezen/vector/v1/512/all/{z}/{x}/{y}.mvt")
  -protomaps-bucket-uri string
    	The gocloud.dev/blob.Bucket URI where Protomaps tiles are stored. Only necessary if -map-provider is "protomaps" and -protomaps-serve-tiles is true.
  -protomaps-caches-size int
    	The size of the internal Protomaps cache if serving tiles locally. Only necessary if -map-provider is "protomaps" and -protomaps-serve-tiles is true. (default 64)
  -protomaps-database string
    	The name of the Protomaps database to serve tiles from. Only necessary if -map-provider is "protomaps" and -protomaps-serve-tiles is true.
  -protomaps-label-rules-uri gocloud.dev/runtimevar
    	// An optional gocloud.dev/runtimevar URI referencing a custom Javascript variable used to define Protomaps label rules.
  -protomaps-paint-rules-uri gocloud.dev/runtimevar
    	// An optional gocloud.dev/runtimevar URI referencing a custom Javascript variable used to define Protomaps paint rules.
  -protomaps-serve-tiles
    	A boolean flag signaling whether to serve Protomaps tiles locally. Only necessary if -map-provider is "protomaps".
  -protomaps-tile-url string
    	A valid Protomaps .pmtiles URL for loading map tiles. Only necessary if -map-provider is "protomaps". (default "/tiles/")
  -server-uri string
    	A valid aaronland/go-http-server URI (default "http://localhost:8080")
  -tilezen-enable-tilepack
    	Enable to use of Tilezen MBTiles tilepack for tile-serving. Only necessary if -map-provider is "tangram".
  -tilezen-tilepack-path string
    	The path to the Tilezen MBTiles tilepack to use for serving tiles. Only necessary if -map-provider is "tangram" and -tilezen-enable-tilezen is true.
Example
protomaps

go run -mod vendor cmd/server/main.go \
	-map-provider protomaps \
	-protomaps-serve-tiles \
	-protomaps-bucket-uri file:///{PATH_TO}/go-http-maps/fixtures
	-protomaps-database sfo
tangram

go run -mod vendor cmd/server/main.go \
	-map-provider tangram \
	-nextzen-apikey {APIKEY}

Or if you have a local tilepack of Nextzen tiles:

go run -mod vendor cmd/server/main.go \
	-map-provider tangramjs \
	-tilezen-enable-tilepack \
	-tilezen-tilepack-path /usr/local/data/sf.db
leafet

go run -mod vendor cmd/server/main.go \
	-map-provider leaflet
	-leaflet-tile-url https://tile.openstreetmap.org/{z}/{x}/{y}.png

See also

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendAssetHandlers

func AppendAssetHandlers(mux *http.ServeMux, opts *MapsOptions) error

Append all the files in the net/http FS instance containing the embedded Maps assets to an *http.ServeMux instance.

func AppendResourcesHandler

func AppendResourcesHandler(next http.Handler, opts *MapsOptions) http.Handler

AppendResourcesHandler will rewrite any HTML produced by previous handler to include the necessary markup to load Maps JavaScript and CSS files and related assets.

func AppendResourcesHandlerWithProvider added in v0.2.0

func AppendResourcesHandlerWithProvider(next http.Handler, map_provider provider.Provider, maps_opts *MapsOptions) http.Handler

Types

type MapsOptions

type MapsOptions struct {
	JS             []string
	CSS            []string
	DataAttributes map[string]string
	// AppendJavaScriptAtEOF is a boolean flag to append JavaScript markup at the end of an HTML document
	// rather than in the <head> HTML element. Default is false
	AppendJavaScriptAtEOF bool
	RollupAssets          bool
	Prefix                string
	Logger                *log.Logger
}

MapsOptions provides a list of JavaScript and CSS link to include with HTML output.

func DefaultMapsOptions

func DefaultMapsOptions() *MapsOptions

Return a *MapsOptions struct with default paths and URIs.

Directories

Path Synopsis
app
cmd
http
www

Jump to

Keyboard shortcuts

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