Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions atlas/atlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,21 +102,19 @@ func (a *Atlas) AllMaps() []Map {

// SeedMapTile will generate a tile and persist it to the
// configured cache backend
func (a *Atlas) SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
func (a *Atlas) SeedMapTile(ctx context.Context, m Map, tile *slippy.Tile) error {

if a == nil {
// Use the default Atlas if a, is nil. This way the empty value is
// still useful.
return defaultAtlas.SeedMapTile(ctx, m, z, x, y)
return defaultAtlas.SeedMapTile(ctx, m, tile)
}

// confirm we have a cache backend
if a.cacher == nil {
return ErrMissingCache
}

tile := slippy.NewTile(z, x, y)

// encode the tile
b, err := m.Encode(ctx, tile)
if err != nil {
Expand All @@ -126,16 +124,16 @@ func (a *Atlas) SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
// cache key
key := cache.Key{
MapName: m.Name,
Z: z,
X: x,
Y: y,
Z: tile.Z,
X: tile.X,
Y: tile.Y,
}

return a.cacher.Set(&key, b)
}

// PurgeMapTile will purge a map tile from the configured cache backend
func (a *Atlas) PurgeMapTile(m Map, tile *tegola.Tile) error {
func (a *Atlas) PurgeMapTile(m Map, tile *slippy.Tile) error {
if a == nil {
// Use the default Atlas if a, is nil. This way the empty value is
// still useful.
Expand Down Expand Up @@ -249,12 +247,12 @@ func SetCache(c cache.Interface) {

// SeedMapTile will generate a tile and persist it to the
// configured cache backend for the defaultAtlas
func SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
return defaultAtlas.SeedMapTile(ctx, m, z, x, y)
func SeedMapTile(ctx context.Context, m Map, tile *slippy.Tile) error {
return defaultAtlas.SeedMapTile(ctx, m, tile)
}

// PurgeMapTile will purge a map tile from the configured cache backend
// for the defaultAtlas
func PurgeMapTile(m Map, tile *tegola.Tile) error {
func PurgeMapTile(m Map, tile *slippy.Tile) error {
return defaultAtlas.PurgeMapTile(m, tile)
}
14 changes: 7 additions & 7 deletions atlas/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ func NewWebMercatorMap(name string) Map {
Bounds: tegola.WGS84Bounds,
Layers: []Layer{},
SRID: tegola.WebMercator,
TileExtent: 4096,
TileExtent: uint64(mvt.DefaultExtent),
TileBuffer: uint64(tegola.DefaultTileBuffer),
}
}

type Map struct {
Name string
// Contains an attribution to be displayed when the map is shown to a user.
// Contains an attribution to be displayed when the map is shown to a user),
// This string is sanatized so it can't be abused as a vector for XSS or beacon tracking.
Attribution string
// The maximum extent of available map tiles in WGS:84
Expand Down Expand Up @@ -197,10 +197,8 @@ func (m Map) Encode(ctx context.Context, tile *slippy.Tile) ([]byte, error) {
return err
}

// TODO (arolek): change out the tile type for VTile. tegola.Tile will be deprecated
tegolaTile := tegola.NewTile(tile.ZXY())

sg := simplify.SimplifyGeometry(tegolaGeo, tegolaTile.ZEpislon())
sg := simplify.SimplifyGeometry(tegolaGeo,
simplify.ZEpislon(tile.Z, float64(m.TileExtent)))

// TODO: remove this geom conversion step once the simplify function uses geom types
geo, err = convert.ToGeom(sg)
Expand All @@ -212,7 +210,8 @@ func (m Map) Encode(ctx context.Context, tile *slippy.Tile) ([]byte, error) {
// check if we need to clip and if we do build the clip region (tile extent)
var clipRegion *geom.Extent
if !l.DontClip {
clipRegion = tile.Extent3857().ExpandBy(float64(m.TileBuffer))
webs := slippy.Pixels2Webs(tile.Z, uint(m.TileBuffer))
clipRegion = tile.Extent3857().ExpandBy(webs)
}

// create a hitmap for the makevalid function
Expand Down Expand Up @@ -308,3 +307,4 @@ func (m Map) Encode(ctx context.Context, tile *slippy.Tile) ([]byte, error) {
// return encoded, gzipped tile
return gzipBuf.Bytes(), nil
}

139 changes: 136 additions & 3 deletions atlas/map_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (

vectorTile "github.com/go-spatial/geom/encoding/mvt/vector_tile"
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/geom/encoding/mvt"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/internal/p"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/provider"
"github.com/go-spatial/tegola/provider/test"
"github.com/go-spatial/tegola/provider/test/emptycollection"
)
Expand Down Expand Up @@ -196,6 +199,11 @@ func TestEncode(t *testing.T) {
return
}

if len(tileLayer.Features) != len(expectedLayer.Features) {
t.Errorf("expected %v features in layer %v, got %v", len(expectedLayer.Features), *tileLayer.Name, len(tileLayer.Features))
return
}

// features check
for k, tileLayerFeature := range tileLayer.Features {
expectedTileLayerFeature := expectedLayer.Features[k]
Expand All @@ -219,7 +227,7 @@ func TestEncode(t *testing.T) {
}

if !reflect.DeepEqual(tileLayerFeature.Geometry, expectedTileLayerFeature.Geometry) {
t.Errorf("expected %v got %v", tileLayerFeature.Geometry, expectedTileLayerFeature.Geometry)
t.Errorf("expected %v got %v", expectedTileLayerFeature.Geometry, tileLayerFeature.Geometry)
return
}
}
Expand Down Expand Up @@ -292,8 +300,10 @@ func TestEncode(t *testing.T) {
Provider: &test.TileProvider{},
},
},
TileBuffer: uint64(tegola.DefaultTileBuffer),
TileExtent: uint64(mvt.DefaultExtent),
},
tile: slippy.NewTile(2, 3, 4),
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down Expand Up @@ -340,6 +350,127 @@ func TestEncode(t *testing.T) {
},
},
},
"clip": {
grid: atlas.Map{
Layers: []atlas.Layer{
{
Name: "layer1",
MinZoom: 0,
MaxZoom: 2,
DontSimplify: true,
Provider: &test.TileProvider{
Features: []provider.Feature{
{
SRID: 3857,
Geometry: slippy.NewTile(0, 0, 0).Extent3857().AsPolygon(),
},
},
},
},
},
TileBuffer: uint64(tegola.DefaultTileBuffer),
TileExtent: uint64(mvt.DefaultExtent),
},
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Version: p.Uint32(2),
Name: p.String("layer1"),
Features: []*vectorTile.Tile_Feature{
{
Id: p.Uint64(0),
Tags: []uint32{0, 0, 1, 1},
Type: &polygon,
Geometry: []uint32{9, 127, 127, 26, 8320, 0, 0, 8320, 8319, 0, 15},
},
},
Extent: p.Uint32(vectorTile.Default_Tile_Layer_Extent),
},
},
},
},
"clip no buf": {
grid: atlas.Map{
Layers: []atlas.Layer{
{
Name: "layer1",
MinZoom: 0,
MaxZoom: 2,
DontSimplify: true,
Provider: &test.TileProvider{
Features: []provider.Feature{
{
SRID: 3857,
Geometry: slippy.NewTile(0, 0, 0).Extent3857().AsPolygon(),
},
},
},
},
},
TileBuffer: uint64(0),
TileExtent: uint64(mvt.DefaultExtent),
},
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Version: p.Uint32(2),
Name: p.String("layer1"),
Features: []*vectorTile.Tile_Feature{
{
Id: p.Uint64(0),
Tags: []uint32{0, 0, 1, 1},
Type: &polygon,
Geometry: []uint32{9, 0, 0, 26, 8192, 0, 0, 8192, 8191, 0, 15},
},
},
Extent: p.Uint32(vectorTile.Default_Tile_Layer_Extent),
},
},
},
},
"don't clip": {
grid: atlas.Map{
Layers: []atlas.Layer{
{
Name: "layer1",
MinZoom: 0,
MaxZoom: 2,
DontSimplify: true,
Provider: &test.TileProvider{
Features: []provider.Feature{
{
SRID: 3857,
Geometry: slippy.NewTile(0, 0, 0).Extent3857().AsPolygon(),
},
},
},
DontClip: true,
},
},
TileBuffer: uint64(tegola.DefaultTileBuffer),
TileExtent: uint64(mvt.DefaultExtent),
},
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Version: p.Uint32(2),
Name: p.String("layer1"),
Features: []*vectorTile.Tile_Feature{
{
Id: p.Uint64(0),
Tags: []uint32{0, 0, 1, 1},
Type: &polygon,
Geometry: []uint32{9, 24573, 24573, 26, 32766, 0, 0, 32766, 32765, 0, 15},
},
},
Extent: p.Uint32(vectorTile.Default_Tile_Layer_Extent),
},
},
},
},
"empty_collection": {
grid: atlas.Map{
Layers: []atlas.Layer{
Expand All @@ -350,8 +481,10 @@ func TestEncode(t *testing.T) {
Provider: &emptycollection.TileProvider{},
},
},
TileBuffer: uint64(tegola.DefaultTileBuffer),
TileExtent: uint64(mvt.DefaultExtent),
},
tile: slippy.NewTile(2, 3, 4),
tile: slippy.NewTile(2, 3, 3),
expected: vectorTile.Tile{
Layers: []*vectorTile.Tile_Layer{
{
Expand Down
11 changes: 4 additions & 7 deletions cmd/tegola/cmd/cache/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/atlas"
"github.com/go-spatial/tegola/cache"
"github.com/go-spatial/tegola/internal/log"
Expand Down Expand Up @@ -74,8 +73,8 @@ func seedWorker(overwrite bool) func(ctx context.Context, mt MapTile) error {
}
}

// seed the tile
if err = atlas.SeedMapTile(ctx, m, z, x, y); err != nil {
// seed the tile
if err = atlas.SeedMapTile(ctx, m, mt.Tile); err != nil {
if err == context.Canceled {
return err
}
Expand Down Expand Up @@ -112,10 +111,8 @@ func purgeWorker(_ context.Context, mt MapTile) error {
}
}

// purge the tile
ttile := tegola.NewTile(mt.Tile.ZXY())

if err = atlas.PurgeMapTile(m, ttile); err != nil {
// purge the tile
if err = atlas.PurgeMapTile(m, mt.Tile); err != nil {
return seedPurgeWorkerTileError{
Purge: true,
Tile: *mt.Tile,
Expand Down
9 changes: 9 additions & 0 deletions defaults.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tegola

const (
DefaultEpislon = 10.0
DefaultExtent = 4096
DefaultTileBuffer = 64.0
MaxZ = 22
)

27 changes: 27 additions & 0 deletions maths/simplify/epislon.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package simplify

import (
"math"

"github.com/go-spatial/tegola"
)

var (
DefaultTolerence = 10.0
)

// This is from Leaflet
func ZEpislon(z uint, tileExtent float64) float64 {

if z == tegola.MaxZ {
return 0
}
epi := DefaultTolerence
if epi <= 0 {
return 0
}

denom := (math.Exp2(float64(z)) * tileExtent)

return epi / denom
}
Loading