OpenLayers

The OpenLayers module has been in development for a few years and has a more contemporary architecture and API than the GMap module. There is plenty of documentation around the OpenLayers module in the module’s code and on Drupal.org, but the easiest way to learn the API is to find something in the code that is similar to what you want to do and learn from that by adapting it.

Architecture

The OpenLayers module architecture is more complicated than the GMap module, but the basic structure is still the same as described at the beginning of this chapter: we create a configuration object in PHP; we send the object to the client (web browser) to be processed with JavaScript; and finally the object is rendered by the OpenLayers library. The main difference is that the OpenLayers module separates out aspects of the map creation into Layers, Styles, Behaviors, and Maps, as outlined in Mapping with the OpenLayers Module.

The architecture of the OpenLayers module is based on a widely used Drupal module called CTools. The CTools module provides APIs and tools to do a broad range of things in Drupal more easily, including multistep forms, displaying modal windows, and handling AJAX requests. The most important role that the CTools module plays in OpenLayers is that it allows for plug-ins. CTools plug-ins is an architecture that activates code within other modules so that they carry out extra tasks or interact with one another in various useful ways. Layer Types and Behaviors are examples ...

Get Mapping with Drupal now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.