Networked Map Viewer

Map Viewer

This application was made using XNA embedded in a Winforms project. The original tutorial for embedding XNA in Windows Forms can be found here. I needed to make some modifications to the ContentBuilder.cs included with the demo project to allow it to compile shaders and load fonts.

I retrieved the map textures from the Google maps API. The height values were retrieved from the Bing maps API since the limit for maximum number of height queries per day on Bing maps is much higher than Google or many other alternatives. In addition to the benefit of a high limit on queries, the Bing maps API allows me to query height values in a grid by defining the four corners of a patch with latitude and longitude instead of the alternative of querying based on a large list that contains each vertex’s lat/lon.

The main concern when building a mapping application like this was getting the height values retrieved from Bing maps to line up with the textures from Google maps. Google maps receives image requests by taking a single latitude, longitude, and zoom level. The zoom level exponentially shrinks the area of coverage of a map. so if a zoom level 1 covers a 1000x1000km square then zoom level 2 will cover a 500x500km square and the next will cover 250x250km. Bing maps differs in that it takes in a list of four latitudes and longitudes along with two integers specifying the dimensions of the grid to query. Unfortunately it is not quite as easy as querying the center point + half the coverage size of the Google maps tile. This is because we must account for the curvature of the Earth as illustrated in the figure below. This is done by projecting the latitude and longitude from cylindrical space to spherical space using the Mercator projection. This is explained in further detail at Wolfram.

Once I have the latitudes and longitudes of the points that I need to query I create an HttpWebRequest and append the latitude and longitude to the REST API url. I then send off this request in a separate thread so that rendering does not hang while tiles are loading.

Here’s a demo of the application

I have attached the project files below. The included binaries work correctly, however I have omitted my Bing maps API key from the source so if you wish to compile the project and retrieve the height data  you will need to sign up for a key. There are instructions for doing so here.


Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>