From the authorThis article is a draft for another, larger article, but is published for the first time. It may be somewhat complicated for perception for a specialist not familiar with MapServer and digital cartography, I will try to fill this gap in the future.
Task:Demonstration of a custom spatial dataset (layer) delivered using a WMS MapServer on a cartographic basis of Google Maps using the Google Maps API and pure javascript.
Unlike OpenLayers, which is specifically designed to work with data received from other servers, the program interface (API) to Google Maps does not support working with WMS layers by default, which is very inconvenient. Also, Google Maps does not provide the ability to use their data through WMS. Fortunately, there is a way to “teach” the Google Maps API to work with WMS layers, such as those delivered using MapServer.
')
Next, we consider the implementation of such an interface with the simplest means, it is assumed that the reader has an idea of ​​adding Google Maps to the site pages and creating WMS servers using MapServer. If not, I will be glad to provide the reader with detailed instructions about this and about the other in Russian written by me.
Definitions:In any case, it’s good to start with definitions that are key to this article.
MapServer is a free development environment for web-mapping applications. MapServer is not a complete GIS. The main task of MapServer is to render spatial data (vector and raster) for the web. Among other things, MapServer can act as a WMS server.
Google Maps -
Google’s map service, which provides access to spatial data stored on Google’s servers using the Google Maps API Developer Toolkit, allows the display of user data.
WMS is a web mapping service (Web Mapping Service) that defines the parameters for requesting and providing cartographic (spatial) information in the Internet environment as a graphic image. It also describes the conditions for obtaining and providing information about the contents of the map (for example, the properties of an object at a specific place on the map) and describes the conditions for obtaining and providing information about the server's capabilities to represent various types of cartographic information.
The coordinate system is a set of rules determining the position of objects in space in one or more dimensions. Common coordinate systems are geographic and rectangular (projected).
PracticeSo, let's look at how:
- 1. Implement access to WMS in Google Maps
- 2. Add the coordinate system of the Google Maps service in Proj
- 3. Configure MapServer
1. Implementing access to WMS in google mapsThe WMS overlay trick consists of two parts. Create a new layer of type GTileLayer and GCopyrightCollection, usually used for custom images, such as copyrights. As you can see, in the example, one of the main parameters passed to this layer is the address of our WMS service created in advance.
var tile= new GTileLayer(new GCopyrightCollection(""),1,17);
tile.myLayers='WMS';
tile.myFormat='image/png';
tile.myBaseURL='http://gis-lab.info/cgi-bin/wmsworld?';
tile.getTileUrl=CustomGetTileUrl;
This example uses a real WMS server, which you can try, and you, Reader.
After specifying some additional parameters, the URL of each fragment of the layer using the CustomGetTileUrl function. This function is contained in a
special javascript program created by John Deck.
This script is designed to generate special requests to the WMS servers using javascript, taking into account the coordinate system required for the correct display of data in Google Maps. Taking the address of the WMS server from the tile.myBaseURL parameter, the script takes tiles of 256x256 pixels from it and creating GTileLayer for each of them on the basis of Google Maps.
An example of one of the tiles of our WMS test service:

Another important function that the script performs is coordinating the coordinate systems of the WMS server and Google Maps, each tile is returned to the desired GM system.
On this client (browser) part is completed, go to the fraud on the server.
2. Add the coordinate system of the Google Maps service in ProjIn order for MapServer to return data in the coordinate system of the required GM, it is necessary for it to register it. MapServer coordinate systems are stored in the epsg file and managed by the indispensable program of any cartographer used in hundreds of other projects - PROJ. Therefore, we go for example here: / usr / local / share / proj / epsg
And add the following description to the end of the file:
# Google Mercator
<54004> +proj=merc +lat_ts=0 +lon_0=0 +k=1.000000 +x_0=0 +y_0=0
+ellps=WGS84 +datum=WGS84 +units=m no_defs <>
3. Configure MapServerAgain, it is assumed that the WMS service is already configured and working, we just need to add the service output to the Capabilities in the coordinate system we need, which is now denoted by the magic code 54004. To do this, go to our map file, find the description of LAYER and add the new code:
LAYER
....
METADATA
wms_title "world"
wms_abstract "world test"
wms_srs "EPSG:4326 EPSG:54004"
wms_include_items "all"
END
END
Enjoying the result, here, on top of the basics of Google Maps superimposed the content of the WMS service providing access to the linear layer of the borders of the countries, drawn in red.

Note: The article has not yet been published on GIS-Lab in the open and will be published a few days after publication here in the Habré.
Update January 5, 2009 : The full version of the article, containing many interesting additional details that are not vital for the implementation, can be found at:
http://gis-lab.info/qa/ms-gm.html .