Map Tiles (2) – Sample TileMap

Our last post introduced the concept of map tiles and the benefits for using them in a desktop application. Before using map tiles in XNA, we need to create a sample “TileMap”. Normally, tile maps would be created automatically using some GIS or Mapping program. To gain a better understanding though, we will manually create a set of map tiles using this world map that we have used before:

World Map

The original image from the Wikimedia Commons is over 8 MB in size so we can cut it up in a graphics program and create each tile individually. All tiles will be the same size – 800 pixels wide by 400 pixels tall. Our sample TileMap will have 3 TileSets each a different scale (also referred to as “zoom levels”). They will be numbered from 0 to 2 with 0 being the farthest from ground level.

Read the rest of this entry »

Map Tiles (1) – Introduction

Google Maps ushered in a new era in web mapping: pre-rendered map tiles. Traditionally, web mapping followed a 4-tiered approach for generating map images:

Web Mapping 4 Steps

The benefits in this scenario are obvious. Maps at any scale can be produced and layers of information (e.g. roads, lakes, etc.) can be turned on or off with each map request. Map colors, shapes, and symbols can even be changed between requests. The unlimited possibilities come a cost though of slower rendering because each request requires the raw data to be accessed, combined with other layers, and the returned as a single image.

Read the rest of this entry »

Mapscript and XNA (3)

Continuing with our program that combines Mapserver (via the Mapscript API) and XNA, we next added functionality to the update method our of XNA program. We check for a mouse click to initiate a map pan and also for key presses to zoom in, out and return to full extent. At the end, if any map event has occurred, the map will be updated. It is in the updating that a new Mapserver image is generated and prepared for displaying on-screen.

protected override void Update(GameTime gameTime)
    // check if a mouse click has occured
    if (mouse.LeftButton == ButtonState.Pressed)
        mapserver.ZoomMap(1, mouse.X, mouse.Y);
    // check if a key has been pressed
    KeyboardState keyState = Keyboard.GetState();
    if (keyState.IsKeyDown(Keys.F))
    else if (keyState.IsKeyDown(Keys.Z))
        mapserver.ZoomMap(2, mapserver.MapPixelCenter.X, 
    else if (keyState.IsKeyDown(Keys.X))
        mapserver.ZoomMap(-2, mapserver.MapPixelCenter.X, 
    else if (keyState.IsKeyDown(Keys.C))
    else if (keyState.IsKeyDown(Keys.Escape))
    // check if a new mapserver image needs to be generated
    if (mapserver.RefreshMap)

Read the rest of this entry »

Mapscript and XNA (2)

In order to use Mapserver in XNA, we need to create a class that primarily serves as an interface between XNA and Mapscript (Mapserver’s API). Our last post discussed in general how to accomplish this but now let’s add some code.

MapserverXNA Class

We named the class MapserverXNA and the properties and methods look like this:

UML MapserverXNA Class

Read the rest of this entry »

Mapscript and XNA (1)

We’ve demonstrated a number of smaller projects over the past couple of months showcasing some simple mapping and XNA applications. Now things are starting to get more interesting as we build upon what we’ve learned in an effort to create more interesting products. This next series of posts combines aspects from several of our projects, including World Mapper, Using Mapserver, Mapscript Demo, and the Image Swapping example. Basically, we now have the opportunity to incorporate Mapserver-generated images into an XNA program.

Read the rest of this entry »

XNA and GIS (4) – Image Swapping

We’ve already discussed in general how XNA could be used as our graphics engine for building a mapping application. Today we will demonstrate a specific example of XNA in action as it relates to map images.

Let’s assume that we have a map image already generated by a mapping engine (Mapserver/Mapscript for example).

Image 1

Read the rest of this entry »

Mapscript Demo (3)

Mapscript Desktop Program
The final portion of this project involves adding some map functionality to our program. As a quick review, we first setup Mapserver on our computer and then created a simple desktop application (part 1, part 2) that used the Mapscript API.

Read the rest of this entry »

Mapscript Demo (2)

Continuing with our exploring into Mapscript, our desktop mapping application needs some more setup. Our last post added a map file constant and now we will add two more variables to our form:


const string MAP_FILE = @"C:\ms4w\apps\gmap\htdocs\";
mapObj m_map;
rectObj m_fullExtent;


Both are Mapscript objects. The first (m_map) is our map object that will be the primary class used in this project. The second will simply remember the extent of the map upon startup, which is usually also the full extent of the map.

In the form’s constructor method, we setup our map to match our picture box size and the define the full extent:


m_map = new mapObj(MAP_FILE);
m_map.width = picMap.Width;
m_map.height = picMap.Height;
m_fullExtent = new rectObj(m_map.extent.minx, m_map.extent.miny,
                   m_map.extent.maxx, m_map.extent.maxy, 0);


Read the rest of this entry »

Mapscript Demo (1)

In our last post, we setup MapServer using the MS4W package. That tutorial enabled us to have a working web mapping environment on a desktop machine without much hassle. If you haven’t read that post, I encourage you to read it before continuing.

Today’s project will build off that setup by creating a small desktop application that uses MapServer’s ability to generate map images. Since MapServer is just a program (mapserv.exe) and some required DLLs, it is possible to create stand-alone applications that don’t have a web component.

Introducing Mapscript

In their own words

MapScript provides a scripting interface for MapServer for the construction of Web and stand-alone applications. MapScript is used independently of CGI MapServer, it is a loadable module that adds MapServer capability to your favorite scripting language. MapScript currently exists in Php, Perl, Python, Ruby, Tcl, Java, and C# flavors.

Read the rest of this entry »

Using MapServer (1) – 10 Minute Tutorial

UPDATE: This post was originally posted in May 2007 but since has been updated to cover the more recent release of Mapserver version 5.0.0.

Most of our recent posts have focused on topics relating more to the components of a mapping application then on the maps and data. This post begins the first of several posts discussing free and open source mapping software applications. After introducing each software, we will explore various ways to create applications around them.

Introduction to MapServer

One of the most popular open source GIS applications is MapServer. Initially developed by the University of Minnesota, MapServer has evolved into a fast and easy-to-use internet map server.

“MapServer is an Open Source development environment for building spatially-enabled internet applications. MapServer is not a full-featured GIS system, nor does it aspire to be. Instead, MapServer excels at rendering spatial data (maps, images, and vector data) for the web.” –

Read the rest of this entry »