When I print out the map rendered by the code below the map div is all grey and I get the error message:

Uncaught TypeError: Cannot read property 'layerControl' of undefined

  $leaflet_map = leaflet_leaflet_map_info();
  $leaflet_features = array(
      'type' => 'point',
      'lat' => $vars['node']->field_geo['und'][0]['lat'],
      'lon' => $vars['node']->field_geo['und'][0]['lon'],
      'icon' => array(
        'iconUrl' => '/sites/default/themes/mytheme/img/map-marker.png'
      'popup' => l($vars['node']->title, 'node/' . $vars['node']->nid),
      'leaflet_id' => 'company' . $vars['node']->nid

  $vars['company_map'] = leaflet_render_map($leaflet_map, $leaflet_features, '300px');

See attached screenshots for additional info.

Members fund testing for the Drupal project. Drupal Association Learn more


rogical’s picture

Priority: Normal » Major

same issue

RdeBoer’s picture

I think the problem with the code in this issue is that it does not treat the return value of leaflet_map_get_info() as an array.
So in the call to leaflet_render_map() you probably want to pass in reset($leaflet_map), rather than $leaflet_map

See this code taken from the Leaflet Demo module (submodule of Leaflet More Maps).
This code renders the same set of features on ALL of the maps returned from leaflet_map_get_info(). You can see the result here: http://flink.com.au/tips-tricks/27-reasons-not-to-use-google-maps

  $features = array(
      'type' => 'point',
      'lat' => ....
      'lon' => ....
  $center = array('lat' => ...., 'lon' => ....);
  $output = '<div class="leaflet-gallery">';
  $map_info = leaflet_map_get_info();
  foreach ($map_info as $map_id => $map) {
    $map['settings']['zoom'] = $zoom;
    $map['center'] = $center;
    $features[0]['leaflet_id'] = "demo-$map_id";
    $title = $map_info[$map_id]['label'];
    $output .=
        '<div class="leaflet-gallery-map">'
      . '<div>' . $title . '</div>'
      . leaflet_render_map($map, $features, '300px')
      . '</div>';
  $output .= '</div>';
RdeBoer’s picture

Status: Active » Closed (works as designed)