Online Book Reader

Home Category

Mapping With Drupal - Alan Palazzolo [30]

By Root 304 0
a new Map Configuration, choosing your earthquake layer in the “Layers & Styles” tab.

Follow the instructions in Using Views to display an OpenLayers map to display the map, choosing the Map Configuration that you just created.

You should end up with a map that looks something like Figure 4-9.

Figure 4-9. Earthquakes map

Mapping with the GMap Module


The GMap module integrates Drupal with the Google Maps API to display maps. One of its strengths is that it is faster and simpler than using the OpenLayers API to display Google Maps. The drawback is that you are then committed to using just Google Maps. Switching to another source would require big changes to your code and data. Google Maps are not open source; they come with restrictions. However, for many purposes they are free to use.

NOTE

If you are going to build a site that relies on Google Maps, it is worth reading and understanding the usage limits and terms of service.

Basic Configuration


The basic configuration of the GMap module was covered in Extending the Location module with the GMap module, so if you have been following through the examples, this module should already be installed and enabled.

Integrating with Views


Unlike the OpenLayers module, GMap does not require two separate displays, so creating a map is a little simpler. Just as it was when using the OpenLayers module, the maps are created using the Views module. In this example, we will use the GMap and Views modules to create a map of “Drupal companies.” We created the “Drupal companies” content type earlier in Adding geographic data to a node with the Location module.

Download and install the Views module, including the Views UI module if you do not already have these set up for your site.

From the Views page, add a new view at admin/structure/views/add.

For the “View name,” enter Drupal companies.

Tick the “Description” checkbox and enter the description Map of Drupal companies.

In the “Show” section, from the first drop-down leave “Content” selected. Change the “type” drop-down to “Drupal Company.” Leave the “sorted by” drop-down set to “Newest first.”

NOTE

If you do not see the “Drupal Company” item in the drop-down, make sure that you created this content type in Adding geographic data to a node with the Location module.

Leave “Create a page” checked. This is the page that will contain the map. In the “Display format” section, change the first drop-down to “GMap.” Change the second drop-down to “fields.” Change “Items to display” to 100.

NOTE

See Browser Capabilities on why to avoid displaying an unlimited amount of data.

Click the “Continue & edit” button.

All the basic configuration has been done to create a map. Click the “Save” button on the top right.

Click the “view page” button on the right to see the map, which will be at /drupal-companies. As shown in Figure 4-10, the default map is very small and shows an unhelpful part of the world, unless your Drupal companies are in southern Europe and northern Africa. If you drag the map around, you should see the locations that you added to the map.

Figure 4-10. Basic map with GMap and Views

Edit the view again. In the “Format” section, click the “Settings” link next to “Format: GMap” as shown in Figure 4-11.

Figure 4-11. Configuring GMap in Views

The reason the map is small and centered on Spain is because of the macro that is being used for this View, which is currently set to [gmap ]. The concept of a macro in the GMap module was introduced in Extending the Location module with the GMap module. Using the instructions from there, create a macro that will make the map fill the width of the page. It should be something like:

[gmap zoom=2 |center=27.9944,4.9218 |width=100% |height=400px |control=Small |type=Map]

Enter this value into the “Macro” field on the Style options screen for the map view.

The next field is “Data source.” For this example, it should be left set to “Location.module,” but it is possible to change this if you need to select specific fields

Return Main Page Previous Page Next Page

®Online Book Reader