Mapping With Drupal - Alan Palazzolo [33]
There is work in progress on an OpenLayers Proximity module for Drupal 7. This will provide an Exposed Filter that will allow a user to enter their location and see a list of nearby content with distances.
Creating Feeds
In Creating an OpenLayers Map Layer from KML, a KML file was taken from an external source and displayed on a map. With Drupal it is easy to create a KML file like this for other sites to use. The KML module integrates with both the Location and Geofield modules; it just requires a latitude and longitude field. This example will extend the View created in Spatial Data in Tables and Lists to create a KML file that includes Drupal events that people have added to the website, such as meetups, happy hours, and conferences.
Download and install the latest stable release of the KML module. There is no permissions change or other configuration needed for this module.
Edit the Upcoming events view at admin/structure/views/view/upcoming_events/edit.
At the top of the page click the “+ Add” button and add a “Feed.”
The fields in this Feed Display will be different from the fields in the Page Display that we created before. The Title field will no longer be a link, because we do not have any particular need to bring people to our event details page. More importantly we need to include the latitude and longitude fields in this Display. Be sure to override the fields, otherwise the Page Display (the table we created earlier) will be changed, too.
In the Fields section, edit the Title field. At the top of that screen, change the “For” drop-down from “All displays” to “This feed (override).” In the “Rewrite results” section, untick the “Output this field as a link” checkbox.
Add a new field, “Content: Event geo.” In the configuration for this field, add a label of Longitude. In the “Formatter” drop-down, change to “Longitude only.” Leave the “Format” as “Decimal degrees.”
Repeat the previous step, setting the label and formatter to Latitude.
On the Feed details page, change the Format from “RSS Feed” to “KML Feed.”
On the “Feed: Style options” screen, the “Field Usage” section is where the XML elements for the KML file are matched with fields in the Drupal View. Set the Name to “Content: Title,” the Description to “Description,” the Longitude to “Longitude,” and the Latitude to “Latitude.” Change the Filename to drupal-events. Click the “Apply” button to save.
In the Feed settings section, update the path to drupal-events.kml.
All of the other view settings will be inherited by the KML feed from the Page display, and can be left unchanged. Save the changes to the View.
You can now download the KML file at /drupal-events.kml (or the path you set for the feed). The KML file can be viewed in Google Earth or uploaded to many different mapping services.
The Views module has caching that can be configured in the Advanced section of the Views interface. One fast and efficient way to display maps in Drupal is to create a KML file in Views, which is automatically cached; pulling that KML file into a map in OpenLayers is outlined in Creating an OpenLayers Map Layer from KML.
Chapter 5. Extending Map Interactions
The basics of mapping in Drupal are fairly simple: create your configuration in Drupal with PHP; send that configuration to the web browser; do a bit of custom JavaScript processing; and then let your chosen JavaScript library, such as Google Maps, do its magic. How this gets constructed varies from module to module; in the last two chapters we have shown how to build the basic setup with both Location and GMap, and with Geofield and OpenLayers. This chapter will focus on creating