https://github.com/tidwall/mvt
Draw Mapbox Vector Tiles (MVT) in Go
https://github.com/tidwall/mvt
drawing golang mapbox tiles vector
Last synced: 11 months ago
JSON representation
Draw Mapbox Vector Tiles (MVT) in Go
- Host: GitHub
- URL: https://github.com/tidwall/mvt
- Owner: tidwall
- License: mit
- Created: 2018-01-21T05:24:44.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-12T23:50:40.000Z (over 1 year ago)
- Last Synced: 2025-04-10T00:21:15.096Z (about 1 year ago)
- Topics: drawing, golang, mapbox, tiles, vector
- Language: Go
- Homepage:
- Size: 24.4 KB
- Stars: 56
- Watchers: 7
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mvt
[](https://godoc.org/github.com/tidwall/mvt)
Draw [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) 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
```go
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](http://twitter.com/tidwall)
## License
mvt source code is available under the MIT [License](/LICENSE).