I am working with JSON to theme Google Maps in the api v3.
I have my custom JSON script as an external JS file, and I am currently referencing it in html.tpl.php after the other scripts are loaded. This works great, and maps are themed, but on any pages that don't have a GMAP on them, i get the following error in Dev Tools...
"Uncaught TypeError: Cannot call method 'addHandler' of undefined"
So I am trying to add the JS file to just the pages that have a GMAP, in template.php I use the following under the MY_THEME_preprocess_page function.
if (isset($vars['node']) && $vars['node']->type == 'venue') { drupal_add_js(drupal_get_path('theme', 'MY_THEME') . '/js/mapstyle.js'); }
This loads the JS for all pages that are of the content type "Venue". The problem I am having is that the JS file is loading BEFORE the gmap scripts, and the style is not being rendered.
How do i get a JS file to load after all of the other scripts? I also need to load the JS file on a views page mysite.com/venues , but as a views page doesnt have a "node/id" alias, I am struggling to figure out how to only load the JS on that page using template.php
'[#attached']
in renderable array or info files.drupal_add_js
is only a "fallback" for situations where you can't use any of these safer ways.