mvt

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: BSD-3-Clause Imports: 10 Imported by: 1

README

go-http-mvt

Go package proving http.HandlerFunc instances for serving MVT vector tiles using custom data providers.

Example

import (
	"net/http"
	
	"github.com/sfomuseum/go-http-mvt"
)

func main() {

	// This is your custom code to implement the following method signature
	//  to return a dictionary of GeoJSON FeatureCollection instances:
	// func(*http.Request, string, *maptile.Tile) (map[string]*geojson.FeatureCollection, error)
	
	var features_cb := mvt.GetFeaturesCallbackFunc

	mvt_opts := &mvt.TileHandlerOptions{
		GetFeaturesCallback: features_cb,
		Simplify:            true,
	}

	mvt_handler, _ := mvt.NewTileHandler(mvt_opts)

	mux := http.NewServeMux()
	mux.Handle("/tiles/", mvt_handler)

	http.ListenAndServe(":8080", mux)
}

This package does not provide any tile caching or CORS support. That is left to separate middleware handlers like victorspringer/http-cache or rs/cors (or equivalents) respectively.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTileHandler

func NewTileHandler(opts *TileHandlerOptions) (http.Handler, error)

NewTileHandler return a new `http.Handler` instance serving MVT vector tiles.

Types

type GetFeaturesCallbackFunc

type GetFeaturesCallbackFunc func(*http.Request, string, *maptile.Tile) (map[string]*geojson.FeatureCollection, error)

GetFeaturesCallbackFunc defines the method signature for custom functions to derive a collection of named `geojson.FeatureCollection` instances for a given tile request.

type TileHandlerOptions

type TileHandlerOptions struct {
	// GetFeaturesCallback is the `GetFeaturesCallbackFunc` used to derive a collection of named `geojson.FeatureCollection` instances for a given tile request.
	GetFeaturesCallback GetFeaturesCallbackFunc
	// Simplify is a boolean flag to signal that tile data should be simplified (using DouglasPeucker) before being returned by the handler.
	Simplify bool
	// Timings is a boolean flag to enable logging timing information (using `log/slog.Debug`).
	Timings bool
}

Jump to

Keyboard shortcuts

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