2023-03-29 10:50:25 +00:00
|
|
|
package tiles
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"git.coopgo.io/coopgo-platform/carpool-service/storage"
|
|
|
|
"github.com/paulmach/orb"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
type TilesHandler struct {
|
|
|
|
Config *viper.Viper
|
|
|
|
PersistentStorage storage.Storage
|
|
|
|
|
|
|
|
CachedTileset map[string]Tileset
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTilesHandler(cfg *viper.Viper, persistantStorage storage.Storage) (*TilesHandler, error) {
|
|
|
|
return &TilesHandler{
|
|
|
|
Config: cfg,
|
|
|
|
PersistentStorage: persistantStorage,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTiles retrieves tiles
|
|
|
|
func (h *TilesHandler) GetTiles(driverOrPassenger string, date time.Time, points ...orb.Point) (*Tileset, error) {
|
2023-03-29 22:45:18 +00:00
|
|
|
dateString := date.Format("2006-01-02")
|
|
|
|
|
2023-03-29 10:50:25 +00:00
|
|
|
result := Tileset{}
|
|
|
|
|
|
|
|
grid_ids := []GridId{}
|
|
|
|
|
|
|
|
nb_points := len(points)
|
|
|
|
|
|
|
|
if nb_points > 1 {
|
|
|
|
grid_ids = LineStringGridIds(orb.LineString(points))
|
|
|
|
} else if nb_points == 1 {
|
|
|
|
grid_ids = []GridId{PointGridId(points[0])}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, gid := range grid_ids {
|
|
|
|
tile, err := h.GetTile(driverOrPassenger, date, gid)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
result[dateString] = tile
|
|
|
|
}
|
|
|
|
|
|
|
|
return &result, nil
|
|
|
|
}
|