Module Architecture

Архитектура модуля


OpenLayers presets contain

  • Map Settings
    • Height, width
    • Centerpoint
    • OpenLayers source file, theme location, ProxyHost
  • Enabled Behaviors
  • Enabled Layers
  • Enabled Styles

OpenLayers Map Views

OpenLayers map views use the Views module merely as a way to put a map on a page. They do not, like other views, query data by themselves. To add Drupal nodes or data to a OpenLayers map view, enable openlayers_views and create a OpenLayers Map Data view, and add it as a layer.

OpenLayers Map Views pull from OpenLayers Presets

Layer Types

Layer types are plugins. A base set of layer types is provided within the OpenLayers module, and other contrib modules like MapBox can provide even more. Layer Types generate Layers and provide their functionality


Layers are exportables which contain per-layer configuration.


Styles are exportables which contain OpenLayers Styles. They are attached to layers by the configuration in Presets.

Plain-English Explanation

Styles are exportables, as simple as that, they don't have any functionality and have a very simple interface

Layer types are basically factories for layers and provide their functionality. They're ctools plugins, so they're loaded via that framework, but they aren't exportables because they're functional, rather than data. A layer_type generates layers, which are, in fact, exportables, which are tied back to the layer_type that created them. At runtime, a layer_type is initialized as an object (which has the all-important render() function) with a layer, to provide them with configuration and data. And layer types can also provide another function outside of this - the settings_form() allows a layer to define a per-site setting, which is most commonly an API key.

Of course, this is a bit un-obvious with a quick glance over the code, but it's quite important, because this means that we can define new layer types outside of openlayers proper, which provide their own forms and functionality, and then make multiple layers with those layer types.

The same goes for behaviors: behaviors are basically factory objects, since they provide the same kind of render() method and are also ctools plugins, but then give birth to instances of themselves, which are the behaviors you attach to each map. So as a result, behaviors can have per-map settings, like the zoomToLayer behavior can have a per-map setting of which layer to zoom to.