forked from ryankurte/go-mapbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapbox.go
55 lines (48 loc) · 1.69 KB
/
mapbox.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
/**
* go-mapbox Mapbox API Modle
* Wraps the mapbox APIs for golang server (or application) use
* See https://www.mapbox.com/api-documentation/for API information
*
* https://github.com/anoda-vladislavhirko/go-mapbox
* Copyright 2017 Ryan Kurte
*/
package mapbox
import (
"github.com/anoda-vladislavhirko/go-mapbox/lib/base"
"github.com/anoda-vladislavhirko/go-mapbox/lib/directions"
"github.com/anoda-vladislavhirko/go-mapbox/lib/directions_matrix"
"github.com/anoda-vladislavhirko/go-mapbox/lib/geocode"
"github.com/anoda-vladislavhirko/go-mapbox/lib/map_matching"
"github.com/anoda-vladislavhirko/go-mapbox/lib/maps"
)
// Mapbox API Wrapper structure
type Mapbox struct {
base *base.Base
// Maps allows fetching of tiles and tilesets
Maps *maps.Maps
// Geocode allows forward (by address) and reverse (by lat/lng) geocoding
Geocode *geocode.Geocode
// Directions generates directions between arbitrary points
Directions *directions.Directions
// Direction Matrix returns all travel times and ways points between multiple points
DirectionsMatrix *directionsmatrix.DirectionsMatrix
// MapMatching snaps inaccurate path tracked to a map to produce a clean path
MapMatching *mapmatching.MapMatching
}
// NewMapbox Create a new mapbox API instance
func NewMapbox(token string) (*Mapbox, error) {
m := &Mapbox{}
// Create base instance
base, err := base.NewBase(token)
if err != nil {
return nil, err
}
m.base = base
// Bind modules
m.Maps = maps.NewMaps(m.base)
m.Geocode = geocode.NewGeocode(m.base)
m.Directions = directions.NewDirections(m.base)
m.DirectionsMatrix = directionsmatrix.NewDirectionsMatrix(m.base)
m.MapMatching = mapmatching.NewMapMaptching(m.base)
return m, nil
}