Mapping With Drupal - Alan Palazzolo [27]
Still in the “Layers & Styles” tab, go to the “Overlay layers” table. Tick the “Enabled” and “Activated” checkboxes for your “Drupal groups data layer” layer.
NOTE
You set the title of the “Drupal groups data layer” in Step 8.
Finally, click on the “Behaviors” tab. This configures the interactive elements of the map. We will discuss the various behaviors in more detail in Exploring OpenLayers Behaviors, but for now just tick the Attribution, Popup, Navigation, and PanZoomBar checkboxes. When you click the Popup checkbox, an option will open below to select which layer will contain the data for the pop ups. Here, tick the box labelled “drupal_groups_openlayers_1,” as this is the data layer that was enabled in the previous step.
NOTE
You may have to save the Map Configuration before the “drupal_groups_openlayers_1” option shows under the Popup behavior. This is because the interface is not AJAX-enabled and does not know yet that you have enabled that layer.
Click the “Save” button to save your Map Configuration. It will now show in the list of OpenLayers maps at admin/structure/openlayers/maps.
We now have a Map Configuration and need a way to display the map on a page of the website.
Using Views to display an OpenLayers map
The simplest way to display an OpenLayers map uses the Views module. The View creates a page that uses the Map Configuration from the previous step .
Add a new View at admin/structure/views/add.
For the “View name,” enter Map of Drupal groups.
Leave the “Create a page” checkbox ticked, and leave the default Page title and Path.
Change the first “Display format” drop-down to “OpenLayers Map”.
Click the “Continue & edit” button.
On the “Page details” configuration page, under “Format” (circled in red in Figure 4-6), click on the “Settings” link.
Figure 4-6. Changing the map display
In the “Map” drop-down, select “Drupal user groups.” Click the “Apply (all displays)” button to save.
Click the “Save” button on the top right to save the view and create the map display.
On the right of the page is a “view page” button. Click this to view the map. It should look something like Figure 4-7. You can see an example of this online.
Figure 4-7. Completed map of Drupal user groups
If you click on the marker for one of the Drupal user groups, you will see a pop up open with the name of the group and its description. If the person adding the information has entered a long description, the pop up will be really wide and might go off the edge of the map, as shown in Figure 4-8. If you want a long description, it is possible to make the pop up narrower using CSS. Alternatively, the description can be truncated in the View configuration. Edit the view that contains the data layer at admin/structure/views/view/drupal_groups/edit. Under the “Fields” section, click on “Content: Body (Body).” Expand the “Rewrite results” section. Tick the “Trim this field to a maximum length” checkbox. In the “Maximum length,” enter 60 (which will be 60 characters). Leave all other options as their defaults. Click the “Apply (all displays)” button to save. Click the “Save” button on the top right again.
Figure 4-8. Oversized pop up
We now have a map that displays Drupal user groups, but an orange dot on the map isn’t a particularly inspiring representation of a Drupal group. The next section will allow customization of styles on the map.
OpenLayers styles
OpenLayers styles provide a way to determine the appearance of geographic data: for example, the color and thickness of lines, the radius of points, or the opacity of polygons. Styles can be icons or markers, as well as simple geometric shapes like a circle. The OpenLayers module comes with some default styles, which can be seen at admin/structure/openlayers/styles.