You are here

function leaflet_geojson_map_pane_render_layered_map in Leaflet GeoJSON 7.2

Helper function to generate the map markup based on the pane config.

1 call to leaflet_geojson_map_pane_render_layered_map()
leaflet_geojson_map_pane_render in plugins/content_types/leaflet_geojson.map_pane.inc
Callback to render the pane.

File

plugins/content_types/leaflet_geojson.map_pane.inc, line 57

Code

function leaflet_geojson_map_pane_render_layered_map($conf) {

  // Gather information about the leaflet base and data layers.
  $map_base_info = leaflet_map_get_info($conf['map_settings']['base']);
  $data_layers_info = array();
  foreach ($conf['map_settings']['info']['data'] as $layer_idx => $layer_machine_name) {
    $data_layers_info[$layer_idx] = leaflet_geojson_source_get_info($layer_machine_name);
  }

  // We are not currently supporting mixed bounding, i.e. if any one layer
  // is not bounded, then all layers will be fetched non-bounded. This will
  // have serious performance impact at large scale.
  $all_bounded = TRUE;
  foreach ($data_layers_info as $layer_idx => $layer_info) {
    if (!isset($layer_info['bbox'])) {
      $all_bounded = FALSE;
      break;
    }
  }
  $feature_layers = array();
  if ($all_bounded) {

    // Ensure the map center is non-empty for bbox.
    if (empty($map_base_info['center'])) {
      $map_base_info['center'] = array(
        'lon' => 0,
        'lat' => 0,
      );
    }

    // Add the bounding (bbox) script.
    leaflet_geojson_add_bbox_strategy($data_layers_info);

    // If we are using geocluster, add the javascript.
    if (module_exists('geocluster')) {
      drupal_add_js(drupal_get_path('module', 'geocluster') . '/js/geocluster.leaflet.bbox.js', array(
        // Make sure geocluster's weight is loaded after leaflet.bbox
        'weight' => 100,
      ));
    }
  }
  else {

    /* @TODO: non-bounded data fetch */
  }

  // Apply any overrides of natural center and zoom.
  if (!empty($conf['map_settings']['override_zoom_center'])) {
    if (!empty($conf['map_settings']['custom_zoom_center']['zoom'])) {
      $map_base_info['settings']['zoom'] = $conf['map_settings']['custom_zoom_center']['zoom'];
    }
    if (!empty($conf['map_settings']['custom_zoom_center']['center']['lat']) && !empty($conf['map_settings']['custom_zoom_center']['center']['lon'])) {
      $map_base_info['map_settings']['center'] = array(
        'lat' => $conf['map_settings']['custom_zoom_center']['center']['lat'],
        'lon' => $conf['map_settings']['custom_zoom_center']['center']['lon'],
      );
    }
  }

  // Allow other modules to alter the map data.
  drupal_alter('leaflet_geojson_map_pane', $map_base_info, $feature_layers);
  $map = leaflet_build_map($map_base_info, $feature_layers, $conf['map_settings']['height'] . 'px');
  return render($map);
}