Google Maps in Drupal: JavaScript gmap reference

Is there a way to get javascript links to google maps embedded in GMP's Drupal pages? I want to be able to manipulate maps on these pages. I want to copy and zoom. But I can not find the link to the built-in map object. I did not consider the corresponding JavaScript objects Drupal.gmap and Drupal.settings.gmap without any success - if I did not notice anything.

The Drupal GMap module does not explicitly provide links (within its API) to GMap objects that it embeds in pages. It simply creates thematic text that is interpolated to the page.

The method of transferring the HTML identifier of the map container to either the GMap2 object GMap2 or the similar Drupal.gmap.getMap() function to get a map link does not work: both simply return the instance to a new map that has the same dimensions and basic characteristics of the original map, but, by - apparently, without all its impositions (which may contain markers). And I have to call setCenter() on it before I can use it, which initializes the structure, so I know that it has no overlays.

+4
source share
2 answers

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 getMap (). Doing the above has zoomed in on the map on the page.

+2
source

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
source

Source: https://habr.com/ru/post/1302309/


All Articles