Drupal Openlayers - Display your content on a map


Israel Office



Europe office


Drupal Openlayers - Display your content on a map
submitted by: Raz Konforti
One of the classical challenges when working with maps is - How to set a map with two content layers, each with it's own markers color ( with no code involved ). We'll use the OpenLayers module that bringing the OpenLayers JavaScript library into Drupal. Although it's most convenient to work with, settings are not always trivial and can be a bit confusing at the beginning. We'll try to go over the settings process and pass through all obstacles. Drupal core - Drupal 6.x Modules – cck.module, views.module, openlayers.module ###CCK settings Each content that needs to be shown on a map, should contain the relevant geographic data, so first we need to add the Latitude/Longitude field for each content type which is to be displayed on our map. We are using the **Openlayers WKT (Well Known Text)** field which comes with the Openlayers CCK module. Other geo-data input formats, like the new geo.module module can be used as well). In the settings page select the "Input Map Preset" (see how to create and set preset in the Openlayers settings section below). The map preset will be displayed in the node edit form, to help us assign our points, lines and polygons visually. *Figure 1 - Node edit form - mark your feature straight on the map or by input WKT markup* ###Views settings Our map is built out of (at least) two displays of views. The first one is the data display named "*OpenLayers Data*". Each OpenLayers Data display will create a layer for our map. We can add as many layers as we need. Under the *style settings*, select the "*OpenLayers Data*" style (it's the only one there). In the settings under the *Map Data Sources* select *Openlayers WKT* (this is the data type we use). Select the WKT field we added in the CCK settings section (remember to add it first in the Fields box. The WKT field is the only required filed, although we probably want to add a title and a description as well). Any additional fields added under the Fields box, will be able to be selected under the other drop downs. If we select them, the will show on the popup/tooltip on the map. Remember to add filters as needed. *Figure 2 - The view form - OpenLayers Data display with OpenLayers Data style* The second type of display is the map display. We'll add a new page display and select the "*OpenLayers Map*" style under the style settings box. Select the map preset under *Style Settings* (we'll see how to set it up in the Openlayers settings section). Next, we need to set the page URL and menu item. ###Openlayers Settings **Layers** - In this page, in addition to the external layers that are included in the module, we can now see the layers we defined as a data display in our view. **Styles** – are referring to features (points/lines/polygons) on the map. Under *Edit* we can select color, shape, radius, image (optional), etc. Note that a style can be assigned for the features (again - points/lines/polygons) of each layer. **Presets** – Preset is define for each map-display, and include all the settings for the map. We now have at least two maps. The first one we defined as CCK field to assign features on the map, which will appear in the edit form (to assign the preset to the field use the field's setting page). The second one is the main map that we defined in the views map-page display. We have assigned that preset in the views map-page display in the style settings box. This means that we need at least two presets, one for each map. First, we'll set the general information for the name, title description, and dimensions. Then, under the Center & Bounds, we'll figure the initial focus and zoom for the map by simply setting it visually. Under Behaviors, we'll select the ones we would like to add to our map. Zoom bar, layer switcher, popup, fullscreen button, permalink, etc. Finally, under *Layers & Styles settings*, leave the default settings – 900913 for map projection and 4326 for display projection. This should be fine for most cases. Under Base Layers, select the background maps images that serve you the best. Under the Overlay Layers we'll see the data layers that we created in our view. Here you can enable, activate and assign the styles to the features of the layer. *Figure 3 - The preset form - Select the map and and the layers will be available for display.* That's it, here is our map with two content layers, each with different markers color. *Figure 4 - The map.*
Image icon openlayers-cck.png53.54 KB
Image icon openlayers-views.png85.43 KB
Image icon openlayers-presets.png49.89 KB
Image icon openlayers-map.png238.31 KB


Heard about openlayers geocoder? It's a great add on! http://drupal.org/project/openlayers_geocoder

Thank you for the excellent write up. Maybe this should be added to a handbook page on drupal.org?

Does the geocoder work with other languages?
Obviously providing an address and getting it geocoder is a possible solution for data entry, but sometimes the actual content in the site is not in an urban landscape and you need to place the widget manually.
Anyway thanks for the tip!


I have a question concerning OpenLayers and Drupal v6.17. I've installed the OpenLayers module for Drupal, as well as the modules for CKK and Views. I'm able to configure the OpenLayers module and see the test maps. I've created a content type for OpenLayers; however, when I try to embed a map on a page, I don't see the map.

I don't quite understand the concept of a view, nor if I need to create one just to display a map. I did, however, create a view for OpenLayers, but I don't know to add that to a page while adding content.

Can someone help?


Is there any way to insert longitude and latitude coordinates in a more user-friendly way? Most of users won't know coordinates but the address... Location with GMAP allows to write the address or point directly in a map. Is there something similar for OpenLayers?

I don't get any results from the final map;
markers (geometry points) are placed on each node, but... I get no results back;
I'm using views 3.x and cck 3.x, openlayers 2.x
I've also installed geocoder and geotaxonomy, but I'm not using them in my content type.

Any ideas why I'm not getting results back? Thank you in advance

Fortunately, unlike most Drupal tutorials, I could not even get past the first step, so time was not wasted going through the entire tutorial.

This was the error trying to fill in the node. No idea if it is on my end, or what end.

Wrong geometry type. Got GEOMETRYCOLLECTION, was expecting point.

I think i follow all the steps and nothing appear in map. Which version of views, cck and opelayers you are using? i think the part of views need more detail. i dont understand very well the part of presets how many and how will nee to be apply

...for me. I'm only able to see a single map point for whatever node the browser is displaying. An "aggregate" page (or block) of map points displays no points at all. :-(

...and I think that I have my map working now. (I think) what solved my problem was: that I had the "Items to Display" in my Views set to the default 10. Even though I had less than 10 data points (I had 7), I was only getting the first three points. I set the the number of Items to Display to unlimited (0), in all of my views OpenLayers Data displays and now I can see all the points on my map. Hooray. I think I had another problem in conjunction with this one (I'm not sure), but setting the items to display to unlimited finally gets me the fully functional map I've been looking for.

Add new comment


Welcome popup block