Posted by zacker on May 1, 2006 at 11:03pm
Story: On Saturday night Drummy, Tony, and I went to Super Happy Dev House IX. I was a bit drunk. I bet Neil and Tony that I the "business guy" would beat them the "hackers" at hacking. My goal for the night was to integrate the gmaps module with views to allow users to create maps of any view.
I won handily:
http://zacker.org/mapdev/?q=mapview
Here is the theme code required to do this (add to template.php):
<?php
function phptemplate_views_view_list($view, $nodes) {
$thismap = gmap_parse_macro('[gmap|id=viewmap|center=37,-100|zoom=3|width=100%|height=400px]');
foreach ($nodes as $node) {
$node_data = node_load(array("nid"=>$node->nid));
$location = $node_data->location;
$newmarker['label'] = '';
foreach ($view->field as $field) {
$newmarker['label'] .= "<p>" . _views_handle_field($fields, $field, $node) . "</p>";
}
$newmarker['point']= $location['lat'] . ',' . $location['lon'];
$newmarker['markername']='drupal_view';
$thismap['markers'][]= $newmarker;
}
$output .= gmap_draw_map($thismap);
return $output;
}
?>
Comments
Looks like you’re running
Looks like you're running into Views & node_access not getting along very well. :/
:(
Yeah..... Try reloading, should work now.
Be careful...
there's a known shortage of Drupal developers. If you let on that you understand this stuff we're going to turn you into a code monkey! =)
demo is missing
Zack, can you post a link to a working demo? All I found on your site was http://zacker.org/gmaps-views-a-happy-hack and a link to http://drupal.org/node/61335. No demo.
Don't worry...
I don't think you really need the demo any more. You can achieve what Zack has done here by just using Views and GMap "as is" now, since GMap now has Views support. Hence, you can add a View which displays a map of nodes as per the rest of the Views settings (filters, etc).
Web Development in Nottingham, UK by Kineta Systems / Follow me on Twitter! @NikLP
verify?
How can I verify that my gmap version has views support? I dont see gmap as an option for the view type, when I try to add a new view...
6.x-1.0-rc2, 6.x-2.1
Thanks!
Cathy Theys
http://YesTrainingAndEducation.com
Cathy Theys
You are right
I was hoping for a demo so I could show it to someone. So much for trying to get away with being lazy. :)
a demo for what it's worth
For what it's worth, here's my gmap based on a view with some custom theming on the nodes to make tabs in infoWindow:
http://bchc.co.brazos.tx.us/histmarkers-map
If the site doesn't come up for you, pls pm me with relevant info-- having some troubles with dns.
cool!
I dig thickbox integration and the option to view the info in both list and map format. Do you enter the lat/long info manually or is it calculated from addresses?
Cool :)
Yup, Nik likes it too...! :)
Any chance you could share some of the theming info? I urgently need to theme some map markers and popups this week, and I don't as yet have any information on it... ( pretty please? :p )
I'm using the latest gmap/views/cck of course (dev/1.6/1.5)
PS no dns issues for me
Web Development in Nottingham, UK by Kineta Systems / Follow me on Twitter! @NikLP
tricky stuff..
Thanks guys. Before I or someone can get around to make a handbook, the basics might be gleaned from my infoWindow tabs request here:
http://drupal.org/node/153018
Regarding thickbox: yeah that was a tricky one.. I couldn't get the thing to initialize consistently (an init per node was crazy and only worked in firefox not in IE), so I invite you inspect the output* for how I devised a workaround. If you can think of something better, I am all ears! "I tried everything."
(* it's just more fun that way :D)
Wow, at 8am Central US, d.o is smokin' fast!
GMap module vs. "GMaps" module
If anyone is wondering after seeing the title, this is about GMap and not GMaps.