views:

397

answers:

2

Is there a way to obtain JavaScript references to the Google maps that are embedded into Drupal pages by the GMap module? I want to be able to manipulate the maps in these pages. I want to pan and zoom them. But I cannot find a reference to an embedded map object. I've dissected the relevant JavaScript objects Drupal.gmap and Drupal.settings.gmap with no success--unless I've overlooked something.

The Drupal GMap module doesn't seem to explicitly provide references (within its API) to the GMap objects that it embeds into pages. It just generates themed text which is interpolated into the page.

The technique of passing the HTML ID of the map container to either the GMap2 object constructor or the similar Drupal.gmap.getMap() function in order to obtain a map reference doesn't appear to work: Both simply return an instance to a new map, one having the same dimensions and basic characteristics of the original map, but apparently sans all of its overlays (which could contain markers). And I have to call setCenter() on it before I can use it, which initializes the structure, so I know it has no overlays.

A: 

You can pass php values to javascript using drupal_add_js().

Example

drupal_add_js(array('mymodule' => array(
     'username' => 'Erik',)), 'setting')

then in JS you can use

Drupal.settings.mymodule.username

to access 'Erik'

Erik Ahlswede
A: 

This worked for me:

Drupal.gmap.getMap('mapid').map.setZoom(10)

The actual map object seems to be in the map property of the object returned by the getMap() function. Doing the above changed the zoom on the map on the page.

Benjamin