Hello Fellow Drupalers,

Well, as of today no where online is there info on how to theme those dreaded gmap popups for drupal. Well, I am happy to share this with you. I spent hours learning to do this and only hope this will help someone NOT spend hours. My theme efforts were for map/node path/page. Not for any blocks or any other embedded gmaps, but I think my solution will still work, although I have not tested it for other scenarios.

:)

Ok, before I begin I want to explain a bit of what is happening on the map/node,
http://new.felixapartments.com/map/node

Ok, click on those little markers and watch the themed popup show up.

So now you have a visual of what I am talking about, let me explain what is happening. When gmap loads those makers, it essentially loops through each node (in this case) or user and then assigns a marker. In the background of each marker, on each loop, it actually acts as if it is loading that particular node (node or user) that the marker represents. So, for first marker, it gets the node info, then prepopulates (if i can explain it this way) the marker by running that node as if you were to open it in another window. Basically, that little popup can be thought of as the node page, just within the popup. Think about that for a second. It took me a while to understand this...

OK, if you are using CCK or are applying a gmap map to a node like story, blog etc, you might want to have a tpl file for the node. So if you created a new node type in CCK, let's call it properties, and plan to map out the nodes of that node type, then you will need to make a tpl (template) file. Go to your theme directory and copy and paste your node.tpl file, then renamed the copy one to node-properties.tpl (in this example).

From here you have a few options.
1) install the Contemplate module, then to go "create" template, select body or teaser, then copy all the possible node variables for the node type (in this case again, properties).
2) if you don't plan to use data from the node type, you can just use what you have in your tpl file and make a few changes the code to get the layout you desire.

Either way you go, you are going to need a if/else statement. Let's move into that...

in your tpl file, you wan to look to see what page you are on, to check and see if you are on the node with the gmap map embeded, if so, you are going to give it a modified theme, else you do nothing - just use the normal node.tpl (properties.tpl in this case) code that was in the file to begin with.

Why, just in case we are lost at this point, because the markers are looping through this tpl file and will use the default code in that file, unless you tell it to otherwise. If you do not make a tpl file for the node type, node.tpl will be used instead, which you could do the if/else statement there too I suppose.

Somewhere in the tpl file do a simple

if ($_GET['q'] == 'map/node'): // to be in line with the url I gave in the beginning...

If we are on http://new.felixapartments.com/map/node we want to use a different layout than what a normal property node has...

Add your layout for the gmap map popup now

else:

Use the regular tpl code here... to keep the example going here is the other layout for the property nodes: http://new.felixapartments.com/propertise/lafayette

endif;

That is it! All you have to do is add the new popup classes to your style.css sheet and you are on your way to a themed gmap popup. Below is what my properties.tpl file looks like - as a guide.

Please feel free to correct me gmap module creator if I did not explain the how the gmap markers loop etc. Please also feel free to expand on this, sharing what nodes/users popups you themed and how.

Have fun!

===============================


  <div class="content">
<?php if ($_GET['q'] == 'map/node'): ?>

 <div class="property-image-popup">
   <a target="_blank" href="/<?=$node->field_image[0]['filepath']?>">
    <img src="/files/imagecache/gmap/<?=$node->field_image[0]['filepath']?>" alt="<?=$node->field_image[0]['alt']?>" title="<?=$node->field_image[0]['title']?>" />
   </a><br />
   <center><a target="_blank" href="/<?=$node->field_image[0]['filepath']?>">Enlarge Image</a></center>
 </div>

 <div class="property-description-popup">
 <b>Address:</b> <?php print $node->locations[0]['street'] . ', ' . $node->locations[0]['city'] . ' ' . $node->locations[0]['province'] . ' ' . $node->locations[0]['postal_code']; ?>
 <br />
 <b>Print Driving Directions:</b> 
 <a target="_blank" href="http://maps.google.com/maps?f=d&hl=en&saddr=<?=$node->locations[0]['street']?>+<?=$node->locations[0]['postal_code']?>&daddr=&layer=&ie=UTF8&z=16&om=1&iwloc=addr">Google Maps</a>, 
 <a target="_blank" href="http://maps.yahoo.com/index.php#mvt=m&q1=<?=$node->locations[0]['street']?>+<?=$node->locations[0]['postal_code']?>&trf=0&mag=3">Yahoo Maps</a>, 
 <a target="_blank" href="http://www.mapquest.com/maps/map.adp?searchtype=address&country=US&addtohistory=&searchtab=home&formtype=address&popflag=0&latitude=&longitude=&name=&phone=&level=&cat=&address=<?=$node->locations[0]['street']?>&city=&state=&zipcode=<?=$node->locations[0]['postal_code']?>">Mapquest</a>
 <br /><br />
 <b>Description:</b> <?php print $node->field_description[0]['value'] ?>     
 </div>
 
<?php else: ?>
   <div class="property-image">
     <a target="_blank" href="/<?=$node->field_image[0]['filepath']?>">
      <img src="/files/imagecache/thumbnail/<?=$node->field_image[0]['filepath']?>" alt="<?=$node->field_image[0]['alt']?>" title="<?=$node->field_image[0]['title']?>" />
     </a><br />
     <center><a target="_blank" href="/<?=$node->field_image[0]['filepath']?>">Enlarge Image</a> | <a target="_blank" href="/properties">See Map</a></center>
   </div>

   <div class="property-description">
   <b>Description:</b> <?php print $node->field_description[0]['value'] ?><br /><br />
     
     <?php if ($node->field_unit1[0]['view']): ?><b>Unit 1:</b> <?=$node->field_unit1[0]['view']?><br />
      <?php if ($node->field_unit1_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit1_desc[0]['view']?><br />
      <?php endif;?>
      <br />
     <?php endif;?>
     
     
     <?php if ($node->field_unit2[0]['view']): ?><b>Unit 2:</b> <?=$node->field_unit2[0]['view']?><br />
      <?php if ($node->field_unit2_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit2_desc[0]['view']?><br />
      <?php endif;?>
      <br />
     <?php endif;?>
     
     <?php if ($node->field_unit3[0]['view']): ?><b>Unit 3:</b> <?=$node->field_unit3[0]['view']?><br />
      <?php if ($node->field_unit3_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit3_desc[0]['view']?><br />
      <?php endif;?>
      <br />
     <?php endif;?>
     
     <?php if ($node->field_unit4[0]['view']): ?><b>Unit 4:</b> <?=$node->field_unit4[0]['view']?><br />
      <?php if ($node->field_unit4_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit4_desc[0]['view']?><br />
      <?php endif;?>
      <br />
     <?php endif;?>

     <?php if ($node->field_unit5[0]['view']): ?><b>Unit 5:</b> <?=$node->field_unit5[0]['view']?><br />
      <?php if ($node->field_unit5_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit5_desc[0]['view']?><br />
      <?php endif;?>
      <br />
     <?php endif;?>
     
     <?php if ($node->field_unit6[0]['view']): ?><b>Unit 6:</b> <?=$node->field_unit6[0]['view']?><br />
      <?php if ($node->field_unit6_desc[0]['view']): ?><b>Description:</b> <?=$node->field_unit6_desc[0]['view']?><br />
      <?php endif;?>
     <?php endif;?>
     
   </div>

<?php endif; ?>
   <div class="clearboth"><hr /></div>
  </div>

Comments

deville’s picture

Thanks mcneelycorp, this is exactly what I am trying to do as well. However, there seems to be a couple of gaps in your explanation (or in my head, not sure which).

The examples you provided are no longer live but I did check your site which seems to be a bit different from what you describe here.

What is the macro I need to link to Gmaps on my site with the specific location details for the user (in my case, yours might be nodes)?

Any additional help would be appreciated.

elvis2’s picture

sorry, I can't comment on the "users" end of gmap module. But do let us know if you find a solution.

texas-bronius’s picture

It seems my node-cck_name.tpl.php is only getting called when I view the node directly (in which instance your tips work like a champ). However, when I'm viewing the node in-line in my view (using gmap, location..) with the view type set to "gmap" (as opposed to List View, Full Node, etc), nothing I theme is coming through.

There needs to be some way to theme this as a view, not just a CCK.......

Are we doing this differently?

--
http://drupaltees.com
80s themed Drupal T-Shirts

elvis2’s picture

Hi bcswebstudio,

I am not using views with this setup so I can't comment on your approach. Send me the link or screenshot of what you are talking about and I will see if I can help.

Thanks

texas-bronius’s picture

mcneelycorp-
Thanks for the reply. At present, I've got everything behind firewall and can't share as-is.

Indeed, the important difference between our setups is that I'm using the View type=gmap exposed by the gmap_views module, and you're using location's /map/node (not sure what else to call it). Calling /maps/node shows a site-wide map of nodes with location info enabled and attached, and it does properly theme my CCK nodes as expected..

I've taken the relevant part of my question to the module's support util:
http://drupal.org/node/137148
but intend to close the gap here when I crack this nut.

thanks

--
http://drupaltees.com
80s themed Drupal T-Shirts

binford2k’s picture

Install the views wizard and select 'list theme fields'. That will give you a starting point to write overriding functions for the node display.

texas-bronius’s picture

I probably should have closed the gap on this thread a while ago. Since my original posting here, Brandon has added a theme hook to his gmap view which now allows theming. Thanks.
--
..happiness is point and click..

--
http://drupaltees.com
80s themed Drupal T-Shirts

PartisanEntity’s picture

Hello,

I know this is an older thread, but could someone inform me how to edit the layout and design of the node locations page as has been done in this example?

I too would like the node locations page to contain only the map and nothing else.

Thanks in advance.
PE

akahn’s picture

One way to achieve this would be by using the Contemplate (Content Templates) module to control what the body of your location nodes shows. This way you could turn off the display of the address, which is by default. Then you would want to turn on the "location map" block in /admin/build/blocks, and set it to display in the content region. Hope that helps.

igrcic’s picture

Is this working for rewrite also
<?php if ($_GET['q'] == 'map/node'): ?>

I doesnt work for me, i made it like this:

<?php if (arg(0)."/".arg(1) == 'map/node'): ?>

Greets

TimDavies’s picture

Version 5.x-1.x-dev of GMap appears to load markers dynamically via Ajax and so the if statement above wasn't working for me.

As the nodes are loaded via /map/node/load/{$nid} I'm using the if statement below:

if (strstr($_GET['q'],'map/node/load')):
OnkelTem’s picture

Да херня это всё... ХЗ как у тебя это работало

danielb’s picture

umm map/node == page not found... how do you explain this?

Michelle’s picture

This post is over a year old... Like it or not, linkrot happens. ;)

Michelle

--------------------------------------
See my Drupal articles and tutorials or come check out life in the Coulee Region.

ron_s’s picture

@danielb -- When you click the link, it redirects you to "new/map/node". Just remove the "new" from the URL when you're on the Felix Apts website, and you're in business.

scedwar’s picture

This thread contains useful references to this discussion:
http://drupal.org/node/185617

mrgoltra’s picture

subscribing

davide.taibi’s picture

I'm trying to customize the popup window. I tried to apply exactly the same procedure as described in this post but I have some problems.

I want to customize the window in http://localhost/drupal/?q=map/node

I add the code above in node.tpl.php file in the theme I use. The problem is that the popup window, first show all the post (including lacation, custom fields, and all body...) and then show the message included in else: block.

I would like to show only the post title, address and one field.

Can you help me?

Davide