forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_layer.go
51 lines (46 loc) · 1.95 KB
/
map_layer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package provider
import (
"fmt"
"strings"
"github.com/go-spatial/tegola/internal/env"
)
// MapLayer represents a the config for a layer in a map
type MapLayer struct {
// Name is optional. If it's not defined the name of the ProviderLayer will be used.
// Name can also be used to group multiple ProviderLayers under the same namespace.
Name env.String `toml:"name"`
ProviderLayer env.String `toml:"provider_layer"`
MinZoom *env.Uint `toml:"min_zoom"`
MaxZoom *env.Uint `toml:"max_zoom"`
DefaultTags env.Dict `toml:"default_tags"`
// DontSimplify indicates whether feature simplification should be applied.
// We use a negative in the name so the default is to simplify
DontSimplify env.Bool `toml:"dont_simplify"`
// DontClip indicates whether feature clipping should be applied.
// We use a negative in the name so the default is to clipping
DontClip env.Bool `toml:"dont_clip"`
// DontClip indicates whether feature cleaning (e.g. make valid) should be applied.
// We use a negative in the name so the default is to clean
DontClean env.Bool `toml:"dont_clean"`
}
// ProviderLayerName returns the names of the layer and provider or an error
func (ml MapLayer) ProviderLayerName() (provider, layer string, err error) {
// split the provider layer (syntax is provider.layer)
plParts := strings.Split(string(ml.ProviderLayer), ".")
if len(plParts) != 2 {
// TODO (beymak): Properly handle the error
return "", "", fmt.Errorf("config: invalid provider layer name (%v)", ml.ProviderLayer)
// return "", "", ErrInvalidProviderLayerName{ProviderLayerName: string(ml.ProviderLayer)}
}
return plParts[0], plParts[1], nil
}
// GetName will return the user-defined Layer name from the config,
// or if the name is empty, return the name of the layer associated with
// the provider
func (ml MapLayer) GetName() (string, error) {
if ml.Name != "" {
return string(ml.Name), nil
}
_, name, err := ml.ProviderLayerName()
return name, err
}