Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
I have printed a Drupal map using the following code:
$map = \Drupal\openlayers\Openlayers::load('Map', 'mymap');
$output = $map->build();
drupal_add_js(array('mapid' => array('mapid' => $output['openlayers']['#attributes']['id'])), 'setting');
return $output;
In the map, I used to access the map in javascript using the following code in openlayers 7.2.x:
var map = $('#openlayers-map').data('openlayers');
Now, I believe it changed and I have to access it this way according to https://www.drupal.org/node/2600848
var map = Drupal.openlayers.getMapById(Drupal.settings.mapid.mapid);
However, map returns false.
Am I doing anything wrong?
Comments
Comment #2
m.stentaCleaning up the issue queue... moving this to 7.x-3.x...
Comment #3
PolMaybe m.stenta could help you with that.
Comment #4
m.stentaYea you're in luck - I recently needed to do something similar! Here is how I got the map object in JS:
The first line looks up the ID of the map - this will only work if you have a single map on the page. But basically it's just trying to get the ID and there are other ways of doing that. The second line is what actually loads the map object.
Note the the "map" variable is the Drupal Openlayers module's map object, but it also contains the normal Openlayers library map object in:
map.map
Hope that helps!