Preprocessor on Gmap and Views
I've been working on a method of generating a map that shows the same content to each user but centers the map on the currently logged in user. The solution I came up with is pasted below and works fine, however it violates best practices and I'm wondering if there is a way to do this without violating those practices.
I have a view called mapz that shows locations of restaurants (all are nodes with locations CCK fields). I want the map to show all restaurants and center it on the current user. I finally figured out that the preprocessor that the gmaps module us using is called:
function template_preprocess_gmap_view_gmap which resided in the file gmap.views.inc
So I decided to override that function with my own and using what I believe are proper preprocessor naming rules which gives (my theme name is veggiezen):
veggiezen_preprocess_gmap_view_gmap which I placed in my template.php file.
The problem that I've ran into is that this doesn't override gmap's preprocessor, rather it is simply ran after gmap's preprocessor. Since Gmap's function alters the $vars['map'] variable in a way that I can't override or disect, I am forced to comment out the entire template_preprocess_gmap_view_gmap function so that it doesn't muck with the variables.
In my function, I check if the map being generated is part of the view I am generating and if so it alters the variables.
My question is: Is there a better way to override the preprocessor from gmap.views.inc in a more "Best Practices" way. Or alternatively is there a better way to accomplish what I'm doing which is cleaner (I consider my method pretty clean).
My code is below, with the addition that I commented out gmap.views.inc's preprocessor.
/This preprocessor overrides function template_preprocess_gmap_view_gmap in gmap.views.inc
* template_preprocess_gmap_view_gmap in gmap.views.inc must be commented out for this to function properly.
*
*/
function veggiezen_preprocess_gmap_view_gmap(&$vars) {
$vars['map_object'] = $vars['rows'];
// Rows is actually our map object.
unset($vars['rows']);
/ Check if the map being generated is from my view called mapz /
/ and if it is alter the center point of the map */
if ($vars['view']->name == 'mapz'){
global $user;
$vars['map_object'][latitude] = $user->location[latitude];
$vars['map_object'][longitude] = $user->location[longitude];
}
// Theme the map.
$vars['map'] = theme('gmap', array('#settings' => $vars['map_object']));
}
