Latitude and Longitude of visible area.

4 posts, 0 answers
  1. Mark
    Mark avatar
    3 posts
    Member since:
    Apr 2012

    Posted 02 Jul 2012 Link to this post

    Hi,

    Is it possible to get the longitude and latitude of the visible area on screen?

    The scenario is the user has zoomed into a city, I want to be able to get the upper left lat and long, the lower right lat and long and then based on those values go to the database and get all the branches in that area.

    Simplistic code example.

    public void ItemsRequest(object sender, ItemsRequestEventArgs e)
    {
        var dataContext = page.DataContext as MappingViewModel;
        if (dataContext == null)
            return;
     
        //var minZoom = e.MinZoom;
        var upperLeft = e.UpperLeft;
        var lowerRight = e.LowerRight;
         
        var branches = _repository.GetBranches(upperLeft.Latitude, upperLeft.Longitude, lowerRight.Latitude, lowerRight.Longitude);
     
        dataContext.SetBranches(branches, e);
    }

    The problem is that the e.upperLeft and e.LowerRight latitude and longitude values don't seem to represent what is in the visible area.

    Sorry for my lack of understanding, this is the first time I have developed for maps so this may be a really stupid question! :-)

    Regards,
    Mark
  2. Mark
    Mark avatar
    3 posts
    Member since:
    Apr 2012

    Posted 03 Jul 2012 Link to this post

    I managed to solve my issue. I had set the LatitudesCount and Longtudes count incorrectly on my zoomgrids in each dynamic layer.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Maurizio
    Maurizio avatar
    43 posts
    Member since:
    Jan 2012

    Posted 05 Jul 2012 Link to this post

    Hello,

    i have the same problem i want to get the longitude and latitude of the visible area on screen after a Zoom Changed, but i am not using a dynamic layer. Is it possible to get the upperleft Point and lowerright Point of the visible area without using a dynamic layer?

    best regards
  5. Andrey
    Admin
    Andrey avatar
    1681 posts

    Posted 09 Jul 2012 Link to this post

    Hello Mark,

    Since you want to show items in the visible area using for example the click event of a button you can get the visible area using the RadMap.LocationRect property. But as I see from your code you use the Dynamic Layer to show your items on the map. The UpperLeft and LowerRight parameters of event arguments depend on the ZoomGridList you use in your application for the dynamic layer.
    The optimal value for number of the Latitudes and Longitudes in ZoomGridList depends on the viewport (visible area) size of the map control and the min zoom level of the zoom grid.
    I think that the dynamic layer will have best performance when the square size for request will be approximately equal to the viewport size.
    The count could be calculated the following way:
    1. For example the viewport size is 1024x1024.
    2. The map size is 512x512 when the zoom level is 1, 1024x1024 for 2 and 2048x2048 for 3 etc. The map size is calculated as 2 ^ (zoom level + 8).
    3. When the zoom level is 3, then the count could be calculated as 2048 / 1024 = 2. I.e. count is calculated as map size/ viewport size.

    I would recommend using the way of ZoomGridList calculation above for achieving good performance for high zoom levels. The sample code is below.

    int latitudes = (int)(Math.Pow(2, minZoomLlevel + 8) / viewportHeight);
    latitudes = Math.Max(latitudes, 1);
     
    int longitudes = (int)(Math.Pow(2, minZoomLlevel + 8) / viewportWidth);
    longitudes = Math.Max(longitudes, 1);
     
    this.dynamicLayer.ZoomGridList.Add(new ZoomGrid(latitudes, longitudes, minZoomLlevel));

    Greetings,
    Andrey Murzov
    the Telerik team

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

Back to Top