Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: adds configurable query parameters to tile endpoints #867

Closed
Prev Previous commit
Next Next commit
feat: disable caching for maps with params
Warn about disabled caching
  • Loading branch information
bemyak committed Nov 30, 2022
commit 8329ac4353a2ac664ad7cb2df2799179bed64aac
36 changes: 0 additions & 36 deletions atlas/atlas.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,6 @@ import (
"github.com/go-spatial/geom/slippy"
"github.com/go-spatial/tegola"
"github.com/go-spatial/tegola/cache"
"github.com/go-spatial/tegola/config"
"github.com/go-spatial/tegola/internal/log"
"github.com/go-spatial/tegola/internal/observer"
"github.com/go-spatial/tegola/observability"
@@ -79,10 +78,6 @@ type Atlas struct {
// holds a reference to the observer backend
observer observability.Interface

// holds a reference to configured query parameters for maps
// key = map name
params map[string][]config.QueryParameter

// publishBuildInfo indicates if we should publish the build info on change of observer
// this is set by calling PublishBuildInfo, which will publish
// the build info on the observer and insure changes to observer
@@ -135,7 +130,6 @@ func (a *Atlas) SeedMapTile(ctx context.Context, m Map, z, x, y uint) error {
tile := slippy.NewTile(z, x, y)

// encode the tile
// TODO (bemyak): Make query parameters work with cache
b, err := m.Encode(ctx, tile, nil)
if err != nil {
return err
@@ -219,36 +213,6 @@ func (a *Atlas) AddMap(m Map) {
a.maps[m.Name] = m
}

// AddParams adds the given query parameters to the atlas params map
// keyed by the map name, with upper-cased tokens
func (a *Atlas) AddParams(name string, params []config.QueryParameter) {
if a == nil {
defaultAtlas.AddParams(name, params)
return
}
if a.params == nil {
a.params = make(map[string][]config.QueryParameter)
}
a.params[name] = params
}

// GetParams returns any configured query parameters for the given
// map by name
func (a *Atlas) GetParams(name string) []config.QueryParameter {
if a == nil {
return defaultAtlas.GetParams(name)
}
return a.params[name]
}

// HasParams returns true if the given map by name has configured query parameters
func (a *Atlas) HasParams(name string) bool {
if a == nil {
return defaultAtlas.HasParams(name)
}
return len(a.params[name]) > 0
}

// GetCache returns the registered cache if one is registered, otherwise nil
func (a *Atlas) GetCache() cache.Interface {
if a == nil {
3 changes: 3 additions & 0 deletions atlas/map.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ import (
"strings"
"sync"

"github.com/go-spatial/tegola/config"
"github.com/go-spatial/tegola/observability"

"github.com/golang/protobuf/proto"
@@ -54,6 +55,8 @@ type Map struct {
// WGS:84 values), the third value is the zoom level.
Center [3]float64
Layers []Layer
// Params holds configured query parameters
Params []config.QueryParameter

SRID uint64
// MVT output values
5 changes: 1 addition & 4 deletions cmd/internal/register/maps.go
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ import (
func webMercatorMapFromConfigMap(cfg config.Map) (newMap atlas.Map) {
newMap = atlas.NewWebMercatorMap(string(cfg.Name))
newMap.Attribution = SanitizeAttribution(string(cfg.Attribution))
newMap.Params = cfg.Parameters

// convert from env package
for i, v := range cfg.Center {
@@ -156,10 +157,6 @@ func Maps(a *atlas.Atlas, maps []config.Map, providers map[string]provider.Tiler
newMap.Layers = append(newMap.Layers, layer)
}

if len(m.Parameters) > 0 {
a.AddParams(string(m.Name), m.Parameters)
}

a.AddMap(newMap)
}
return nil
15 changes: 12 additions & 3 deletions cmd/tegola/cmd/cache/cache.go
Original file line number Diff line number Diff line change
@@ -159,11 +159,20 @@ func doWork(ctx context.Context, tileChannel *TileChannel, maps []atlas.Map, con
}(i)
}

nonParamMaps := make([]atlas.Map, 0)

for _, m := range maps {
// we don't support caching for maps with custom parameters
if m.Params != nil || len(m.Params) > 0 {
log.Warnf("caching is disabled for map %s as it has custom parameters configures", m.Name)
}
nonParamMaps = append(nonParamMaps, m)
}

// run through the incoming tiles, and generate the mapTiles as needed.
TileChannelLoop:
for tile := range tileChannel.Channel() {
for m := range maps {

for _, m := range nonParamMaps {
if ctx.Err() != nil {
cleanup = true
break
@@ -180,7 +189,7 @@ TileChannelLoop:
}

mapTile := MapTile{
MapName: maps[m].Name,
MapName: m.Name,
Tile: tile,
}