Navigation commands

2 posts, 1 answers
  1. Rieni De Rijke
    Rieni De Rijke avatar
    170 posts
    Member since:
    Mar 2010

    Posted 09 Mar 2011 Link to this post

    When we should make our own navigationbuttons, then what kind of command could we write in the on-click-event?

    private void GoEastClick(object sender, RoutedEventArgs e)
    {
        RadMap1.....?
    }
  2. Answer
    Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 14 Mar 2011 Link to this post

    Hi Rieni De Rijke,

    Unfortunately the map control does not have API for navigation commands.
    You can use available API for custom navigation buttons to change center of map or you can fire appropriate KeyDown events which will be processed by map control.
    The sample code is below.

    private void GoEastClick(object sender, RoutedEventArgs e)
    {
        this.RaiseKeyDownEvent(Key.Right);
    }
      
    private void RaiseKeyDownEvent(Key key)
    {
        KeyEventArgs keyEventArgs = new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(this.radMap), 0, key);
        keyEventArgs.RoutedEvent = UIElement.KeyDownEvent;
        this.radMap.RaiseEvent(keyEventArgs);
    }



    private void GoEastClick(object sender, RoutedEventArgs e)
    {
        this.MoveCenterByKey(Key.Right);
    }
      
    private void MoveCenterByKey(Key key)
    {
        Point pixelCenter = this.RecenterByKey(key);
        this.radMap.Center = Location.GetCoordinates(this.radMap, pixelCenter);
    }
      
    private Point RecenterByKey(Key key)
    {
        Point adjustmentFactor = new Point(this.ActualWidth / 3, this.ActualHeight / 3);
        Point pixelCenter = Location.LogicalToPixel(this.radMap, this.radMap.SpatialReference.GeographicToLogical(this.radMap.Center));
      
        switch (key)
        {
            case Key.Left:
                pixelCenter.X -= adjustmentFactor.X;
                break;
      
            case Key.Right:
                pixelCenter.X += adjustmentFactor.X;
                break;
      
            case Key.Up:
                pixelCenter.Y -= adjustmentFactor.Y;
                break;
      
            case Key.Down:
                pixelCenter.Y += adjustmentFactor.Y;
                break;
        }
      
        return pixelCenter;
    }

    All the best,
    Andrey Murzov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top