This is a migrated thread and some comments may be shown as answers.

DynamicLayer + MapPinPoint = handling event problem

1 Answer 83 Views
Map
This is a migrated thread and some comments may be shown as answers.
drLich
Top achievements
Rank 1
drLich asked on 20 May 2011, 06:22 PM
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).

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 25 May 2011, 09:06 AM
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
Tags
Map
Asked by
drLich
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or