Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [45]

By Root 503 0
does not have a shadow. A shadow is a separate image file that is layered underneath the marker image.

anchorX and anchorY define how the top left of the image should be offset so that the point of the pin is over the appropriate place on the map. In this case the point of the pin is the center of the bottom of the image, so anchorX should be half of the width of the image (15 pixels) and anchorY should be almost the full height of the image (41 pixels).

infoX and infoY are the pixel coordinates relative to the top left of the marker image where the “tail” of a pop up points to. See Theming Pop Ups for more on pop ups.

[mappingdrupal] defines the marker set (see sequence below to see why it is a set) and is the identifier for the marker.

name is the marker’s text name, used to refer to it in the interface (see Figure 6-5).

sequence defines the marker or markers that are used for this marker set. It is a sequence because we could use multiple images here, such as markers with numbers 1 through 9 on them.

Figure 6-5. Choosing the Mapping Drupal marker in GMap

Regenerate marker cache


Finally, we tell GMap to rebuild its marker cache. We can do this in the interface. Go to admin/config/services/gmap and under the Regenerate Marker Cache section, click on the button titled Regenerate. Then you can choose your new marker called Mapping Drupal Black, as shown in Figure 6-5. When shown on a map of San Francisco, it will look like Figure 6-4.

Data-Driven Styling


It is possible to change markers or styles based on data in your website. For example, a user can set the color of a marker, choosing a color when adding a new “Drupal User Group” to your website. This data-driven styling is achieved with Marker Handling in the GMap module, and with Attribute Replacement in OpenLayers. Both of these techniques are powered by the Views module, which includes the data needed for styling when doing the database query that creates the data layer for the map.

GMap Marker Handling


The GMap module uses Views to display Drupal data, as described earlier in Mapping with the GMap Module. The GMap Location module allows you to choose which markers to use based on Taxonomy Terms, Content Types, and User Roles. It is also possible to create a Field in your Content Type that contains a list of marker names. To select a marker for a particular content type, edit the content type and select a marker from the list. To use this setting when creating a map, you need to specify that in the “Marker handling” section of the View, as shown in Figure 6-6.

Figure 6-6. Marker handling for GMap Views formatter

OpenLayers Attribute Replacement


In the OpenLayers module, it is possible to replace any Style value with data, specifically Views data. To achieve this in the OpenLayers modules, we first have to tell Views that we want to use new some fields, then use a specific syntax to pass the data from the fields to our Style.

To do this, we will add a field to our Drupal User Groups content type from Geofield Module. This field will contain a list of colors. When a user is adding a new Drupal user group, they can choose a color from this list.

As shown in Figure 6-7, create a new field of type Select (Text) and add some colors to the “Allowed values list.” Make this a required field; a missing color will cause errors when displaying the map.

Figure 6-7. Values for Drupal Groups color field for OpenLayers Attribute Replacement

Next, add your new field to the View created earlier in Setting Up an OpenLayers Map. In the Data Overlay View, add your new field to the Field List. Now, if you look in the “Preview” section of the View, you will see a section that looks like Figure 6-8.

Figure 6-8. Views preview shows Attribute Replacement options

Copy ${field_style_color} from this list of parameters, as this is the Token that will be replaced with the color for each Drupal user group that will be shown on the map.

The last step is to update our Style with this new Token value. Edit the Drupal User Groups style

Return Main Page Previous Page Next Page

®Online Book Reader