Get distance of MapControl border in degrees

為{幸葍}努か 提交于 2019-12-14 02:47:12

问题


I have a MapControl and would like to know how many degrees are currently shown on the x and y axes.

First example:

360 degrees are shown on the x axis (longitude)

~90 degrees are shown on the y axis (latitude)

(The zoom level is 3.2 and it's max zoomed out)

Second example:

~220 degrees on the x axis (longitude)

180 degrees on the y axis (latitude)

(zoom level: 1.7; max zoomed out)

I tried calculating the current degrees on the x axis using following code:

double dist = 360 * Math.Pow(0.5, macSurrounding.ZoomLevel - 1);

but it doesn't work, because the zoom level is just strange...


回答1:


You should use the MapControl's GetLocationFromOffset method to calculate the geographic coordinates of the south-east and north-west corner points of the current map viewport. The width and height of the viewport would be the latitude and longitude differences of these points.

Geopoint northEast;
Geopoint southWest;

map.GetLocationFromOffset(new Point(map.ActualWidth, 0), out northEast);
map.GetLocationFromOffset(new Point(0, map.ActualHeight), out southWest);

var width = northEast.Position.Longitude - southWest.Position.Longitude;
var height = northEast.Position.Latitude - southWest.Position.Latitude;



回答2:


Got it:

Longitude:

360 * Math.Pow(0.5, mcMapControl.ZoomLevel - 1) * mcMapControl.ActualWidth / 409.5;

Latitude:

180 * Math.Pow(0.5, mcMapControl.ZoomLevel - 1) * mcMapControl.ActualHeight / 409.5;


来源:https://stackoverflow.com/questions/34688496/get-distance-of-mapcontrol-border-in-degrees

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!