Esempio n. 1
0
        /// <summary>
        /// Get updates from Viewport
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void ViewportPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // Only check, if the Viewport is correct
            if (map.Viewport.Width == 0 || map.Viewport.Height == 0)
            {
                return;
            }

            // Did Center changed?
            if (e.PropertyName.Equals("Center"))
            {
                var centerPosition = map.Viewport.Center.ToForms();

                if (Center.Equals(centerPosition))
                {
                    return;
                }

                Center           = centerPosition;
                LastMoveToRegion = new MapSpan(Center, LastMoveToRegion.LatitudeDegrees, LastMoveToRegion.LongitudeDegrees);

                // We don't need to resend event again
                return;
            }

            // Did Viewport dimensions changed
            if (e.PropertyName.Equals("Width") | e.PropertyName.Equals("Height"))
            {
                // Do this the first time after Viewport has correct size
                if (init)
                {
                    map.NavigateTo(LastMoveToRegion.ToMapsui());
                    init = false;
                }

                // Raise event, that VisibleRegion has changed
                RaisePropertyChanged(nameof(VisibleRegion));

                return;
            }

            // Did Viewport resolution changed
            if (e.PropertyName.Equals("Resolution"))
            {
                var bottomLeft = map.Viewport.Extent.BottomLeft.ToForms();
                var topRight   = map.Viewport.Extent.TopRight.ToForms();

                LastMoveToRegion = new MapSpan(Center, Math.Abs(bottomLeft.Latitude - topRight.Latitude), Math.Abs(bottomLeft.Longitude - topRight.Longitude));
            }

            RaisePropertyChanged(e.PropertyName);
        }
Esempio n. 2
0
        /// <summary>
        /// Methods
        /// </summary>

        /// Change Viewport
        public void MoveToRegion(MapSpan mapSpan)
        {
            LastMoveToRegion = mapSpan ?? throw new ArgumentNullException(nameof(mapSpan));
            map.NavigateTo(LastMoveToRegion.ToMapsui());
        }