OpenLayers Map

Impressions of OpenLayers in Drupal 7

Posted by JD Collier on September 30, 2011

I'm a fan of the OpenLayers module in Drupal 7 (and 6 too, for that matter) and here's why you should be too.

You can allow for both latitude/longitude mapping, KML property boundary mapping, geocoding entered addresses (with a helper module) and more. With this module, you can input the geo data and then display all your information on a map.

Main modules We Use

  • Openlayers -> This is the API module to make everything work.
  • Openlayers KML Layer -> With a KML file, you can add a layer on top of your map with the boundaries on the map drawn. 
  • Openlayers UI -> This piece adds the administrative UI to set up maps and configure OpenLayers.
  • Openlayers Views -> This module allows you to create a view as a datasource for mapping points on a map (like pulling in latitude/longitude points from content) or displaying the maps from the KML layers.

With these modules in place, you can add latitude/longitude decimal degrees fields to a content type and a KML file upload to display property boundaries.

Following the online documentation for the OpenLayers module, you next create your default maps, your view to act as a data source and a view to display the maps you desire.


The end result is nothing short of amazing — interactive maps with your Drupal content plotted out.

Below is an example of what you can do. We have a content type with names and addresses of doctors in a geographic region. We created a view that selects all the offices and then used OpenLayers to create a map with all the geographic data from the view plotted on a map. You can click on individual pins and it will display a pop-up window with the fields that we selected in the Drupal view.


The best part is that you aren't limited to using Google's great satellite, street or hybrid maps. You can also pull in maps from many other sources.

Have you used OpenLayers? If so, do you have any tips to share?

More On Drupal Development

MSP Guide

Monthly Marketing Insights.

Get thought-provoking and actionable insights to improve how your firm makes a connection with your customers.


The content of this field is kept private and will not be shown publicly.

Plain text

  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.
Submitted by Brandonian on Fri, 09/30/2011 - 1:50pm

Don't forget the Geofield module, which handles geo data as an entity field. This module was originally written as a successor to D6's Openlayers CCK module, and plays nicely with Openlayers in D7.

Submitted by David Eads on Mon, 10/03/2011 - 9:34am

Hmm, what happened to my comment from last week? I laid out some serious architectural issues in the OL module and library that could be helpful to developers trying to choose between OL and other technologies, like Leaflet and Wax.

Submitted by Amy Peveto on Mon, 10/03/2011 - 11:41am

David, did you have to fill out a CAPTCHA when you left your last comment? Sometimes when you have to do that, it deletes your comment and leaves the default "Leave a comment here" text in place.

It's one of the down sides of the Mollom module.

Perhaps you could try submitting the original comment again?

Submitted by David Eads on Mon, 10/03/2011 - 11:44am

Amy, that might be what happened -- I *did* have to fill out the captcha as I included a link. I don't have the original comment, but I'll rewrite it.

Submitted by David Eads on Wed, 10/05/2011 - 11:22am

Whoops, apparently Mollom ate my first comment. I do a lot of work with the Drupal 6 version of OpenLayers module (see and wanted to throw in my curmudgeonly 2 cents. The short version: Both the module and Javascript library have issues which should be considered when picking a mapping solution.

The module's architecture: Overall the OL module's architecture is sound. It has one, it is well-documented, and it does the job for most use-cases. The problem is in the map-building process and map-rendering pipeline, which are tightly coupled. There is literally no way to pass arbitrary data or parameters to layer constructors during map building. In my project, where several layers are completely dynamically generated based on data that comes back from a web-service, I have to check the POST or querystring parameters from the layer constructor, reconstruct the data query, and get the cached result. This also means that these layers simply cannot be drawn without these parameters.

The module user interface: These architectural choices lead to one of the strangest of all of the OL module's behaviors: To create a map, you create a View with a custom display handler, which becomes available as a layer, which you add to a "preset" (now called "map"), which you then create another View to display. This is pretty confusing and arduous! And while it works fine for filtering with static layers, these choices mean richer interaction using Drupal tools can be hard to pull off.

The Javascript library architecture: OpenLayers-the-library remains the de-facto open source mapping library, but I think it is showing its age and complicated lineage, and I worry about the direction of the project. Recent point releases introduce major API changes. Much work has been done recently on mobile mapping, but the rendering API and map interaction remain hard to work with. The project documentation is thorough but not particularly enlightening, and there are literally unfinished parts of the codebase (like the curve geometry): documented but non-functional.

If you need a working, stable mapping solution, OpenLayers for Drupal is still your best option and the Drupal OL ecosystem continues to improve. But if you need complex interactivity, you'll find yourself fighting with both the Drupal module and the library. I'm currently looking into using Leaflet and Wax with a query-able GeoJSON service to handle these features going forward.

Submitted by JD Collier on Thu, 10/13/2011 - 10:47am

Thank you for your thoughtful response, David! I find that I agree with everything you say.

I do find myself fighting with the module, I guess I expect it a little on this one. Geo data is so complex and the projects that come to us that need Geo data have wide-ranging requirements. It isn't like implementing a simple form where you just find out what questions to ask ... every project seems to have vastly different mapping needs. What I like about OL is that if you do spend the time to "fight" with the libary, as you say, I'm generally rewarded with the functionality I need.

I do wish it could be less complex, but I'm afraid if I lost complexity on this one, I'd also lose that unique requirement I will need in the next project.

I also have to thank you for mentioning Leaflet ... I'm excited to dig deeper on what it can do!

Submitted by Odin on Fri, 02/17/2012 - 3:02pm

Im new to Drupal, and need some help, like previous users mention, the docs in the drupal site dont give a lot of info about the "How-to", any more details adding your maps, and using kml as overlay for bounderies for my maps, that will be very appreciated! keep up the good work.

Submitted by Joeland on Thu, 05/24/2012 - 7:24am

Nice to discover this tutorial.

I'm looking for a tutorial on OpenLayers witch also display a chart on one fo the layeres

Submitted by Vincenzo Di Di… on Sun, 07/29/2012 - 6:57am

[...] Impressions of OpenLayers in Drupal 7 responsive design [...]