Basic Mapping Documentation

Modules to be installed

OpenLayers javascript libraries installed in sites/all/libraries.

The data format for mapping with OpenLayers in Drupal is handled by content types with particular data type fields associated with those content types. We've covered two field data types, which allow us to map points, more specifically longitude and latitude. Those fields are Postal Address field and Geofield.

If we use postal address field, we also have to use geofield. First add the postal address field; there's only a single widget option, Dynamic address form. In the configuration, set this field to be required, filter to particular countries if that's needed for data entry. The rest of the defaults should be fine. Then add a geofield to the content type in order to transform the entered address into a longitude and latitude. The widget for this field needs to be set to Geocode from another field. Set this field to be required, choose the address field as the Geocode from field that will be transformed into geolocation data, and finally choose the geocoding service. We used Google during the demo, but there are privacy issues to be discussed around actual data. When entering data, only the address field appears on the edit form, but when viewing the entered content the longitude and latitude appear as well.

If we use just the geofield, there are several options. We've covered the map-based data entry option. When adding the geofield to the content type, select Openlayers Map as the widget. Set the field to be required and adjust the default map center and zoom for data entry if that's needed. The rest of the defaults should be fine to accept. When editing the content, the map appears for the user to enter the data, but only the longitude and latitude appear when viewing it.

The geofield supports other types of data, such as direct input of longitude and latitude and two dimensional shapes.

With some data now entered as content in Drupal, we need to create a map. Creating a map with OpenLayers in Drupal requires three components
  1. Aggregating the data and transforming from the Drupal format to standardized mapping format
  2. Creating the map that assembles base and overly layers
  3. Creating the page where the map is rendered
  1. Mapping with OpenLayers in Drupal uses Views to aggregate the data.
  2. The OpenLayers modules provides several example maps that we're going to clone and configure for the map we want to create. Under Structure > OpenLayers > Maps, there should be a list of the example maps (and any other maps we've created in the past). Click the down arrow in the Operations column for the map we want to clone and click the Clone option.
  3. OpenLayers with Drupal also uses Views to render the map we just created in Step 2 onto a page that renders the enabled base and overlay layers into a single map that the user can interact with. This can be done with either a completely separate view or by adding a Page display to the data aggregation view we created in Step 1.

The map should now be rendered at the path given in the last step.