DeArmond.net

Thoughts, adventures, projects, and photography by Shawn DeArmond

Mapping with Drupal

January 18, 2012 - 12:35pm -- Shawn

Mapping means a lot of different things to a lot of different people. You ask The Word Shop, and they just want a navigable map with a single point indiciation their location. You ask Development Seed the same question, and you get a completely different answer. You ask my wife, who is a GIS analyst exceedingly proficient in ArcGIS, and you'll get an entirely different concept of the word "map".

That's what makes this hard.

Over the years, Drupal has become an extremely flexible platform with regard to geographic data. The biggest advancement, in my opinion, was the integration with OpenLayers. Thanks to Alan Palazzolo, et al, for the amazing OpenLayers module, we have a fantastic platform on which to build systems to display our data.

OpenLayers is great, but it's not the be-all, end-all, so maybe I'm getting ahead of myself. Let's start at the beginning:

First of all, if you're using Drupal 7, you want to use the Geofield module. This module adds a field type called Geofield, which, you guessed it, stores geographic information for your entity. Remember, Drupal 7 allows for fields on ANY entity, so you can put this Geofield on a node (obviously), but also a user, a taxonomy term, a comment, etc. etc.

So, Geofield will store "geographic data", so what's that? Basically, there are three main types of geographic data: points, lines, and polygons. Think of points as: "my storefront is located HERE." An example of a line is a Garmin GPS device hiking track. And a polygon is a shape that ends up where it starts, such as the Sacramento City Limits. It could also be a land parcel, or a water feature, like a lake. Geofield can store any and all of these.

Next, we need Views. Because every Drupal site needs Views. Views will let us build the query we need (including all relationships, filters, contextual filters, etc.) in order to get the data we want to display on the map. With Views, you create OpenLayers-compatible layers which can be assembled into a map. This gives you ultimate control of exactly what you want on the map, even to the point where you can have them be toggleable in your map.

There are a few other modules that are in varying states of completeness that I feel I should mention:

  • OpenLayers Proximity lets you search for distance from a point. (Show me all Ikea stores within 30 miles from this address.) [D7 version here]
  • Geocoder lets you take other fields, such as address fields, and generate the longitude/latitude points.
  • Geocoder Autocomplete will auto-fill addresses in text fields using Geocoder API.
  • Address Field is shaping up to be THE way you store address information in Drupal 7

I am making a presentation on this at the Sacramento Drupal Users Group meeting tonight. If all goes according to plan, I'll post a video of it. In the mean time, here are my slides.

UPDATE: I did a screen capture, but unfortunately, the audio didn't get recorded. I have the video, but I don't think it would be all that useful without the audio. Bummer. Sorry folks!