示例#1
0
        /// <summary>
        /// The map search box got the mouse focus.
        /// </summary>
        /// <param name="Sender">The sender of the event.</param>
        /// <param name="RoutedEventArgs">The event parameters.</param>
        private void MapSearchBox_GotFocus(Object Sender, RoutedEventArgs RoutedEventArgs)
        {
            MapSearchBorder.Background  = new SolidColorBrush(Colors.White);
            MapSearchBorder.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x77, 0x77, 0x77));
            MapSearchBox.Foreground     = new SolidColorBrush(Colors.Black);

            if (MapSearchBox.Text == MapSearchBoxText)
            {
                MapSearchBox.Clear();
            }
        }
示例#2
0
        /// <summary>
        /// Process any text entered into the MapSearchBox
        /// </summary>
        /// <param name="Sender">The sender of the event.</param>
        /// <param name="KeyEventArgs">The event parameters.</param>
        private void MapSearchBox_ProcessInput(Object Sender, KeyEventArgs KeyEventArgs)
        {
            switch (KeyEventArgs.Key)
            {
                #region Esc pressed => clear map search box

            case Key.Escape:
                MapSearchBox.Clear();
                MapSearchBorder.Background = new SolidColorBrush(Colors.White);
                break;

                #endregion

                #region Enter pressed => zoom map

            case Key.Enter:

                #region Process a "latitude, longitude" input

                var TextArray = MapSearchBox.Text.Split(new String[3] {
                    " ", ",", "."
                }, StringSplitOptions.RemoveEmptyEntries);

                Double latitude, longitude;
                UInt32 zoomlevel;

                if (TextArray.Length == 4)
                {
                    if (Double.TryParse(TextArray[0] + "," + TextArray[1], out latitude))
                    {
                        if (latitude >= -90 && latitude <= 90)
                        {
                            if (Double.TryParse(TextArray[2] + "," + TextArray[3], out longitude))
                            {
                                if (longitude >= -90 && longitude <= 90)
                                {
                                    MapControl.MoveTo(new Latitude(latitude), new Longitude(longitude));
                                    MapSearchBox_LostFocus(this, null);
                                    MapControl.Focus();
                                    return;
                                }
                            }
                        }
                    }

                    MapSearchBorder.Background = new SolidColorBrush(Color.FromArgb(0x77, 0xFF, 0x00, 0x00));
                }

                #endregion

                #region Process a "latitude, longitude, zoomlevel" input

                if (TextArray.Length == 5)
                {
                    if (Double.TryParse(TextArray[0] + "," + TextArray[1], out latitude))
                    {
                        if (latitude >= -90 && latitude <= 90)
                        {
                            if (Double.TryParse(TextArray[2] + "," + TextArray[3], out longitude))
                            {
                                if (longitude >= -90 && longitude <= 90)
                                {
                                    if (UInt32.TryParse(TextArray[4], out zoomlevel))
                                    {
                                        if (zoomlevel >= eu.Vanaheimr.Aegir.Controls.MapControl.MinZoomLevel &&
                                            zoomlevel <= eu.Vanaheimr.Aegir.Controls.MapControl.MaxZoomLevel)
                                        {
                                            MapControl.ZoomTo(new Latitude(latitude), new Longitude(longitude), zoomlevel);
                                            MapSearchBox_LostFocus(this, null);
                                            MapControl.Focus();
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    MapSearchBorder.Background = new SolidColorBrush(Color.FromArgb(0x77, 0xFF, 0x00, 0x00));
                }

                #endregion

                // Search for a town name...
                MapSearchBorder.Background = new SolidColorBrush(Color.FromArgb(0x77, 0xFF, 0x00, 0x00));

                KeyEventArgs.Handled = true;
                break;

                #endregion
            }
        }