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

Latitude and Longitude of visible area.

3 Answers 240 Views
Map
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 02 Jul 2012, 03:57 PM
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

3 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 03 Jul 2012, 10:04 AM
I managed to solve my issue. I had set the LatitudesCount and Longtudes count incorrectly on my zoomgrids in each dynamic layer.
0
Maurizio
Top achievements
Rank 2
answered on 05 Jul 2012, 08:14 AM
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
0
Andrey
Telerik team
answered on 09 Jul 2012, 11:56 AM
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 >>

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