Ejemplo n.º 1
0
        public DestinationPickPage(string navigationGraphName, CategoryType category)
        {
            InitializeComponent();

            const string resourceId = "IndoorNavigation.Resources.AppResources";

            _resourceManager = new ResourceManager(resourceId, typeof(TranslateExtension).GetTypeInfo().Assembly);

            _destinationItems = new ObservableCollection <DestinationItem>();

            _navigationGraphName = navigationGraphName;

            _navigationGraph = NavigraphStorage.LoadNavigationGraphXML(navigationGraphName);
            if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "en-US")
            {
                _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_en-US.xml");
            }
            else if (CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh" || CrossMultilingual.Current.CurrentCultureInfo.ToString() == "zh-TW")
            {
                _nameInformation = NavigraphStorage.LoadInformationML(navigationGraphName + "_info_zh.xml");
            }

            NavigationPage.SetBackButtonTitle(this, _resourceManager.GetString("BACK_STRING", CrossMultilingual.Current.CurrentCultureInfo));

            foreach (KeyValuePair <Guid, IndoorNavigation.Models.Region> pairRegion in _navigationGraph.GetRegions())
            {
                string floorName = _nameInformation.GiveRegionName(pairRegion.Value._id);
                if (pairRegion.Value._waypointsByCategory.ContainsKey(category))
                {
                    foreach (Waypoint waypoint in pairRegion.Value._waypointsByCategory[category])
                    {
                        string waypointName = waypoint._name;
                        waypointName = _nameInformation.GiveWaypointName(waypoint._id);
                        if (waypoint._type.ToString() == "terminal" || waypoint._type.ToString() == "landmark")
                        {
                            Console.WriteLine("check type : " + waypoint._type.ToString());
                            _destinationItems.Add(new DestinationItem
                            {
                                _regionID     = pairRegion.Key,
                                _waypointID   = waypoint._id,
                                _waypointName = waypointName,
                                _floor        = floorName
                            });
                        }
                        else
                        {
                            Console.WriteLine("Portal, No need to add!!");
                        }
                    }
                }
            }

            MyListView.ItemsSource = from waypoint in _destinationItems
                                     group waypoint by waypoint._floor into waypointGroup
                                     orderby waypointGroup.Key
                                     select new Grouping <string, DestinationItem>(waypointGroup.Key,
                                                                                   waypointGroup);
        }
        private void SetInstruction(NavigationInstruction instruction,
                                    out string stepLabel,
                                    out string stepImage,
                                    out string firstDirectionImage,
                                    out int rotation,
                                    out int location,
                                    out int instructionValue)
        {
            var    currentLanguage      = CrossMultilingual.Current.CurrentCultureInfo;
            string connectionTypeString = "";
            string nextWaypointName     = instruction._nextWaypointName;

            nextWaypointName = _xmlInformation.GiveWaypointName(instruction._nextWaypointGuid);
            string nextRegionName = instruction._information._regionName;

            firstDirectionImage = null;
            rotation            = 0;
            stepImage           = "";
            instructionValue    = _originalInstructionScale;
            location            = _originalInstructionLocation;
            nextRegionName      = _xmlInformation.GiveRegionName(instruction._nextRegionGuid);
            switch (instruction._information._turnDirection)
            {
            case TurnDirection.FirstDirection:
                string            firstDirection_Landmark  = _firstDirectionInstruction.returnLandmark(instruction._currentWaypointGuid);
                CardinalDirection firstDirection_Direction = _firstDirectionInstruction.returnDirection(instruction._currentWaypointGuid);
                int    faceDirection          = (int)firstDirection_Direction;
                int    turnDirection          = (int)instruction._information._relatedDirectionOfFirstDirection;
                string initialDirectionString = "";
                int    directionFaceorBack    = _firstDirectionInstruction.returnFaceOrBack(instruction._currentWaypointGuid);

                if (faceDirection > turnDirection)
                {
                    turnDirection = (turnDirection + 8) - faceDirection;
                }
                else
                {
                    turnDirection = turnDirection - faceDirection;
                }

                if (directionFaceorBack == _initialFaceDirection)
                {
                    initialDirectionString = _resourceManager.GetString(
                        "DIRECTION_INITIAIL_FACE_STRING",
                        currentLanguage);
                }
                else if (directionFaceorBack == _initialBackDirection)
                {
                    initialDirectionString = _resourceManager.GetString(
                        "DIRECTION_INITIAIL_BACK_STRING",
                        currentLanguage);
                    if (turnDirection < 4)
                    {
                        turnDirection = turnDirection + 4;
                    }
                    else if (turnDirection >= 4)
                    {
                        turnDirection = turnDirection - 4;
                    }
                }
                string instructionDirection = "";
                string stepImageString      = "";

                CardinalDirection cardinalDirection = (CardinalDirection)turnDirection;
                switch (cardinalDirection)
                {
                case CardinalDirection.North:
                    instructionDirection = _resourceManager.GetString(
                        "GO_STRAIGHT_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_up";
                    break;

                case CardinalDirection.Northeast:
                    instructionDirection = _resourceManager.GetString(
                        "GO_RIGHT_FRONT_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_frontright";
                    break;

                case CardinalDirection.East:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_RIGHT_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_right";
                    break;

                case CardinalDirection.Southeast:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_RIGHT_REAR_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_rearright";
                    break;

                case CardinalDirection.South:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_BACK_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_down";
                    break;

                case CardinalDirection.Southwest:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_RIGHT_REAR_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_rearleft";
                    break;

                case CardinalDirection.West:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_LEFT_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_left";
                    break;

                case CardinalDirection.Northwest:
                    instructionDirection = _resourceManager.GetString(
                        "TURN_LEFT_FRONT_STRING",
                        currentLanguage);
                    stepImageString = "Arrow_frontleft";
                    break;
                }
                if (instruction._previousRegionGuid != Guid.Empty && instruction._previousRegionGuid != instruction._currentRegionGuid)
                {
                    stepLabel = string.Format(
                        _resourceManager.GetString(
                            "DIRECTION_INITIAIL_CROSS_REGION_STRING",
                            currentLanguage),
                        instructionDirection,
                        Environment.NewLine,
                        nextWaypointName,
                        Environment.NewLine,
                        instruction._information._distance);
                    stepImage = stepImageString;
                    break;
                }
                else if (firstDirection_Landmark == _pictureType)
                {
                    string pictureName;

                    string regionString   = instruction._currentRegionGuid.ToString();
                    string waypointString = instruction._currentWaypointGuid.ToString();

                    pictureName = _navigationGraph.GetBuildingName() + regionString.Substring(33, 3) + waypointString.Substring(31, 5);

                    stepLabel = string.Format(
                        initialDirectionString,
                        _resourceManager.GetString(
                            "PICTURE_DIRECTION_STRING",
                            currentLanguage),
                        Environment.NewLine,
                        instructionDirection,
                        Environment.NewLine,
                        nextWaypointName,
                        " ",
                        instruction._information._distance);
                    firstDirectionImage = pictureName;
                    stepImage           = stepImageString;
                    rotation            = 75;
                    location            = _firstDirectionInstructionLocation;
                    instructionValue    = _firstDirectionInstructionScale;
                    break;
                }
                else
                {
                    stepLabel = string.Format(
                        initialDirectionString,
                        firstDirection_Landmark,
                        Environment.NewLine,
                        instructionDirection,
                        Environment.NewLine,
                        nextWaypointName,
                        Environment.NewLine,
                        instruction._information._distance);
                    stepImage = stepImageString;
                    break;
                }

            case TurnDirection.Forward:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_STRAIGHT_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_up";

                break;

            case TurnDirection.Forward_Right:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_RIGHT_FRONT_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_frontright";

                break;

            case TurnDirection.Right:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_RIGHT_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_right";

                break;

            case TurnDirection.Backward_Right:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_RIGHT_REAR_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_rearright";

                break;

            case TurnDirection.Backward:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_REAR_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_down";

                break;

            case TurnDirection.Backward_Left:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_LEFT_REAR_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_rearleft";

                break;

            case TurnDirection.Left:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_LEFT_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_left";

                break;

            case TurnDirection.Forward_Left:
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_LEFT_FRONT_STRING",
                        currentLanguage),
                    Environment.NewLine,
                    instruction._information._distance,
                    Environment.NewLine,
                    nextWaypointName);
                stepImage = "Arrow_frontleft";

                break;

            case TurnDirection.Up:
                switch (instruction._information._connectionType)
                {
                case ConnectionType.Elevator:
                    connectionTypeString = _resourceManager.GetString("ELEVATOR_STRING", currentLanguage);
                    stepImage            = "Elevator_up";
                    break;

                case ConnectionType.Escalator:
                    connectionTypeString = _resourceManager.GetString("ESCALATOR_STRING", currentLanguage);
                    stepImage            = "Stairs_up";
                    break;

                case ConnectionType.Stair:
                    connectionTypeString = _resourceManager.GetString("STAIR_STRING", currentLanguage);
                    stepImage            = "Stairs_up";
                    break;

                case ConnectionType.NormalHallway:
                    connectionTypeString = _resourceManager.GetString("NORMALHALLWAY_STRING", currentLanguage);
                    stepImage            = "Stairs_up";
                    break;
                }
                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_UP_STRING",
                        currentLanguage),
                    connectionTypeString,
                    Environment.NewLine,
                    nextRegionName);
                break;

            case TurnDirection.Down:
                switch (instruction._information._connectionType)
                {
                case ConnectionType.Elevator:
                    connectionTypeString = _resourceManager.GetString("ELEVATOR_STRING", currentLanguage);
                    stepImage            = "Elevtor_down";
                    break;

                case ConnectionType.Escalator:
                    connectionTypeString = _resourceManager.GetString("ESCALATOR_STRING", currentLanguage);
                    stepImage            = "Stairs_down";
                    break;

                case ConnectionType.Stair:
                    connectionTypeString = _resourceManager.GetString("STAIR_STRING", currentLanguage);
                    stepImage            = "Stairs_down";
                    break;

                case ConnectionType.NormalHallway:
                    connectionTypeString = _resourceManager.GetString("NORMALHALLWAY_STRING", currentLanguage);
                    stepImage            = "Stairs_down";
                    break;
                }

                stepLabel = string.Format(
                    _resourceManager.GetString(
                        "DIRECTION_DOWN_STRING",
                        currentLanguage),
                    connectionTypeString,
                    Environment.NewLine,
                    nextRegionName);
                break;

            default:
                stepLabel = "You're get ERROR status";
                stepImage = "Warning";
                break;
            }
        }