DynamicLayer + MapPinPoint = handling event problem

2 posts, 0 answers
  1. drLich
    drLich avatar
    2 posts
    Member since:
    May 2011

    Posted 20 May 2011 Link to this post

    Hi,
    I have DynamicLayer and ItemsRequest method which returns collection of MapPinPoint. I would like to handle MouseLeftButtonDown event on MapPinPoint which has to show some information on RadMap. What should I do to achieve that?

    I was trying to programmatically add handler for each created MapPinPoint in ItemsRequest method but then I could not access RadMap instance in handler which is in that class (class based on IMapDynamicSource which implements ItemsRequest).

  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 25 May 2011 Link to this post

    Hello drLich,

    When you create the instance of the class which implements the IMapDynamicSource interface then you can reference the instance of class which has access to the RadMap. So, you will have access to the RadMap instance in your handler of mouse event.
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            
    this.dynamicLayer.ZoomGridList.Add(new ZoomGrid(2, 2, 3));
            this.dynamicLayer.ZoomGridList.Add(new ZoomGrid(36, 72, 9));

            
    // set dynamic source
            this.dynamicLayer.DynamicSource = new DynamicSource(this);
        }
        private class DynamicSource : IMapDynamicSource
        {
            private MainPage page;

            
    public DynamicSource(MainPage page)
            {
                this.page = page;
            }

            
    public void ItemsRequest(object sender, ItemsRequestEventArgs e)
            {
                // ...
                pinPoint.MouseLeftButtonDown += new MouseButtonEventHandler(pinPoint_MouseLeftButtonDown);
            }

            
    private void pinPoint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
            {
                RadMap map = this.page.RadMap1;
            }
        }
    }

    Also as an another way you can assign the mouse event handler from the instance of class which has access to the RadMap.
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            
    this.dynamicLayer.ZoomGridList.Add(new ZoomGrid(2, 2, 3));
            this.dynamicLayer.ZoomGridList.Add(new ZoomGrid(36, 72, 9));

            
    // set dynamic source
            this.dynamicLayer.DynamicSource = new DynamicSource(this);
        }

        
    private void pinPoint_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            RadMap map = this.RadMap1;
        }

        
    private class DynamicSource : IMapDynamicSource
        {
            private MainPage page;

            
    public DynamicSource(MainPage page)
            {
                this.page = page;
            }

            
    public void ItemsRequest(object sender, ItemsRequestEventArgs e)
            {
                // ...
                pinPoint.MouseLeftButtonDown += new MouseButtonEventHandler(this.page.pinPoint_MouseLeftButtonDown);
            }
        }
    }


    Best wishes,
    Andrey Murzov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
Back to Top