# Zoom to Fit Points on Surface

I'm attempting to develop a piece of functionality using a 3rd party map control in an application that automatically pans/zooms the map surface to the best possible view given points on map. The map should be centered and zoomed in as close as possible without cutting out any points on the map.

To determine the maps center point, I averaged all of the points on the map surface. This seems to be working fine, but there may be a better approach. The issue I'm running into is how to appropriately zoom in or out to accommodate all points on the map in the "best" possible view.

I'm not very familiar with 3D techniques, so any terminology relating to this problem will probably be new to me. I'm not necessarily looking for a specific algorithm (though I certainly wouldn't turn one down). Mostly, I would like to understand the theory behind approaching such a problem so that I can implement it.

-
This is probably a better topic for stackoverflow. – Throwback1986 Sep 27 '11 at 15:35
Do you know what projection the third party software uses? Is it displaying rectangular tiles of a fixed latitude and longitude or doing an actual 3D projection of the sphere? (The easy way to tell is to try to centre on a pole - the former rendering method won't let you). – Peter Taylor Sep 27 '11 at 15:38
Could you give some example of what are you trying to accomplish specifically? – Rook Sep 27 '11 at 15:48
@PeterTaylor I'm afraid I'm not sure. I'm using the Telerik RadMap control for WPF if that helps: telerik.com/products/wpf/map.aspx – senfo Sep 27 '11 at 16:07

## 1 Answer

I'm not sure what this question has to do with 3D. I'm assuming you're specifying points in 2 dimensions: latitude and longitude.

Just find the max and min latitude and longitude among all the points. The smallest box that contains them all is (min lat, min long), (min lat, max long), (max lat, max long), (max lat, min long). That's assuming relatively local points not near the international date line or the poles.

Let's say your points are (1,5), (2,8), and (3,2). Your minimum latitude is 1, max latitude is 3, min longitude is 2, max longitude is 8. The smallest bounding box is (1, 2), (1, 8), (3, 8), (3, 2). Give yourself a little margin so the points aren't right on the edge, and you're good.

-
Karl, try working out the shortest distance between St. Petersburg and Vladivostok, to see why this is a 3D issue. (The USA is smaller and further south than Russia, but similar considerations apply on large scales). – Mark Bannister Sep 27 '11 at 17:37
@Mark: It's a 2D problem, but in projected coordinates, not lat-long space. Choosing the right map projection may be a 3D problem, but I think it's really more a UI design problem. – kevin cline Sep 27 '11 at 18:29