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

Conditional show context menu based on zoom level

1 Answer 82 Views
Map
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 19 Jun 2012, 07:45 PM
Hi..
How can I conditional show/enable a context menu when the zoom level is a certain value.
I'd like to add a context menu to a pushpin when the pushpin is in view and zoomlevel = 15
thanks again

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 22 Jun 2012, 08:04 AM
Hi Jon,

I think you just can handle the RadMap.MouseRightButtonUp event. When the event occurs then you can check the zoom level and the pushpin which has been clicked. And when the zoom level does not satisfy a condition then you can mark event as handled using the Handled property of event arguments. It prevents showing of a context menu.
The sample code is below.
<telerik:RadMap x:Name="RadMap1" ZoomLevel="14" Center="40,-100" MouseRightButtonUp="MapMouseRightButtonUp">
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu>
            <telerik:RadMenuItem Header="Menu Item 1" />
            <telerik:RadMenuItem Header="Menu Item 2" />
            <telerik:RadMenuItem Header="Menu Item 3" />
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
    <telerik:RadMap.Provider>
        <telerik:OpenStreetMapProvider />
    </telerik:RadMap.Provider>
    <telerik:InformationLayer x:Name="InformationLayer">
        <telerik:Pushpin telerik:MapLayer.Location="40,-100" />
    </telerik:InformationLayer>
</telerik:RadMap>

private Pushpin clickedPushpin;
 
private void MapMouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
    if (this.RadMap1.ZoomLevel == 15)
    {
        Location location = Location.GetCoordinates(this.RadMap1, e.GetPosition(this.RadMap1));
        IEnumerable<object> list = this.InformationLayer.GetItemsInLocation(location);
        foreach (object item in list)
        {
            Pushpin pushpin = item as Pushpin;
            if (pushpin != null)
            {
                this.clickedPushpin = pushpin;
                return;
            }
        }
    }
 
    e.Handled = true;
}

All the best,
Andrey Murzov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Map
Asked by
Jon
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or