1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- using System.Collections;
- namespace ARLocation.MapboxRoutes
- {
- public enum RouteWaypointType
- {
- UserLocation,
- Location,
- Query
- };
- [System.Serializable]
- public class RouteWaypoint
- {
- public RouteWaypointType Type;
- public Location Location = new Location();
- public string Query;
- public override string ToString()
- {
- return "RouteWaypoint{ \n" +
- $"Type = {Type}\n" +
- $"Location = {Location}\n" +
- $"Query = {Query}\n" +
- "}";
- }
- }
- public class RouteWaypointResolveLocation
- {
- public Location result;
- public bool IsError;
- public string ErrorMessage;
- private RouteWaypoint w;
- private MapboxApi api;
- public RouteWaypointResolveLocation(MapboxApi mapboxApi, RouteWaypoint waypoint)
- {
- w = waypoint;
- api = mapboxApi;
- }
- public IEnumerator Resolve()
- {
- switch (w.Type)
- {
- case RouteWaypointType.Location:
- result = w.Location;
- IsError = false;
- ErrorMessage = null;
- yield break;
- case RouteWaypointType.UserLocation:
- result = ARLocationProvider.Instance.CurrentLocation.ToLocation();
- IsError = false;
- ErrorMessage = null;
- yield break;
- case RouteWaypointType.Query:
- yield return api.QueryLocal(w.Query);
- if (api.ErrorMessage != null)
- {
- result = null;
- IsError = true;
- ErrorMessage = api.ErrorMessage;
- }
- else
- {
- result = api.QueryLocalResult.features[0].geometry.coordinates[0];
- IsError = false;
- ErrorMessage = null;
- }
- yield break;
- }
- }
- }
- }
|