During the port of the “Nice Map Drupal module”:http://drupal.org/project/nicemap to a “Wordpress plugin”:http://wordpress.org/extend/plugins/nice-map/, we realized that the code needed for communicating with WMS servers was a large amount of logic that had little to nothing to do with any particular content management system or software at all. Instead of branching all of the source code and maintaining two entirely separate modules, we decided to separate a tested, clean WMS client into a PHP5 library: WMS Client.
The WMS Client library serves two important purposes. First, when given the URL of a map server, it will query that server, getting XML data that describes the layers, styles, and projections that are available and a bit of descriptive information about the service. The client wraps this operation in a simple constructor and exposes this data via the attributes of a PHP object. The second main use of the client is the generation of map URLs: the library will take parameters of arrays of layers and styles, as well as a map size and desired coordinate bounds, and it will generate a web-ready URL.
Although you can drop this library in anywhere that PHP5 is supported, an obvious use is building modules for content management systems, and here the strategy is quite straightforward.
- An administration interface allows users to select a server, projection system, and layers and styles. Load this information by simply creating a new map object — all of the XML trickery is put behind the scenes. You can then cache this information by using the @dump()@ method, which stores all of that information in an easily-storable array.
- Wherever maps are displayed, retrieve the cached server configuration to quickly make a new map object, and call @getmap()@ with your bounding box & and any special layer settings.
- Output the map as a simple HTML image.
Code and an “example implementation”:http://code.developmentseed.org/wms_client/api/file/wms_client/example.php/php/source is available at http://code.developmentseed.org/wms_client/dashboard. Patches welcome.