-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeature.go
51 lines (44 loc) · 1.12 KB
/
feature.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 geojson
import "encoding/json"
type Feature struct {
id int
properties map[string]interface{}
geometry *Geometry
}
func NewFeature(id int, properties map[string]interface{}, geometry *Geometry) *Feature {
return &Feature{id, properties, geometry}
}
// json marshaling for struct Feature
func (f *Feature) MarshalJSON() ([]byte, error) {
return json.Marshal(
map[string]interface{}{
"type": "Feature",
"id": f.id,
"properties": f.properties,
"geometry": f.geometry,
})
}
type FeatureCollection struct {
features []*Feature
results int
}
func NewFeatureCollection(features []*Feature, results int) *FeatureCollection {
return &FeatureCollection{features, results}
}
// json marshaling for struct FeatureCollection
func (fc *FeatureCollection) MarshalJSON() ([]byte, error) {
if fc.results == -1 {
return json.Marshal(
map[string]interface{}{
"type": "FeatureCollection",
"features": fc.features,
})
} else {
return json.Marshal(
map[string]interface{}{
"type": "FeatureCollection",
"features": fc.features,
"results": fc.results,
})
}
}