RouteWaypoint.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections;
  2. namespace ARLocation.MapboxRoutes
  3. {
  4. public enum RouteWaypointType
  5. {
  6. UserLocation,
  7. Location,
  8. Query
  9. };
  10. [System.Serializable]
  11. public class RouteWaypoint
  12. {
  13. public RouteWaypointType Type;
  14. public Location Location = new Location();
  15. public string Query;
  16. public override string ToString()
  17. {
  18. return "RouteWaypoint{ \n" +
  19. $"Type = {Type}\n" +
  20. $"Location = {Location}\n" +
  21. $"Query = {Query}\n" +
  22. "}";
  23. }
  24. }
  25. public class RouteWaypointResolveLocation
  26. {
  27. public Location result;
  28. public bool IsError;
  29. public string ErrorMessage;
  30. private RouteWaypoint w;
  31. private MapboxApi api;
  32. public RouteWaypointResolveLocation(MapboxApi mapboxApi, RouteWaypoint waypoint)
  33. {
  34. w = waypoint;
  35. api = mapboxApi;
  36. }
  37. public IEnumerator Resolve()
  38. {
  39. switch (w.Type)
  40. {
  41. case RouteWaypointType.Location:
  42. result = w.Location;
  43. IsError = false;
  44. ErrorMessage = null;
  45. yield break;
  46. case RouteWaypointType.UserLocation:
  47. result = ARLocationProvider.Instance.CurrentLocation.ToLocation();
  48. IsError = false;
  49. ErrorMessage = null;
  50. yield break;
  51. case RouteWaypointType.Query:
  52. yield return api.QueryLocal(w.Query);
  53. if (api.ErrorMessage != null)
  54. {
  55. result = null;
  56. IsError = true;
  57. ErrorMessage = api.ErrorMessage;
  58. }
  59. else
  60. {
  61. result = api.QueryLocalResult.features[0].geometry.coordinates[0];
  62. IsError = false;
  63. ErrorMessage = null;
  64. }
  65. yield break;
  66. }
  67. }
  68. }
  69. }