Zomm to a Location

5 posts, 0 answers
  1. Vidyadhar
    Vidyadhar avatar
    23 posts
    Member since:
    Oct 2011

    Posted 16 Mar 2012 Link to this post

    Hi,

    I have A RadDocking window with two RadSplitContainers. Each RadSplitContainer has one RadPaneGroup with one RadPane in it.
    One RadPane has a TreeView and the other has a RadMap.
    The TreeView has some TreeNodes.I have a RadContextMenu created on each node, with a "Zoom to Location" RadMenuItem. When I click this RadMenuItem, I can retrieve the "Latitude" and "Longitude" of a Location from the node, and I want the Map in another RadPane to zoom to that Location automatically to zoom level 6 (Am using 3 zoom levels for the map 5,6 and 7). How can this be achieved? 

    Am using Silverlight 5 with MVVM pattern.

    Thanks in Advance,
    Viddy.
  2. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 22 Mar 2012 Link to this post

    Hello Vidyadhar,

    You should use Center and ZoomLevel properties of the RadMap control (see details here http://www.telerik.com/help/silverlight/radmap-features-navigation.html).

    All the best,
    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. Vidyadhar
    Vidyadhar avatar
    23 posts
    Member since:
    Oct 2011

    Posted 22 Mar 2012 Link to this post

    Hi Andrey,
    Thanks for the reply.

    I did try setting those properties, but no luck. Couldn't get the map to Zoom in or change its Center. Please have a look at the code below and let me know where am I going wrong. Am using my own custom MapProvider, am not sure if that has to do anything with it. Am attaching my MapProvider code, just in case.

    XAML:

    <telerik:RadMap Name="RadMap1" ZoomLevel="{Binding Path=CurrentZoomLevel,Mode=TwoWay}" MinZoomLevel="{Binding Path=MinZoomLevel,Mode=TwoWay}" MaxZoomLevel="{Binding Path=MaxZoomLevel,Mode=TwoWay}" 
                            GeoBoundsNW="55.7,-131.0" GeoBoundsSE="27.2,-90.4" MouseClickMode="None"                         
                            Provider="{Binding Path=MyRadMapProvider,Mode=TwoWay}" Center="{Binding Path=MyRadMapCenter,Mode=TwoWay}" InitializeCompleted="RadMap1_InitializeCompleted"  />

    ViewModel Properties:

            private int _zoomLevel;
            public int CurrentZoomLevel
            {
                get { return _zoomLevel; }
                set
                {
                    _zoomLevel = value;
                    NotifyPropertyChanged(m => m.CurrentZoomLevel);
                }
            }

            private int _minZoomLevel;
            public int MinZoomLevel
            {
                get { return _minZoomLevel; }
                set
                {
                    _minZoomLevel = value;
                    NotifyPropertyChanged(m => m.MinZoomLevel);
                }
            }

            private int _maxZoomLevel;
            public int MaxZoomLevel
            {
                get { return _maxZoomLevel; }
                set
                {
                    _maxZoomLevel = value;
                    NotifyPropertyChanged(m => m.MaxZoomLevel);
                }
            }

    In Consturctor of my ViewModel:
    MyRadMapCenter = new Location(41.4, -109.5);
                    MyRadMapProvider.GeoBounds = new LocationRect(new Location(55.7, -131.6), new Location(27.0, -90.0));
                    CurrentZoomLevel = 5;
                    MinZoomLevel = 5;
                    MaxZoomLevel = 7;

    On a MenuItemClick Event am calling a method called Zoomtolocation:

      private void ZoomToLocation(double lat, double longi)
            {
                //MessageBox.Show("This will zoom the map to the location");
                CurrentZoomLevel = 7;
                MyRadMapCenter = new Location(35.353, -123.553);
                //NotifyPropertyChanged(m => m.CurrentZoomLevel);
                //NotifyPropertyChanged(m=>m.MyRadMapCenter);            
            }
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 23 Mar 2012 Link to this post

    Hi Vidyadhar,

    It is hard to say what is wrong with your application having just the code snippet you provided. I created a simple application which do similar things (zoom to center) but using the OpenStreet map provider. Everything works as expected. Please compare it with your own and let me know if there's anything else I can help you with.

    All the best,
    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 >>
  6. Vidyadhar
    Vidyadhar avatar
    23 posts
    Member since:
    Oct 2011

    Posted 23 Mar 2012 Link to this post

    Hey Andrey,

    It worked. It was a data binding issue. When I fixed the DataContext, it started working.

    Thank You,
    Viddy.
Back to Top
DevCraft banner