Using gmap module we can build a macro to display user locations and node locations by making settings on this page administer/settings/gmap_location.

But if creating a gmap view using the views module, where can set a customized gmap macro? I want to create a number of gmap views for diffrent group of locations. Would it be possible to set different gmap macro for each view map?

Comments

merlinofchaos’s picture

Project: Views (for Drupal 7) » GMap Module
Version: 4.7.x-1.x-dev » 6.x-1.x-dev

It would be up to the gmap module to support something like that and giving Views the necessary information to run with it.

bobo’s picture

Agreed, this is quite important. I would like to do this also. How else do I view only one set of nodes under a certain taxonomy on a map that I decide the size and location of?

lennart’s picture

this could be extremely useful

lennart’s picture

maybe the default view could be set to something else than 'GMap' and then when 'GMap' is choosen from the roll down menu in views and extra input field is loaded just under the roll down many.

In this extra field the admin can insert the macro that is created in the usual way.

lennart’s picture

astra - I see you have assigned this to yourself. Are you working on a patch? I am very interested in this functionality.

astra’s picture

No. I am waiting for somebody else who can make a patch to support it.

lennart’s picture

Category: support » feature

Ah, really? Then I think it would be better not to assign it to yourself. This way people will think there is no need to work on it because you already are.

astra’s picture

Assigned: astra » Unassigned

Okay, change to "Unassign", hope somebody can work on it.

abegg.ch’s picture

Title: Set gmap macro for gmap views created by views module? » Add a few lines...

I worked it out the following (dirty ?) hack:

  • Replace the line 1235 of gmap.module (v. 1.45.2.2) by the following lines:
      // generate array from macro
      $thismap = array();
      if ($view->macro) $thismap = gmap_parse_macro($view->macro);
      
      // overvwrite markers and id
      $thismap['id'] = 'view_gmap';
      $thismap['markers'] = $markers;
    

    The original line was: $thismap = array('id' => 'view_gmap', 'markers' => $markers);

  • Fill the $view->macro variable in the macro using the "Argument Handling Code" in the "Arguments" section of the view-editing form (admin/views/edit/#)
    $view->macro = "[gmap |center=47, 8 |zoom=11 |width=300px |height=200px |control=Small |type=Map]";

Seems to work quite well. I'am thinking of passing a node-id as argument and then retrieve the macro-string from a specific field of that node to make gmap-views creation more dynamic.

abegg.ch’s picture

Title: Add a few lines... » Set gmap macro for gmap views created by views module?

sorry, changed title accidently

lennart’s picture

great! good work!

astra’s picture

Thank you abegg! I used you code to replace that line (the line 1250 of gmap module v. 1.49) and it works quite well. That is what I want. Really fantastic!

jredding’s picture

Should this be something that is rolled into a patch and made part of the gmap-views integration piece?

bdragon’s picture

Assigned: Unassigned » bdragon

Yeah, I recently learned how the hack works, and I need this really bad too.

I'll implement it now, thanks for the pointers.

bdragon’s picture

Status: Active » Fixed

I asked merlinofchaos in IRC and he says this is the way to do it at the moment...

Committed change to allow setting $view->gmap_macro.

Thanks!

--Brandon

jonnyz’s picture

Hi. I'm using gmap 5.x-1.x-dev. Can I apply the hack against that? I did not find the code to replace. I tried adding the argument handling code without changing any of the source but that didn't work either. Probably just my ignorance as to which version of the code you guys are working from.

Thanks,

JZ

bdragon’s picture

It's already applied. Note that I used $view->gmap_macro, not $view->macro.

jonnyz’s picture

worked! thank you!

shunting’s picture

Bump

Anonymous’s picture

Status: Fixed » Closed (fixed)
najibx’s picture

Status: Closed (fixed) » Active

Since we can views argument handling in such a way,any suggestion so we could retrieve the macro-string from a specific field of a term and make gmap-views creation more dynamic for specific views? We can add the latitude/longitude, zoom level in the term - http://drupal.org/project/taxonomy_fields

bdragon’s picture

Status: Active » Closed (fixed)

Please open a seperate issue.

najibx’s picture

OK. Posted it here. http://drupal.org/node/310532

carpintero’s picture

Title: Set gmap macro for gmap views created by views module? » Gmap api / function for calling from argument handling.

i am able to insert the following code into the "argument handling code" area of my gmap view, and it works:

$view->gmap_macro = "[gmap |center=13, 170 |zoom=6 |height=250px |tcontrol=off|control=Small |type=Terrain]";

but what i want to do is have the center be dynamic. so i made this code, which finds the latitude and longitude of this node.

if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
$nid = $node->nid;
$query = "SELECT l.latitude, l.longitude FROM {location} l INNER JOIN {node} n ON l.eid = n.vid WHERE n.nid=%d";
$result =  db_query($query, $nid);
$location = db_fetch_object($result);
print 'Latitude: ' . $location->latitude . ' and ' . $location->longitude;
}

i have tested that in the body of the node and i know it works.

so i would think the following code, placed into the "argument handling" section (without the php tags) *should* work. but it doesn't:

if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
$nid = $node->nid;
$query = "SELECT l.latitude, l.longitude FROM {location} l INNER JOIN {node} n ON l.eid = n.vid WHERE n.nid=%d";
$result =  db_query($query, $nid);
$location = db_fetch_object($result);
$view->gmap_macro = '[gmap | zoom=6 |height=250|center='.$location->latitude.','.$location->longitude.' |control=Small|tcontrol=off|type=Terrain]';
return $view;
}

any suggestions? thanks! (drupal 5.7, gmap 5.x-1.x-dev)

ahkiam’s picture

I use "|behavior=+views_autocenter" in my gmap macro code to get centering on the nid lat/long.

jrb207’s picture

Version: 6.x-1.x-dev » 5.x-1.1-rc1
Status: Closed (fixed) » Active

It seems that adding a Gmap Macro to a view by including the following code in the Argument Handling Code field is working for most commenters in this thread.

$view->gmap_macro = "[gmap zoom=15 |center=44.10342701164543,-69.10378932952881 |width=100% |height=450px |control=Small |type=Map]";

I'm not able to make this work with our current Drupal/Gmap versions. (Drupal 5.1 + map - 5.x-1.1-rc1)

http://www.maineboats.com/maine-coastal-directory/harbor/rockland

You'll note from the code above that we are trying to zoom into a specific level and center point with this view but it still defaults to the Gmap Location settings. Since we want to create several maps throughout the site I need to be able to change the settings within each view.

Any suggestions would be greatly appreciated. Thanks.

jrb207’s picture

I discovered the issue. I had AutoZoom checked in the Gmap settings. Since we wanted that enabled for some maps but not for others we were able to override the setting by adding |behavior=+override_autozoom at the end of the gmap macro, within the Argument Handling Code field.

$view->gmap_macro = "[gmap zoom=15 |center=44.10342701164543,-69.10378932952881 |width=100% |height=350px |control=Small |type=Map |behavior=+override_autozoom]";
podarok’s picture

Status: Active » Closed (won't fix)

release unsupported
feel free to open issue against latest 7.x dev