maps

package module
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2023 License: BSD-3-Clause Imports: 9 Imported by: 3

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 *gohttp.ServeMux) error

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

func AppendAssetHandlersWithPrefix

func AppendAssetHandlersWithPrefix(mux *gohttp.ServeMux, prefix string) error

Append all the files in the net/http FS instance containing the embedded Maps assets to an *http.ServeMux instance ensuring that all URLs are prepended with prefix.

func AppendResourcesHandler

func AppendResourcesHandler(next gohttp.Handler, opts *MapsOptions) gohttp.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 AppendResourcesHandlerWithPrefix

func AppendResourcesHandlerWithPrefix(next gohttp.Handler, opts *MapsOptions, prefix string) gohttp.Handler

AppendResourcesHandlerWithPrefix will rewrite any HTML produced by previous handler to include the necessary markup to load Maps JavaScript files and related assets ensuring that all URIs are prepended with a prefix.

func AppendResourcesHandlerWithPrefixAndProvider added in v0.0.7

func AppendResourcesHandlerWithPrefixAndProvider(next gohttp.Handler, map_provider provider.Provider, maps_opts *MapsOptions, prefix string) gohttp.Handler

func AssetsHandler

func AssetsHandler() (gohttp.Handler, error)

AssetsHandler returns a net/http FS instance containing the embedded Maps assets that are included with this package.

func AssetsHandlerWithPrefix

func AssetsHandlerWithPrefix(prefix string) (gohttp.Handler, error)

AssetsHandler returns a net/http FS instance containing the embedded Maps assets that are included with this package ensuring that all URLs are stripped of prefix.

Types

type MapsOptions

type MapsOptions struct {
	JS             []string
	CSS            []string
	DataAttributes map[string]string
}

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