开发者

Google Maps in Drupal: reference to gmap object from JavaScript

开发者 https://www.devze.com 2022-12-21 08:42 出处:网络
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 zoo

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.


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.


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'

0

精彩评论

暂无评论...
验证码 换一张
取 消