示例#1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // initialize orientation (used later when determine if map view requires update)
            _priorOrientation = ApplicationView.Value;

            // register data callback for sharing
            var dtm = DataTransferManager.GetForCurrentView();

            dtm.DataRequested += LeftPanel.GetSharedData;

            // Navigate to new destination
            if (e.NavigationMode == NavigationMode.New)
            {
                LatLong destination;
                LatLong.TryParse(e.Parameter as String, out destination);

                GotoLocation(destination, showMessage: !_firstRun);
            }
            else
            {
                // refresh the point-of-interest list given coordinates saved in page state.  Note that Refresh is async, but
                // we are not awaiting it to lessen risk that a resume operation will timeout
                if (_pageState.MapBox != null)
                {
                    LeftPanel.Refresh(_pageState.MapBox, _pageState.SelectedItemId);
                }

                // reset map to last known view
                _retainRefreshRequiredViewChange = true;
                TheMap.SetView(new Location(_pageState.MapCenter.Latitude, _pageState.MapCenter.Longitude), _pageState.Zoom, MapAnimationDuration.None);
            }
        }
示例#2
0
        /// <summary>
        /// Fires when map panning is complete, and the current bounds of the map can be accessed to apply the points of interest
        /// (note that using TargetBounds in lieu of the event handler led to different results for the same target location depending on
        /// the visibilty of the map at the time of invocation - i.e., a navigation initiated from the search results pages reported sligthly
        /// offset TargetBounds
        /// </summary>
        async void TheMap_ViewChangeEndedWithRefreshNeeded(object sender, ViewChangeEndedEventArgs e)
        {
            // refresh the left panel to reflect points of interest in current view
            await LeftPanel.Refresh(new BoundingBox(TheMap.TargetBounds.North, TheMap.TargetBounds.South, TheMap.TargetBounds.West, TheMap.TargetBounds.East));

            // unregister the handler
            TheMap.ViewChangeEnded -= TheMap_ViewChangeEndedWithRefreshNeeded;
        }
示例#3
0
        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);

            // unregister data callback for sharing
            var dtm = DataTransferManager.GetForCurrentView();

            dtm.DataRequested -= LeftPanel.GetSharedData;

            // stop the autorefresh of the cameras since we're navigating away from the page
            LeftPanel.StopRefreshing();
        }
示例#4
0
        public MainPage()
        {
            this.InitializeComponent();

            // view model
            this.DefaultViewModel["PendingRefresh"] = false;

            // check to see if this is the first time application is being executed by checking for data in local settings.
            // After checking add some notional data as marker for next time app is run. This will be used to determine whether
            // to prompt the user (or not) that location services are not turned on for the app/system. Without this check, the
            // first time the app is run, it will provide a system prompt, and if that prompt is dismissed without granting
            // access the propmpt displayed by the application would also appear unnecessarily.
            _firstRun = ApplicationData.Current.LocalSettings.Values.Count == 0;
            if (_firstRun)
            {
                ApplicationData.Current.LocalSettings.Values.Add(
                    new System.Collections.Generic.KeyValuePair <string, object>("InitialRunDate", DateTime.UtcNow.ToString()));
            }

            this.SizeChanged += (s, e) =>
            {
                // determine if there's been a change in orientation that doesn't require notice that the map view has changed (e.g., app open, snapped mode transitions)
                if (_priorOrientation == ApplicationView.Value)
                {
                    return;
                }

                _noRefreshRequiredViewChange = (_priorOrientation == ApplicationViewState.Snapped || ApplicationView.Value == ApplicationViewState.Snapped);
                _priorOrientation            = ApplicationView.Value;

                VisualStateManager.GoToState(LeftPanel, ApplicationView.Value.ToString(), true);
            };

            // whenever map view changes track center point and zoom level in page state
            TheMap.ViewChangeEnded += (s, e) =>
            {
                // save new center/zoom for page state
                _pageState.MapCenter = new LatLong(TheMap.TargetCenter.Latitude, TheMap.TargetCenter.Longitude);
                _pageState.Zoom      = TheMap.TargetZoomLevel;

                // ViewChangeEnded fires a bit too often, so retain bounding box to determine if the view truly has changed
                BoundingBox thisBox = new BoundingBox(TheMap.TargetBounds.North, TheMap.TargetBounds.South,
                                                      TheMap.TargetBounds.West, TheMap.TargetBounds.East);

                // determine if view change should notify user of pending refresh requirement
                if (_retainRefreshRequiredViewChange)
                {
                    this.DefaultViewModel["PendingRefresh"] = _pageState.PendingRefresh;
                }
                else if (_noRefreshRequiredViewChange)
                {
                    this.DefaultViewModel["PendingRefresh"] = false;
                }
                else if (App.InitialMapResizeHasOccurred)
                {
                    this.DefaultViewModel["PendingRefresh"] = (thisBox != _lastBox);
                }

                // update state variables
                _lastBox = thisBox;
                if (App.InitialMapResizeHasOccurred)
                {
                    _noRefreshRequiredViewChange = false;
                }
                _retainRefreshRequiredViewChange = false;
                App.InitialMapResizeHasOccurred  = true;
            };

            // if refresh prompt is tapped, refresh the map
            RefreshPrompt.Tapped += async(s, e) =>
            {
                await LeftPanel.Refresh(_lastBox);

                this.DefaultViewModel["PendingRefresh"] = false;
            };

            // a tap on map will cause refresh is one is predicated
            TheMap.Tapped += async(s, e) =>
            {
                if ((Boolean)this.DefaultViewModel["PendingRefresh"])
                {
                    await LeftPanel.Refresh(_lastBox);

                    this.DefaultViewModel["PendingRefresh"] = false;
                }
            };

            // set the reference to the current map for the LeftPanel (note: using Element binding will not handle all of the page navigation scenarios)
            LeftPanel.Map = TheMap;

            // whenever the contents of left panel are refreshed, save the map coordinates that were in play as part of the page state
            LeftPanel.Refreshed += (s, e) =>
            {
                _pageState.MapBox = new BoundingBox(TheMap.TargetBounds.North, TheMap.TargetBounds.South, TheMap.TargetBounds.West, TheMap.TargetBounds.East);
            };

            // whenver a new item is selected in the left panel, update the map pins and save the item selected as part of the page state
            LeftPanel.ItemSelected += (s, e) =>
            {
                TheMap.HighlightPointOfInterestPin(e.NewItem, true);
                TheMap.HighlightPointOfInterestPin(e.OldItem, false);

                this._pageState.SelectedItemId = e.NewItem == null ? null : e.NewItem.Id;
            };

            // whenever a new location is selected from the SearchFlyout (this is NOT the Search charm) update the position accordingly
            SearchFlyout.LocationChanged += (s, e) =>
            {
                GotoLocation(e.Position);
                SearchFlyout.Hide();
            };

            // manage SearchFlyout visibility/interaction
            this.Tapped += (s, e) =>
            {
                if (SearchFlyout.IsOpen)
                {
                    SearchFlyout.Hide();
                    e.Handled = true;
                }
            };
            BottomAppBar.Opened += (s, e) => { SearchFlyout.Hide(); };
            SearchFlyout.Tapped += (s, e) => { e.Handled = true; };

            // allow type-to-search for Search charm
            SearchPane.GetForCurrentView().ShowOnKeyboardInput = true;

            // The BingMaps API allows use of a "session key" if the application leverages the Bing Maps control. By using the session
            // key instead of the API key, only one transaction is logged agains the key versus one transaction for every API call! This
            // code sets the key asynchronously and stored it as a resource so it's available when the REST API's are invoked.
            TheMap.Loaded += async(s, e) =>
            {
                if (!Application.Current.Resources.ContainsKey("BingMapsSessionKey"))
                {
                    Application.Current.Resources.Add("BingMapsSessionKey", await TheMap.GetSessionIdAsync());
                }
            };
        }
示例#5
0
 private async void Refresh_Click(object sender, RoutedEventArgs e)
 {
     await LeftPanel.Refresh(new BoundingBox(TheMap.TargetBounds.North, TheMap.TargetBounds.South,
                                             TheMap.TargetBounds.West, TheMap.TargetBounds.East));
 }