gridserver

package module
v0.0.0-...-dfcebc9 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package gridserver serves tiles with the plus codes grid. This parses the request, and generates either a GeoJSON or PNG image response.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetImageFont

func SetImageFont(ttf []byte) error

SetImageFont parses a TTF font and uses it for the image labels.

Types

type GeodeticTMS

type GeodeticTMS struct {
	// contains filtered or unexported fields
}

GeodeticTMS provides a EPSG:4326 projection. The top zoom level is scaled to two tiles. Zoom levels are not square but rectangular. Although TMS tiles are numbered from south to north, raster coordinates are numbered from north to south. This code is indebted to the gdal2tiles.py from OSGEO GDAL.

func NewGeodeticTMS

func NewGeodeticTMS() *GeodeticTMS

NewGeodeticTMS gets new projection object.

func (*GeodeticTMS) LatLngToRaster

func (g *GeodeticTMS) LatLngToRaster(lat, lng float64, zoom float64) (x, y float64)

LatLngToRaster converts a WGS84 latitude and longitude to absolute pixel values. Note that the pixel origin is at top left.

func (*GeodeticTMS) String

func (g *GeodeticTMS) String() string

String provides the name of the projection.

func (*GeodeticTMS) TileLatLngBounds

func (g *GeodeticTMS) TileLatLngBounds(tx, ty, zoom int) (latlo, lnglo, lathi, lnghi float64)

TileLatLngBounds returns bounds of a TMS tile in latitude/longitude using WGS84 datum.

func (*GeodeticTMS) TileOrigin

func (g *GeodeticTMS) TileOrigin(tx, ty, zoom int) (x, y float64)

TileOrigin returns the left and top of the tile in raster pixels.

type LatLng

type LatLng struct {
	Lat float64 `json:"lat"`
	Lng float64 `json:"lng"`
}

LatLng represents a latitude and longitude in degrees.

func (*LatLng) String

func (l *LatLng) String() string

String returns the lat/lng formatted as a string.

type MercatorTMS

type MercatorTMS struct {
	// contains filtered or unexported fields
}

MercatorTMS provides a spherical mercator projection using TMS tile specifications. Although TMS tiles are numbered from south to north, raster coordinates are numbered from north to south. This code is indebted to the gdal2tiles.py from OSGEO GDAL.

func NewMercatorTMS

func NewMercatorTMS() *MercatorTMS

NewMercatorTMS gets new projection object.

func (*MercatorTMS) LatLngToRaster

func (m *MercatorTMS) LatLngToRaster(lat, lng float64, zoom float64) (x, y float64)

LatLngToRaster converts a WGS84 latitude and longitude to absolute pixel values. Note that the pixel origin is at top left.

func (*MercatorTMS) String

func (m *MercatorTMS) String() string

String provides the name of the projection.

func (*MercatorTMS) TileLatLngBounds

func (m *MercatorTMS) TileLatLngBounds(tx, ty, zoom int) (latlo, lnglo, lathi, lnghi float64)

TileLatLngBounds returns bounds of a TMS tile in latitude/longitude using WGS84 datum.

func (*MercatorTMS) TileOrigin

func (m *MercatorTMS) TileOrigin(tx, ty, zoom int) (x, y float64)

TileOrigin returns the left and top of the tile in raster pixels.

type Projection

type Projection interface {
	TileOrigin(tx, ty, zoom int) (float64, float64)
	TileLatLngBounds(tx, ty, zoom int) (float64, float64, float64, float64)
	LatLngToRaster(float64, float64, float64) (x, y float64)
	String() string
}

Projection defines the interface for types that convert between pixel and lat/lng coordinates.

type TileFormat

type TileFormat int

TileFormat specifies the types of tiles to generate.

const (
	// JSONTile indicates the tile output should be GeoJSON.
	JSONTile TileFormat = 0
	// ImageTile indicates the tile output should be a PNG image.
	ImageTile TileFormat = 1
)

type TileOptions

type TileOptions struct {
	Format     TileFormat
	LineColor  color.Color
	LabelColor color.Color
	Projection Projection
	ZoomAdjust int
}

TileOptions are settings to adjust how the tiles are generated.

func NewTileOptions

func NewTileOptions() *TileOptions

NewTileOptions returns a default set of options.

func (TileOptions) String

func (o TileOptions) String() string

String returns a string representation of the options.

type TileRef

type TileRef struct {
	Z       int
	X       int
	Y       int
	Options *TileOptions

	SW *LatLng
	NE *LatLng
	// contains filtered or unexported fields
}

TileRef represents a TMS tile reference, based on x/y/z values. It provides the tile bounding box, and a function to convert lat/lng into pixel references.

func MakeTileRef

func MakeTileRef(x, y, z int, opts *TileOptions) *TileRef

MakeTileRef constructs the tile reference.

func Parse

func Parse(r *http.Request) (*TileRef, error)

Parse extracts information from an HTTP request.

func (*TileRef) GeoJSON

func (t *TileRef) GeoJSON() (*geojson.FeatureCollection, error)

GeoJSON returns a GeoJSON object for the tile. Objects (lines etc) may extend outside the tile dimensions, so clipping objects to match tile boundaries is up to the client.

func (*TileRef) Image

func (t *TileRef) Image() ([]byte, error)

Image returns the tile as a 256x256 pixel PNG image.

func (*TileRef) LatLngToPixel

func (t *TileRef) LatLngToPixel(lat, lng float64, tileSize float64) (x float64, y float64)

LatLngToPixel converts a lat/lng pair in degrees to pixel values relative to the NW corner of the tile.

func (*TileRef) Path

func (t *TileRef) Path() string

Path converts a tile reference into a file path using zoom/x/y/options

Jump to

Keyboard shortcuts

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