mvt

package module
v0.1.0 Latest Latest
Warning

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

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

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.

There's also the helper function mvt.LatLonXY for converting a lat/lon for a specific tile to the appropriate x/y position for drawing in that tile. For example:

f.MoveTo(mvt.LatLonXY(33.4131, -111.9396, 6195, 13154, 15))

This will move to [2.76645 0.56180].

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.

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