From e660f2ef9f9701c5e5312783f1e3b17541a23ca5 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Fri, 14 Jan 2022 11:00:55 -0500 Subject: [PATCH] set up override zoom if both lat and lng within delta --- config.json | 20 +++++++++++++------- config/config.go | 18 ++++++++++++------ main.go | 26 +++++++++++++++++++++++--- message/matrix.go | 2 +- todo.yaml | 3 ++- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/config.json b/config.json index e6d9ce0..6f679d6 100644 --- a/config.json +++ b/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, diff --git a/config/config.go b/config/config.go index c4ffc49..91a4271 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/main.go b/main.go index f11f99e..90f48b2 100644 --- a/main.go +++ b/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