
This commit includes updates that affects the build, testing, and deployment of Tile38. - The root level build.sh has been broken up into multiple scripts and placed in the "scripts" directory. - The vendor directory has been updated to follow the Go modules rules, thus `make` should work on isolated environments. Also some vendored packages may have been updated to a later version, if needed. - The Makefile has been updated to allow for making single binaries such as `make tile38-server`. There is some scaffolding during the build process, so from now on all binaries should be made using make. For example, to run a development version of the tile38-cli binary, do this: make tile38-cli && ./tile38-cli not this: go run cmd/tile38-cli/main.go - Travis.CI docker push script has been updated to address a change to Docker's JSON repo meta output, which in turn fixes a bug where new Tile38 versions were not being properly pushed to Docker
82 lines
1.7 KiB
Go
82 lines
1.7 KiB
Go
package geojson
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/tidwall/gjson"
|
|
)
|
|
|
|
// FeatureCollection ...
|
|
type FeatureCollection struct{ collection }
|
|
|
|
// NewFeatureCollection ...
|
|
func NewFeatureCollection(features []Object) *FeatureCollection {
|
|
g := new(FeatureCollection)
|
|
g.children = features
|
|
g.parseInitRectIndex(DefaultParseOptions)
|
|
return g
|
|
}
|
|
|
|
// AppendJSON appends the GeoJSON reprensentation to dst
|
|
func (g *FeatureCollection) AppendJSON(dst []byte) []byte {
|
|
dst = append(dst, `{"type":"FeatureCollection","features":[`...)
|
|
for i := 0; i < len(g.children); i++ {
|
|
if i > 0 {
|
|
dst = append(dst, ',')
|
|
}
|
|
dst = g.children[i].AppendJSON(dst)
|
|
}
|
|
dst = append(dst, ']')
|
|
if g.extra != nil {
|
|
dst = g.extra.appendJSONExtra(dst, false)
|
|
}
|
|
dst = append(dst, '}')
|
|
strings.Index("", " ")
|
|
return dst
|
|
}
|
|
|
|
// String ...
|
|
func (g *FeatureCollection) String() string {
|
|
return string(g.AppendJSON(nil))
|
|
}
|
|
|
|
// JSON ...
|
|
func (g *FeatureCollection) JSON() string {
|
|
return string(g.AppendJSON(nil))
|
|
}
|
|
|
|
// MarshalJSON ...
|
|
func (g *FeatureCollection) MarshalJSON() ([]byte, error) {
|
|
return g.AppendJSON(nil), nil
|
|
}
|
|
|
|
func parseJSONFeatureCollection(
|
|
keys *parseKeys, opts *ParseOptions,
|
|
) (Object, error) {
|
|
var g FeatureCollection
|
|
if !keys.rFeatures.Exists() {
|
|
return nil, errFeaturesMissing
|
|
}
|
|
if !keys.rFeatures.IsArray() {
|
|
return nil, errFeaturesInvalid
|
|
}
|
|
var err error
|
|
keys.rFeatures.ForEach(func(key, value gjson.Result) bool {
|
|
var f Object
|
|
f, err = Parse(value.Raw, opts)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
g.children = append(g.children, f)
|
|
return true
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if err := parseBBoxAndExtras(&g.extra, keys, opts); err != nil {
|
|
return nil, err
|
|
}
|
|
g.parseInitRectIndex(opts)
|
|
return &g, nil
|
|
}
|