Basic setup of Drupal 7 + OpenLayers + Geofield + Views 3

Our goal

This configuration will setup Drupal 7 with our nodes plotted on an OpenLayers map, using Views module to gather and channel the information to the OpenLayers module. And Geofield letting you input geo data easily via the node add form. We'll also have the OpenLayers Cluster strategy implemented.

Intro

Drupal 7 has been out there for a while already, but not all modules have gotten around yet being compatible. While development on the needed modules for this setup is in beta and RC fases, the documentation is also ... in that fase or say ... not yet completely up to version.

After reading a lot of posts and some Drupal handbook pages on this subject, I noticed most of them are still aiming at D6. And a lot of questions about Drupal 7 versions are not really answered. So I've put together a small how-to combining notes from other posts and a bit of common sense and came to this configuration.

Let's get started!

Step 1: Install Drupal + the modules

Required modules:
Install Drupal 7 (used 7.12 at the time of writing)
Install Views3 (used views-7.x-3.3)
Install CTools (used ctools-7.x-1.0)
Install GeoField (used geofield-7.x-1.0)
Install OpenLayers (used openlayers-7.x-2.0-beta1)
Install Libraries (used libraries-7.x-1.0)
Install library geoPHP (used geoPHP version 0.8)
Download the geoPHP library from https://github.com/downloads/phayes/geoPHP/geoPHP.tar.gz
From the README:

Unarchive the library files and place in sites/all/libraries
Your directory structure should look like: /sites/all/libraries/geoPHP/geoPHP.inc

Optional:
Install Devel module (used devel-7.x-1.2.tar.gz) to generate a bunch of nodes to display on the map.

Quick install of Drupal 7 + the modules above using Drush:
In my setup the webroot directory is called 'oltest7'. So the first command would be run from /var/www for example.

Note: The setup of Drush is not part of this how-to.

drush dl drupal-7.x --drupal-project-rename=oltest7
cd oltest7
drush si minimal --db-url=mysql://root@localhost/oltest7_2
# newer Drush versions will print your User name and User password
 
# enable the field ui
drush en field_ui
 
# install view 3 + ctools
drush dl views-7.x
drush en view views_ui
# it will ask to donwload ctool because it views depends on ctools
# answer (y) to all
 
# install geofield + library
drush dl geofield-7.x
drush en geofield
# it will ask to download library module and enable it
# answer (y) to all
 
# install openlayers
# most stable at this point is beta 1
drush dl openlayers 7.x-2.0-beta1
drush en openlayers_views openlayers_ui openlayers
 
# optional: install devel for node creation
drush dl devel-7.x
drush en devel_generate devel
 
# install the geoPHP library
# from the web root directory
mkdir sites/all/libraries
cd sites/all/libraries
wget github.com/downloads/phayes/geoPHP/geoPHP.tar.gz --no-check-certificate
tar zxvf geoPHP.tar.gz

Depending on your Drush version...
The user / pass to your new site will be admin / admin or Drush will print out the user name and user password just after the Drush si command.

Step 2: Configure the OpenLayers module

Drush installed all modules in sites/all/modules/.
This shouldn't matter, but it's just here as a side note.

Step 2.1: Configure OpenLayers Geofield WIDGET map

We'll set a basic configuration for a map we use to enter the location data into Drupal.

# Go to 
admin/structure/openlayers/maps
# and 
clone the WIDGET map
Give the map title a name that makes sense to you, so you can recognize it later on.
# and
Save

You can configure the map later in the way you want it to work for your users.

Step 2.2: Configure OpenLayers Geofield FORMATTER map - part 1

This step is a lot like the config for the widget map, but this map will be used for output. The nodes will be plotted on this map.

Again, we'll set a basic configuration for a map we use to output the location data from Drupal.

# go to 
admin/structure/openlayers/maps
# and
clone the Geofield Formatter Map map
Give the map title a name that makes sence to you, so you can recognize it later on
# and
Save

You can configure the map later in the way you want the output to display your nodes.
We'll come back to this later to configure the Cluster strategy on the map.

Step 3: Configure a content type

We'll need a content type to enter nodes.
This content type will need a field to hold the geo data.

# go to
admin/structure/types

# and
add content type which suits your needs
# I used "Map item" for this example, the machine name will be "map-item".
Edit the content type and add a field
with name = "Location"
of type = "Geofield"
of widget type = "OpenLayers Map"

In the field configuation:

select the widget you configured in the previous step (2.1) for
"OpenLayers Map" setting.
# and
select "Store each simple feature as a separate field." from the Storage options

The latter will store the points and lines as single features, for my case this was what I wanted, mainly because of counting the single features.

Step 4: Add some nodes

At this point it's practical to quickly add some nodes so you'll some data show up when you create the views.

Step 5: Configure Views

We use Views to scrape for nodes and send em of the to OpenLayers.
In Views we'll create two displays:

  1. a page showing the maps,
  2. an "OpenLayers Data Overlay"

Step 5.1: Add and configure a Views OpenLayers Data Overlay

Add the view

# go to 
admin/structure/views/add
# configure the view
show = content
type = Map item (or whatever ctype name you used)
# You don't have to create a page at this point yet.
Click "Continue and Edit"

Once you're in the view..
The Format show will be set to Fields and the Content: Title field will be added there by default.
We'all also need the geo information for the map. In view:

Add the "Content: Location" field
# Save it with the default settings

This display is were we actually scrap Drupal for the nodes to plot on the map!
After we add the OpenLayers Data Overlay display:

# At the top of the view 
click the "+ Add" 
# to add a views display and 
select "OpenLayers Data Overlay"

In the Format/Format section of the display:

select the "OpenLayers Data Overlay" radio
# next
In the "Map Data Sources" select box, select "WKT".
In the "WKT Field" select box, select "Content: Location".
In the "WKT Title" select box, select "Content: Title".

Note: Override the settings for this views display if you'll be adding more displays to this view. Don't apply the OpenLayes Data Overlay to all the displays!

I only configured the title field, since it's all I want to show in the map popup balloon. If you want to show another node field, configure the Description field in the section above with node field you would like to see in there. You'll have to go back and add the field to the view before you can configure it in the OpenLayers Data Overlay settings.

At this point you should see some WKT appear in the Views preview for the nodes you have entered already.

Step 5.2: Add and configure a Views page

This is were we plot the scraped nodes from 2.3 on the map!
Note: You could do this in an entirely different view.

# at the top of the same view 
click the "+ Add" 
# to add a views display and 
select "Page"

In the Format/Format section

select the "OpenLayers Map" radio

In the Map select box,

select "YOUR CUSTOM FORMATTER MAP"

In the Page settings/Path section

type path where this page will be at. 
# I used "map", my page will be at http://localhost/map

Note: There won't be any nodes showing on the map just yet, since we haven't configured the map to show them ... yet!
We'll do this next... first: Save the view!

Step 6: Configure Geofield FORMATTER map - part 2

We want to the node to show up on the map. For this to happen we have to add the OpenLayers Overlay Data layer to the map.

# go back to 
admin/structure/openlayers/maps
# and 
edit the Geofield formatter map
go to vertical tab "Layers and styles" 
# and 
in the "overlay" table tick the checkboxes "Enabled" and "Activated" 
of your newly created OpenLayers Data Overlay
# and 
hit "Save"

If you go to the page you've just created. You should see a map with you nodes showing up.

Step 7: Cluster strategy (Optional)

Cluster Strategy let's you group the nodes to one point on the map for points that are close to each other. This functionality is in OpenLayers module already. We only have to enable it in the Formatter map.

So..

# go to
admin/structure/openlayers/maps 
# and 
edit your Geofield FORMATTER map
click the vertical tab "Behaviors"
tick the "Cluster Features"
tick the "<openlayers data overlay created by views>"
Distance = 20 # pixel distance on the map at the current zoom level
Threshold = 2 # minimal feature count within the "Distance"
Click "Save"

Go to the page you create to show the map and hit 'refresh'. Depending on the zoomlevel your map features / nodes will the clustered into 1 feature.

Note: If you used Devel module to generate nodes, then the Cluster strategy might show unexpected output when it comes to multipoint, polygon and line entries.

Step 8: Pop Up for Features (Optional)

The Pop Up for Features functionality provides a small balloon on the map when you click the feature. It's on the page and vertical tab as the Cluster Strategy functionality.

So..

# go to
admin/structure/openlayers/maps 
# and 
edit your Geofield FORMATTER map
click the vertical tab "Behaviors"
tick the "Pop Up for Features"
tick the "<openlayers data overlay created by views>"
Click "Save"

And that's it!
If you followed all the steps above you should now have a view showing a map using the OpenLayers module. Displaying your nodes with Cluster Strategy and Popup up balloons when you click on the feature in the map.

Comments? Suggestions?
I'll try adding some screenshots soon.

@todo: Add screenshots.

Reacties

I've created a map exactly as you show. But I don't see a way to change the locations once I've placed an icon pin. Suppose I drop it in the wrong location first time and simply want to move it? (using Drupal 7) How would I do this?

I guess if you have an answer for me, please email me because I don't see a place to look for answers to the comments.

Thanks.

Rick
no1there@austin.rr.com

Member since:
1 juli 2010
Last activity:
2 jaar 50 weken

We simply re-drop the pin. So we don't actually move/modify the existing pin.
Our map is configured to allow only one pin. So clicking the map in a different spot, will move the pin.

I know there is a button (plus-sign with arrows) to modify an existing pin, but that doesn't seem to work that well. I haven't tried it with newer versions of the OpenLayers or Geofield module. So handling multi point features could be a problem in this case.

Is there a way to have an attachment or something that lists the location names of the markers on the map and when you mouse over them it triggers the correct tooltip of pop up?

Thanks great tutorial...
Might want to add Mollom to check spam in comments (and add Botcha and Captcha modules). It will get rid of pretty much all spam for Drupal.

Member since:
25 maart 2010
Last activity:
1 dag 6 uur

We are already using Mollom and it filters most of the spam but sometime something slips through. I've cleaned the mess.

vokodtzouvy, Buy Generic Levitra Online, fACwjOZ, [url=http://varietywi.org/medi-cal-help-to-escape-from-erection/buy-generic-levitra-online]Buy Levitra Without Prescription[/url], uvPAGzl, http://varietywi.org/medi-cal-help-to-escape-from-erection/buy-generic-l... Buy Generic Levitra Online, NShJNLf, Buy Viagra In Chicago, FMTxAmj, [url=http://akiyama-denso.com/viagra/viagra-online-no-prescriptions-usa]Buy Viagra In Chicago[/url], VVQOcsq, http://akiyama-denso.com/viagra/viagra-online-no-prescriptions-usa Viagra Online No Prescriptions Usa, IYzIDtd, How Do I Get Viagra, QqzoDsf, [url=http://movingforwardllc.com/viagra-usa/how-do-i-get-viagra]How Do I Get Viagra[/url], iDLtsLK, http://movingforwardllc.com/viagra-usa/how-do-i-get-viagra Buy Viagra 100mg, EByIIzX, Buy Cheap Cialis, fGSSSKb, [url=http://54percentvoteproject.org/overnight-online-pharmacy/cialis]Buy Generic Cialis[/url], ezGlplm, http://54percentvoteproject.org/overnight-online-pharmacy/cialis Buy Cheap Cialis, xIfGRde, Online Cialis Prescription, sJbyHqH, [url=http://johngrantartist.com/2013/9/6/online-cialis-prescription]Buy Cialis Cheap Online[/url], EHwBKeX, http://johngrantartist.com/2013/9/6/online-cialis-prescription Online Cialis Prescription, uGktcLN, Levitra 20 Mg Price, UyzTurU, [url=http://rest-armenia.info/2009/9/1/levitra/side-effects-of-levitra]Levitra 20 Mg Price[/url], FJRULaQ, http://rest-armenia.info/2009/9/1/levitra/side-effects-of-levitra Levitra 20 Mg Price, vHKWnwV.

鈥淚鈥檓 running for Mayor because the residents and taxpayers of New Hampshire鈥檚 largest city deserve better than the complacency and failed policies of the status quo,鈥?said Arnold in a statement. 鈥淐rime continues to rise. Our schools continue to struggle. Our city continues to bleed opportunities and resources under the current administration. Manchester can and should be leading in education, job opportunities and economic development. We can and should be the best place to live and raise a family in New Hampshire. Our campaign will continue efforts to bring new ideas and new leadership to City Hall and a new vision to Manchester by building on the grassroots organization that we developed in 2013.鈥?toms shoes outlet Last year, Snapchat spurned an acquisition offer of about $US3 billion by Facebook. v toms shoes outlet
Despite the reluctance of the school, the former governors and the local authority to reveal the circumstances which prompted the resignations, the details are now beginning to emerge. toms outlet Her husband, Oscar-winning actor Brad Pitt, was on a plane back from France within hours, she wrote.
Clinton did not have an official government email account, so her personal server was the primary repository for her emails during her time as secretary of state. louis vuitton bags outlet Stricker will be first off the tee in the third round (9:05 a.m.). Because an odd number of players made the cut he will play with a noncompeting marker. b coach purses
P Mustard c Hodd b Plunkett ................ 3 http://www.abercrombie.us.org cup sour cream
q YSwgQ2FydGVyIG5lYXJseSBsb3N0IGEgdG9vdGggd2hlbiBoZSB0b29rIGFuIGVsYm93IHRvIHRo louis vuitton handbags C est la crise au sein du Camp sioniste. Au point qu Itzhak Herzog a envisag d imposer certains membres de son parti y compris des candidats sur la liste la prochaine Knesset un test polygraphique. Le but de cette man uvre: d couvrir l identit de celui ou de ceux qui ont inform la presse du rififi au sein du nouveau parti. toms outlet
The main course fare was better. Sylvia thought her roast loin of pork deliciously flavoursome and tender and heaped praised on the roast potatoes, the light and fluffy Yorkshire pudding, the pigs in blankets, the selection of vegetables (all nicely cooked with a bit of al dente bite to them) and the gravy. michaelkors We had a labour canvasser on our doorstep a couple of weeks ago asking if we would like to ask Jenny Chapman any questions yet when I started listing how labour were as crappy as the tories she ran away. http://www.abercrombiekids.us.com
The New York Times claims that while she was a principal, Farina was a master at convincing ineffective teachers to leave the profession. However in her first year, efforts to remove ineffective teachers have decreased substantially. This is totally in line with the teacher's union, the UFT, which exists to protect all teachers and especially the bad ones. abercrombie and fitch Hines has a 12-month price target of $1 for the stock. His is the lowest, while Bell Potter's at $3.80 (adorned with a buy rating) is one of the highest. That's quite a range. b polo ralph lauren
He was one of five to have been signed on loan from Newcastle without undergoing a medical by former Gers chief executive Derek Llambias. hollister clothing store His was the most impressive innings and he was probably a victim of the Sky cameras confirming to the umpires that they had erred in giving nothing on the first day.
After the Journal Sentinel investigation, ATF did its own probe and confirmed the findings and more. In a subsequent meeting with congressional staffers, ATF officials said disciplinary action had been proposed for Zapor. http://www.polo.us.org We'd like to raise awareness of how important this technology is, Professor Choong said. It's potentially life saving.
Rather than be terminated, Nelsen was permitted to resign on April 2009. hollister clothing Pre-heat the oven to 200C (gas mark 6). Ask the fishmonger to skin and pin-bone the fish for you.
As a coach, you couldn't ask for nothing better out of a team than that, Tremper coach Doug Townsend said. This was an awesome performance today. Everybody contributed. coach No matter what your weight, a 10 per cent reduction can make a remarkable difference to glucose tolerance and blood pressure, he said.
l Global warming? BUNKUM!!Oh please! James Delingpole? You are having a laugh. His scientific qualifications are? Oh yes studying English Lit. at Christ Church, Oxford. Why don't you read this lot. www.tomsoutlet.us.org WATER WORKS PARK
Tanner has done that a number of times this year for us, said Panthers coach Pete McAdams. As the game goes on, he gets hotter and hotter despite the temperature getting colder and colder. http://www.moncleroutlet.us.org 'The Longest Ride' y af
鈥淲e鈥檇 dress up and come in lined up like the Tiller Girls and sing and dance,鈥?she says. 鈥淲e raised 拢15 and 11 shillings and sent it to Mrs Churchill鈥檚 Aid To Russia fund and she sent me a http://www.af.net.co 3 p.m.(TGC)鈥?PGA Tour-WGC: Cadillac Match Play in San Francisco
x Driscoll said it's been another strong season for the symphony. michael kors outlet v
ention-summary-**** true religion outlet Favourite book? tory burch shoes outlet
Mastronardy defeated Democrat George Bob Armstrong earlier this month and will replace Acting Sheriff William Sommeling, who has been serving in that role since the death of William Polhemus. Sommeling also pockets a pension on top of his paycheck. coach factory outlet HOW IT BEGAN: Founder Olly Tress was only 25 when opened his first store on London鈥檚 Fulham Road, with a second-hand till and a shoestring budget. m michael kors handbags
43-10 at home to Wheatley Hills. tory burch outlet online Twice he topped 1,000 runs in a season, took 9-60 against Hartlepool 鈥?鈥渢he other was run out鈥?鈥?and on one unforgettable occasion was on 99 league wickets when the last match of the season was abandoned.
Are you planning to expand and in which areas? michael kors outlet Kennedy said Jackson s mental health is much better than the last time he saw him at the Mayo Clinic. Kennedy said Jackson had even put a positive spin on his time in prison, saying it had allowed him to "unplug" from the world. h coach purses
He said: 鈥淧layers in the past have taken a bit longer - Cabaye took a bit longer, Gouffran...A lot of players took some time to adapt. true religion jeans outlet The report says a review of Anderson's campaign account found no inappropriate use of campaign funds, but rather unreported donations and expenses.

Nieuwe reactie inzenden

De inhoud van dit veld is privé en zal niet openbaar worden gemaakt.
  • Adressen van webpagina's en e-mailadressen worden automatisch naar links omgezet.
  • Toegelaten HTML-tags: <a> <b> <img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3>
  • Regels en paragrafen worden automatisch gesplitst.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

Meer informatie over formaatmogelijkheden

By submitting this form, you accept the Mollom privacy policy.