Using Virtual Earth with OpenLayers
This article by Richard Marsden shows you how to create a Virtual Earth base layer in an OpenLayers application. OpenLayers is an open source Javascript project which receives the layer map data from one or many different sources including WFS, Yahoo, WorldWind, Google, TileCache, TMS, and GML.
This article shows you how to use Virtual Earth with OpenLayers. Our example is based on the maps used by the EcoMap Costa Rica project ( http://www.ecomapcostarica.com ), and will overlay external data on a Virtual Earth base map. Of course Virtual Earth has the ability to display a variety of formats on a base map. However OpenLayers adds many more options. For example, our overlay will be a shapefile that is supplied by MapServer as a series of WMS tiles. OpenLayers also allows us to use different base maps as appropriate. For the EcoMap Costa Rica project, Virtual Earth does an excellent job of visualizing Costa Rica and Central America, but does not currently have the detail required for the main area of study which is less than 1km in extent. By using OpenLayers we can easily re-arrange the layers to meet our specific needs.
OpenLayers is an open source Javascript project that can provide the client side of a web map application. OpenLayers handles the map-keeping operations such as zoom, pan, enable/disable layers, pop-up windows, etc. It receives the layer map data from one or many different sources. Even before we started to use different data sources, we found that OpenLayers's AJAX capabilities greatly enhanced the user experience of a MapServer map application.
The maps at EcoMap Costa Rica use data served by Virtual Earth and MapServer, plus KML files. It is also possible to draw directly in a map using Javascript. We use this feature to draw a grid for field data acquisition. OpenLayers also supports WFS, Yahoo, WorldWind, Google, TileCache, TMS, and GML. Further information, downloads, and examples can be found on the OpenLayers web site at http://www.openlayers.org.
MapServer is an open source environment for 'building spatially-enabled internet applications' - i.e. web sites. It was originally developed by the University of Minnesota, but it is now managed by the Open Source Geospatial Foundation. The MapServer website is at http://mapserver.gis.umn.edu.
MapServer can run on a wide range of different systems. Although the project uses it in a FreeBSD / Apache environment, I have successfully managed to install it on a Windows XP system in order to use some of the offline data tools. MapServer can be controlled in a variety of ways including: as a CGI script that inserts images into web pages; scripted with PHP/Python/PERL; and as a WMS server. We shall be using it as a WMS server.
Installing MapServer is beyond the scope of this article, but I shall show you how to use it as a WMS server. For installation instructions, it is recommended that you read the tutorials on the MapServer website.
Let's start coding! First, download OpenLayers and install it on your web server. The following HTML page assumes that OpenLayers.js is in your local directory, and the other production elements (eg. themes and styles) are in sub-directories. This is slightly non-standard: OpenLayers.js is usually shipped in the build sub-directory.
Here is the HTML. The comments should make it self explanatory.