This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
geofence_area_selector.go
91 lines (75 loc) · 2.92 KB
/
geofence_area_selector.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package t38c
import (
"strconv"
geojson "github.com/paulmach/go.geojson"
)
// GeofenceAreaSelector struct
type GeofenceAreaSelector struct {
client tile38Client
cmd string
key string
}
func newGeofenceAreaSelector(client tile38Client, cmd, key string) GeofenceAreaSelector {
return GeofenceAreaSelector{
client: client,
cmd: cmd,
key: key,
}
}
// Get any object that already exists in the database.
func (selector GeofenceAreaSelector) Get(key, objectID string) GeofenceQueryBuilder {
area := newCmd("GET", key, objectID)
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Bounds - a minimum bounding rectangle.
func (selector GeofenceAreaSelector) Bounds(minlat, minlon, maxlat, maxlon float64) GeofenceQueryBuilder {
area := newCmd("BOUNDS", floatString(minlat), floatString(minlon), floatString(maxlat), floatString(maxlon))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// FeatureCollection - GeoJSON Feature Collection object.
func (selector GeofenceAreaSelector) FeatureCollection(fc *geojson.FeatureCollection) GeofenceQueryBuilder {
b, err := fc.MarshalJSON()
if err != nil {
panic(err)
}
area := newCmd("OBJECT", string(b))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Feature - GeoJSON Feature object.
func (selector GeofenceAreaSelector) Feature(ft *geojson.Feature) GeofenceQueryBuilder {
b, err := ft.MarshalJSON()
if err != nil {
panic(err)
}
area := newCmd("OBJECT", string(b))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Geometry - GeoJSON Geometry object.
func (selector GeofenceAreaSelector) Geometry(gm *geojson.Geometry) GeofenceQueryBuilder {
b, err := gm.MarshalJSON()
if err != nil {
panic(err)
}
area := newCmd("OBJECT", string(b))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Circle - a circle with the specified center and radius.
func (selector GeofenceAreaSelector) Circle(lat, lon, meters float64) GeofenceQueryBuilder {
area := newCmd("CIRCLE", floatString(lat), floatString(lon), floatString(meters))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Tile - an XYZ Tile.
func (selector GeofenceAreaSelector) Tile(x, y, z int) GeofenceQueryBuilder {
area := newCmd("TILE", strconv.Itoa(x), strconv.Itoa(y), strconv.Itoa(z))
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Quadkey - a QuadKey.
func (selector GeofenceAreaSelector) Quadkey(quadkey string) GeofenceQueryBuilder {
area := newCmd("QUADKEY", quadkey)
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}
// Hash - a Geohash.
func (selector GeofenceAreaSelector) Hash(hash string) GeofenceQueryBuilder {
area := newCmd("HASH", hash)
return newGeofenceQueryBuilder(selector.client, selector.cmd, selector.key, area)
}