set up override zoom if both lat and lng within delta
This commit is contained in:
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
|
||||
|
||||
Reference in New Issue
Block a user