Ejemplo n.º 1
0
        public ShowFestaMap(IRepository <MapRegion> mapRep,
                            IRepository <Exhibition> exhibitionRep,
                            IRepository <StageEvent> stageEventRep,
                            IRepository <Stall> stallRep,
                            IEventAggregator eventAggregator,
                            IMapAssociated mapAssociated)
        {
            _mapRepository       = mapRep;
            _exhiitionRepository = exhibitionRep;
            _stageRepository     = stageEventRep;
            _stallRepository     = stallRep;
            _eventAggregator     = eventAggregator;
            _mapAssociated       = mapAssociated;

            Pins     = new ReadOnlyObservableCollection <Pin>(_pins);
            Polygons = new ReadOnlyObservableCollection <Polygon>(_polygons);
        }
Ejemplo n.º 2
0
        public FestaMapRootPageViewModel(INavigationService navigationService, IEventAggregator eventAggregator, IShowFestaMap showFesta, IMapAssociated mapParam)
        {
            _eventAggregator   = eventAggregator;
            _navigationService = navigationService;
            showFestaUsecase   = showFesta;
            _mapParams         = mapParam;

            InfoWindowClickedCommand = new DelegateCommand <InfoWindowClickedEventArgs>(async(pin) =>
            {
                var region = pin.Pin.Tag as MapRegion;
                if (region == null)
                {
                    return;
                }
                if (IsGlobalMap)
                {
                    if (region.MapObjectType.HasFlag(MapObjectEnum.STAGE))
                    {
                        await _navigationService.NavigateAsync(
                            nameof(StageEventListRootPageViewModel).GetViewNameFromRule(),
                            StageEventListRootPageViewModel.GetNavigationParameter(region.Id, region.Name));
                    }
                    else
                    {
                        var type = region.MapObjectType.HasFlag(MapObjectEnum.EXHIBITION) ? PlanningTypeEnum.EXHIBITION : PlanningTypeEnum.STALL;
                        await _navigationService.NavigateAsync(
                            "RegionSpecificPlanningListPage",
                            PlanningListRootPageViewModel.GetNavigationParameter(region.Id, region.Name, type));
                    }
                }
            });

            _eventAggregator.GetEvent <PolygonClickedEvent>().Subscribe((pin) =>
            {
                SelectedPin.Value = pin.Tag as Pin;
                MoveToRegionRequest.MoveToRegion(
                    MapSpan.FromCenterAndRadius(SelectedPin.Value.Position, Distance.FromMeters(100)));
            }).AddTo(this.Disposable);

            showFesta.Pins.ToCollectionChanged <Pin>()
            .Subscribe(change =>
            {
                switch (change.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    Pins?.Add(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    Pins?.Remove(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    Pins?.Clear();
                    break;
                }
            }).AddTo(this.Disposable);

            showFesta.Polygons.ToCollectionChanged <Polygon>()
            .Subscribe(change =>
            {
                switch (change.Action)
                {
                case System.Collections.Specialized.NotifyCollectionChangedAction.Add:
                    Polygons?.Add(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Move:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Remove:
                    Polygons?.Remove(change.Value);
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Replace:
                    break;

                case System.Collections.Specialized.NotifyCollectionChangedAction.Reset:
                    Polygons?.Clear();
                    break;
                }
            }).AddTo(this.Disposable);

            // For iOS
            _eventAggregator.GetEvent <TabbedPageOpendEvent>().Subscribe((ev) =>
            {
                if (ev.Name != this.GetType().Name.Replace("ViewModel", ""))
                {
                    return;
                }

                IsShowingUser.Value = true;
                showFestaUsecase.InitializeAllMapObjects();
                if (IsGlobalMap)
                {
                    MoveToRegionRequest.MoveToRegion(
                        MapSpan.FromCenterAndRadius(
                            new Position(_mapParams.MapCenterLangitude, _mapParams.MapCenterLongitude),
                            Distance.FromMeters(185)));
                }
            }).AddTo(this.Disposable);

            _eventAggregator.GetEvent <LocationPermissionRequestResultEvent>()
            .Subscribe((ev) =>
            {
                IsShowingUser.Value = ev.Granted;
            });

            Title.AddTo(this.Disposable);
            SelectedPin.AddTo(this.Disposable);
            IsShowingUser.AddTo(this.Disposable);
        }