/// <summary> /// Add shortcut if the current edge is one. /// </summary> private bool AddShortcut(RoutingEdge edge, CancellationToken cancellationToken) { // when both are just regular vertices, this could be a shortcut. var edgeProfile = _routerDb.EdgeProfiles.Get(edge.Data.Profile); var shortcutName = string.Empty; if (edgeProfile.IsShortcut(out shortcutName)) { // ok profile is a shortcut, get the actual path, expand and build route. ShortcutsDb shortcutsDb; if (_routerDb.TryGetShortcuts(shortcutName, out shortcutsDb)) { var shortcutProfile = _routerDb.GetSupportedProfile(shortcutsDb.ProfileName); IAttributeCollection shortcutMeta; var shortcut = shortcutsDb.Get(edge.From, edge.To, out shortcutMeta); if (shortcut != null && shortcut.Length >= 2) { try { var route = CompleteRouteBuilder1.Build(_routerDb, shortcutProfile, _routerDb.CreateRouterPointForVertex(shortcut[0], shortcutProfile, _profile), _routerDb.CreateRouterPointForVertex(shortcut[shortcut.Length - 1], shortcutProfile, _profile), new List <uint>(shortcut), cancellationToken); if (shortcutMeta == null) { shortcutMeta = new AttributeCollection(); } shortcutMeta.AddOrReplace(ShortcutExtensions.SHORTCUT_KEY, shortcutName); this.AppendRoute(route, shortcutMeta); } catch (Exception ex) { throw new Exception("Could not build shortcut route.", ex); } return(true); } } } return(false); }
/// <summary> /// Builds a route. /// </summary> public static Route Build(RouterDb db, Profile profile, RouterPoint source, RouterPoint target, List <uint> path) { return(CompleteRouteBuilder1.Build(db, profile, source, target, path, CancellationToken.None)); }