Openlayers 2.x display block with current node's location only

Events happening in the community are now at Drupal community events on www.drupal.org.
barwonhack's picture

Heya all,

I would really appreciate a quick tutorial on how to build a generic Openlayers (2.x) block that will only display the location for the node (page) it is displayed in. Ideally this block will also center on that location.

I am using the Location Module and have successfully created an Openlayers Module map View (rendered via Cloudmade as page and also block) that displays locations filtered by content type.

The next step is to just display one of these locations dynamically (based upon location data available in the currently viewed node) ..?

Which helper modules should I use (the Openlayers Geocoder Module seems to be in need of an update)? Do I need to create a custom javascript or preprocess function? Does anyone have some code to share?

Comments

Hey @smilne23, as per

zzolo's picture

Hey @smilne23, as per Twitters 140 character limit, I'll explain a little more. :)

You should be able to make a OL Views data layer that utilizes arguments to get the current node. Then attach that to a preset and make sure to put on the Zoom to Layer behavior to your data layer. Then display that prest in a block with a OL Views display style.

In theory it should all work. :)

--
zzolo

Tutorial posted

rootwork's picture

I've posted a tutorial on this after I figured it out, here:
http://drupal.org/node/1164886

Would love feedback. In particular, I haven't yet figured out how to suppress the display of the map on a node with no geolocation data (you'll see a "to do" note at the bottom).

Map preset option

zzolo's picture

Hi @rootwork. Nice write up. So, there should be an option available in map presets that hides the map if no data is found.

--
zzolo

Perfect! I think I had tried

rootwork's picture

Perfect! I think I had tried that at some earlier point and it didn't work, but it was because something else I had configured was messing it up. I tried it just now and it does work as expected, so I've updated the tutorial with that information, and removed the to-do item. Hooray!

Default popup behaviour

michaelfillier's picture

Great tutorial, helped me a lot! Do you know how to make the popup default to "on"?

Location and Mapping

Group organizers

Group categories

Wiki type

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: