set up override zoom if both lat and lng within delta
parent
937f91bbf6
commit
e660f2ef9f
20
config.json
20
config.json
|
|
@ -17,17 +17,23 @@
|
|||
"UploadMethod": "POST"
|
||||
},
|
||||
"Maps": {
|
||||
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s\u0026zoom=5",
|
||||
"URIFormat": "https://maps.googleapis.com/maps/api/staticmap?center=%s\u0026markers=label=A|%s\u0026zoom=5\u0026size=250x250\u0026scale=1\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||
"Pathed": false,
|
||||
"Pickup": false,
|
||||
"Dropoff": false
|
||||
"Dropoff": false,
|
||||
"Pathed": {
|
||||
"Enabled": true,
|
||||
"DirectionsURIFormat": "https://maps.googleapis.com/maps/api/directions/json?origin=%s\u0026destination=%s\u0026mode=driving\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg",
|
||||
"PathedURIFormat": "https://maps.googleapis.com/maps/api/staticmap?size=250x250\u0026path=%s\u0026format=jpeg\u0026maptype=roadmap\u0026key=AIzaSyBkACm-LQkoSfsTO5_XAzBVZE9-JQzcNkg\u0026size=250x250\u0026markers=%s|%s",
|
||||
"Zoom": {
|
||||
"AcceptableLatLngDelta": 2,
|
||||
"Override": 5
|
||||
}
|
||||
}
|
||||
},
|
||||
"Clients": {
|
||||
"bel": {
|
||||
"States": [
|
||||
"OH"
|
||||
"NC"
|
||||
],
|
||||
"IDs": {
|
||||
"Matrix": "@bel:m.bltrucks.top"
|
||||
|
|
@ -42,7 +48,7 @@
|
|||
"Message": {
|
||||
"Matrix": {
|
||||
"ReceiveEnabled": true,
|
||||
"Mock": true,
|
||||
"Mock": false,
|
||||
"Homeserver": "https://m.bltrucks.top",
|
||||
"Username": "@bot.m.bltrucks.top",
|
||||
"Token": "mvDWB96KXMF8XhOam8EC5XVdQvSEw0CDeClcSWocBcYkwZX3FPNWZ5uOnQk2EmT1cjpzfeuD7gDYPPjOuyZlI3bE9TE35UjNOlZgi0Tugm25s91iVsbIF6kMZsCIhVMSmEf6w3jxX6wQYOWvmDZ4mu6f5c8wr221EMDcOpEzQV09d1zuBSWgKLBgjqAkYHJZ5dTRIWpEDpPgujhOFZa2ld1HiAOxrJKlIrlfDBN0CUsTlGOGplujDAr4VtpFzNRS",
|
||||
|
|
@ -50,7 +56,7 @@
|
|||
"Room": "!OYZqtInrBCn1cyz90D:m.bltrucks.top"
|
||||
}
|
||||
},
|
||||
"Once": true,
|
||||
"Once": false,
|
||||
"Brokers": {
|
||||
"NTG": {
|
||||
"JobInfo": true,
|
||||
|
|
|
|||
|
|
@ -28,12 +28,18 @@ type Config struct {
|
|||
UploadMethod string
|
||||
}
|
||||
Maps struct {
|
||||
DirectionsURIFormat string
|
||||
PathedURIFormat string
|
||||
URIFormat string
|
||||
Pathed bool
|
||||
Pickup bool
|
||||
Dropoff bool
|
||||
URIFormat string
|
||||
Pickup bool
|
||||
Dropoff bool
|
||||
Pathed struct {
|
||||
Enabled bool
|
||||
DirectionsURIFormat string
|
||||
PathedURIFormat string
|
||||
Zoom struct {
|
||||
AcceptableLatLngDelta float32
|
||||
Override int
|
||||
}
|
||||
}
|
||||
}
|
||||
Clients map[string]Client
|
||||
Storage []string
|
||||
|
|
|
|||
26
main.go
26
main.go
|
|
@ -337,8 +337,8 @@ func sendJob(job broker.Job) (bool, error) {
|
|||
maps := config.Get().Maps
|
||||
pickup := fmt.Sprintf("%s,%s", url.QueryEscape(job.Pickup.City), job.Pickup.State)
|
||||
dropoff := fmt.Sprintf("%s,%s", url.QueryEscape(job.Dropoff.City), job.Dropoff.State)
|
||||
if maps.Pathed {
|
||||
directionsURI := fmt.Sprintf(maps.DirectionsURIFormat, pickup, dropoff)
|
||||
if maps.Pathed.Enabled {
|
||||
directionsURI := fmt.Sprintf(maps.Pathed.DirectionsURIFormat, pickup, dropoff)
|
||||
resp, err := http.Get(directionsURI)
|
||||
if err != nil {
|
||||
return true, err
|
||||
|
|
@ -365,11 +365,31 @@ func sendJob(job broker.Job) (bool, error) {
|
|||
if len(directionsResp.Routes) < 1 || len(directionsResp.Routes[0].Legs) < 1 || len(directionsResp.Routes[0].Legs[0].Steps) < 1 {
|
||||
} else {
|
||||
latLngPath := make([]string, 0)
|
||||
minLat := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lat
|
||||
maxLat := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lat
|
||||
minLng := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lng
|
||||
maxLng := directionsResp.Routes[0].Legs[0].Steps[0].StartLocation.Lng
|
||||
for _, v := range directionsResp.Routes[0].Legs[0].Steps {
|
||||
if v.StartLocation.Lng < minLng {
|
||||
minLng = v.StartLocation.Lng
|
||||
}
|
||||
if v.StartLocation.Lng > maxLng {
|
||||
maxLng = v.StartLocation.Lng
|
||||
}
|
||||
if v.StartLocation.Lat < minLat {
|
||||
minLat = v.StartLocation.Lat
|
||||
}
|
||||
if v.StartLocation.Lat > maxLat {
|
||||
maxLat = v.StartLocation.Lat
|
||||
}
|
||||
latLngPath = append(latLngPath, fmt.Sprintf("%.9f,%.9f", v.StartLocation.Lat, v.StartLocation.Lng))
|
||||
}
|
||||
pathQuery := strings.Join(latLngPath, "|")
|
||||
uri := fmt.Sprintf(maps.PathedURIFormat, pathQuery, pickup, dropoff)
|
||||
uri := fmt.Sprintf(maps.Pathed.PathedURIFormat, pathQuery, pickup, dropoff)
|
||||
// if the bigger delta is <acceptable, override zoom
|
||||
if maxLat-minLat <= maps.Pathed.Zoom.AcceptableLatLngDelta && maxLng-minLng <= maps.Pathed.Zoom.AcceptableLatLngDelta {
|
||||
uri = fmt.Sprintf("%s&zoom=%d", uri, maps.Pathed.Zoom.Override)
|
||||
}
|
||||
log.Printf("sending pathed image: %s", uri)
|
||||
if err := sender.SendImage(uri); err != nil {
|
||||
return true, err
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func (m *Matrix) Receive() ([]Message, error) {
|
|||
log.Printf("matrix.Receive()")
|
||||
messages := make([]Message, 0)
|
||||
for k := range config.Get().Clients {
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!state OH"})
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!state nc"})
|
||||
if k == "bel" {
|
||||
messages = append(messages, Message{Timestamp: time.Now(), Sender: k, Content: "!help"})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
todo:
|
||||
- TEST its falling apart;; mock is nigh useless
|
||||
- TEST its falling apart
|
||||
- figure out zoom on maps;; is there like an auto-zoom I can leverage?
|
||||
- mark jobs no longer avail by modifying in matrix
|
||||
- write-as for clients so ma can write to pa by default
|
||||
|
|
@ -15,6 +15,7 @@ todo:
|
|||
- banlist criteria like vendors, brokers, metadata
|
||||
- set up copy for caleb, broc
|
||||
done:
|
||||
- mock is nigh useless
|
||||
- mark consumed;; save scroll id for matrix
|
||||
- todo: switch house to selfhosted for rate limit
|
||||
tags: now
|
||||
|
|
|
|||
Loading…
Reference in New Issue