mvt

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2020 License: MIT Imports: 3 Imported by: 3

README

mvt

GoDoc

Draw Mapbox Vector Tiles with ease.

Features

  • Mapbox Vector Tiles 2.1 support
  • MoveTo, LineTo, CubicTo, QuadraticTo
  • Defined 256x256 canvas
  • Uses floating points
  • Add tags and IDs to features
  • Fast encoding to MVT protobufs
  • No external dependencies

Install

go get -u github.com/tidwall/mvt

Example

var tile mvt.Tile
l := tile.AddLayer("triforce")
f := l.AddFeature(mvt.Polygon)

f.MoveTo(128, 96)
f.LineTo(148, 128)
f.LineTo(108, 128)
f.LineTo(128, 96)
f.ClosePath()

f.MoveTo(148, 128)
f.LineTo(168, 160)
f.LineTo(128, 160)
f.LineTo(148, 128)
f.ClosePath()

f.MoveTo(108, 128)
f.LineTo(128, 160)
f.LineTo(88, 160)
f.LineTo(108, 128)
f.ClosePath()

data := tile.Render()

// Data now contains a valid mapbox vector tile protobuf 
// for sending over the internets and styling to your 
// heart's content.

Helper functions

  • mvt.LatLonXY: Converts a lat/lon to the pixel offset for a specific tile.
  • mvt.TileBounds: Returns the lat/lon boundary for a tile.

Contact

Josh Baker @tidwall

License

mvt source code is available under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LatLonXY

func LatLonXY(lat, lon float64, tileX, tileY, tileZ int) (x, y float64)

LatLonXY converts a lat/lon to an point x/y for the specified map tile.

func TileBounds added in v0.1.1

func TileBounds(tileX, tileY, tileZ int,
) (minLat, minLon, maxLat, maxLon float64)

TileBounds returns the lat/lon bounds around a tile.

Types

type Feature

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

Feature represents a feature

func (*Feature) AddTag

func (f *Feature) AddTag(key string, value interface{})

AddTag adds a tag

func (*Feature) ClosePath

func (f *Feature) ClosePath()

ClosePath closes a path

func (*Feature) CubicTo

func (f *Feature) CubicTo(x1, y1, x2, y2, x3, y3 float64)

CubicTo draw a cubic curve

func (*Feature) LineTo

func (f *Feature) LineTo(x, y float64)

LineTo draws a line to a point. The tile is 256x256.

func (*Feature) MoveTo

func (f *Feature) MoveTo(x, y float64)

MoveTo move to a point. The tile is 256x256.

func (*Feature) QuadraticTo

func (f *Feature) QuadraticTo(x1, y1, x2, y2 float64)

QuadraticTo draw a quadratic curve

func (*Feature) SetID

func (f *Feature) SetID(id uint64)

SetID set the id

type GeometryType

type GeometryType byte

GeometryType represents geometry type

const (
	// Unknown is an unknown geometry type
	Unknown GeometryType = 0
	// Point is a point
	Point GeometryType = 1
	// LineString is a line string
	LineString GeometryType = 2
	// Polygon is a polygon
	Polygon GeometryType = 3
)

type Layer

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

Layer represents a layer

func (*Layer) AddFeature

func (l *Layer) AddFeature(geomType GeometryType) *Feature

AddFeature add a geometry feature

func (*Layer) SetExtent

func (l *Layer) SetExtent(extent uint32)

SetExtent sets the layers extent. Default is 4096.

type Tile

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

Tile represents a Mapbox Vector Tile

func (*Tile) AddLayer

func (t *Tile) AddLayer(name string) *Layer

AddLayer adds a layer

func (*Tile) Render

func (t *Tile) Render() []byte

Render renders the tile to a protobuf file for displaying on a map.

Jump to

Keyboard shortcuts

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