How to change the mapmode of RadMap's mapprovider?

4 posts, 0 answers
  1. Jimmy
    Jimmy avatar
    24 posts
    Member since:
    Nov 2006

    Posted 07 Feb 2012 Link to this post

    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);
    }
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 09 Feb 2012 Link to this post

    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 >>
  3. DevCraft banner
  4. Jimmy
    Jimmy avatar
    24 posts
    Member since:
    Nov 2006

    Posted 13 Feb 2012 Link to this post

    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!
    
    
    
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 15 Feb 2012 Link to this post

    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 >>
Back to Top