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

How to change the mapmode of RadMap's mapprovider?

3 Answers 141 Views
Map
This is a migrated thread and some comments may be shown as answers.
Jimmy
Top achievements
Rank 1
Jimmy asked on 07 Feb 2012, 08:32 AM
In my xaml file,I have a RadMap control and a RadContextMenu control, I have Bind a BingMapProvider to the radmap Provider,
When click the Item of RadContextMenu control,I want to change the map's mapmode of the Provider.I have wrote this code,but it does not work, how can I do?  
I have upload my test project to the skydrive:
the link:RadMapApp
https://skydrive.live.com/redir.aspx?cid=f0fb1c4281efe663&resid=F0FB1C4281EFE663!128&parid=F0FB1C4281EFE663!126&
authkey=!ACrMTRYYxSQcQbM

the code:
<Grid Background="White">
    <telerik:RadContextMenu.ContextMenu>
        <telerik:RadContextMenu x:Name="RightMenu" cal:Message.Attach="[Event ItemClick]=[Action RightMenu($eventArgs)]">
            <telerik:RadMenuItem Header="Road" />
            <telerik:RadMenuItem Header="Aerial" />
        </telerik:RadContextMenu>
    </telerik:RadContextMenu.ContextMenu>
 
    <telerik:RadMap Name="Map"
                    Margin="0 0 0 0"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    CommandBarVisibility="Collapsed"
                    MouseLocationIndicatorVisibility="Collapsed"
                    NavigationVisibility="Collapsed"
                    Provider="{Binding MapProvider}"
                    ScaleVisibility="Collapsed"
                    ZoomBarPresetsVisibility="Collapsed"
                    ZoomBarVisibility="Collapsed"
                    ZoomLevel="4" />
</Grid>


viewmodel:
private BingMapProvider mapProvider = new BingMapProvider(MapMode.Road, false, "AqKk5lc40_-hQY5SwkvonqQsX3Rj2b-tRN1u30tfJX8CuGqVYo0v_GPQ4kZHgHLx");
 
 
public BingMapProvider MapProvider
{
    get { return mapProvider; }
    set
    {
        mapProvider = value;
        NotifyOfPropertyChange(() => MapProvider);
    }
}
 
private string textValue = "test";
 
public  string TextValue
{
    get { return textValue; }
    set
    {
        textValue = value;
        NotifyOfPropertyChange(() => TextValue);
    }
}
 
 
public void RightMenu(Telerik.Windows.RadRoutedEventArgs e)
{
    string hearder = (e.OriginalSource as RadMenuItem).Header as string;
    switch (hearder)
    {
        case "Road":
            mapProvider = new BingMapProvider(MapMode.Road, false, "AqKk5lc40_-hQY5SwkvonqQsX3Rj2b-tRN1u30tfJX8CuGqVYo0v_GPQ4kZHgHLx");
            textValue = "Road";
            break;
 
        case "Aerial":
            mapProvider = new BingMapProvider(MapMode.Aerial, false, "AqKk5lc40_-hQY5SwkvonqQsX3Rj2b-tRN1u30tfJX8CuGqVYo0v_GPQ4kZHgHLx");
            textValue = "Aerial";
            break;
    }
 
    MessageBox.Show(TextValue);
}

3 Answers, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 09 Feb 2012, 05:07 PM
Hello Jimmy,

In the RightMenu method you are assigning a new provider to the private mapProvider field instead of public MapProvider property. So no PropertyChanged event is raised and binding to the view model doesn't update Provider property of the RadMap control. Actually you don't need to create new instance of the BingMapProvider to change its mode. You can simple use the Mode property of the existing provider.

Regards,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Jimmy
Top achievements
Rank 1
answered on 13 Feb 2012, 08:55 AM
Hello:
    I want to ask how to binging Mode property ?
    I used this code in xaml:
        <telerik:RadMap Name="Map" Margin="0 0 0 0"
                        HorizontalAlignment="Left" VerticalAlignment="Top"
                        Center="30.5,-33.4" CommandBarVisibility="Collapsed"
                        MouseLocationIndicatorVisibility="Collapsed" NavigationVisibility="Collapsed"
                        ScaleVisibility="Collapsed" ZoomBarPresetsVisibility="Collapsed"
                        ZoomBarVisibility="Collapsed" ZoomLevel="4">
            <telerik:RadMap.Provider>
                <telerik:BingMapProvider ApplicationId="AqKk5lc40_-hQY5SwkvonqQsX3Rj2b-tRN1u30tfJX8CuGqVYo0v_GPQ4kZHgHLx" IsLabelVisible="True"
                                         Mode="{Binding BingMapMode}" />
            </telerik:RadMap.Provider>
        </telerik:RadMap>
    and the viewModel, I tried two way:
    1、
        private MapMode bingMapMode = MapMode.Road;
 
        public MapMode BingMapMode
        {
            get { return bingMapMode; }
            set
            {
                bingMapMode = value;
                NotifyOfPropertyChange(() => BingMapMode);
            }
        }
  2、
        private string bingMapMode = "Road";
 
        public string BingMapMode
        {
            get { return bingMapMode; }
            set
            {
                bingMapMode = value;
                NotifyOfPropertyChange(() => BingMapMode);
            }
        }
but all of these does not work, and throw some error!


0
Andrey
Telerik team
answered on 15 Feb 2012, 04:29 PM
Hello Jimmy,

Unfortunately the Mode, IsLabelVisible and ApplicationId properties are not dependency properties. So, the BingMapProvider doesn't support data binding to them.
We have created a PITS issue to implement this feature in future releases of map control. You can track implementation of it using the following link:
http://www.telerik.com/support/pits.aspx#/public/silverlight/9717

Regards,
Andrey Murzov
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Map
Asked by
Jimmy
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Jimmy
Top achievements
Rank 1
Share this question
or