You are here

function leaflet_geojson_leaflet_geojson_source_info in Leaflet GeoJSON 7.2

Same name and namespace in other branches
  1. 8 leaflet_geojson.module \leaflet_geojson_leaflet_geojson_source_info()
  2. 7 leaflet_geojson.module \leaflet_geojson_leaflet_geojson_source_info()

Implements hook_leaflet_geojson_source_info().

File

./leaflet_geojson.module, line 75
API Extension for using Leaflet with GeoJSON that currently just allows to add a bbox strategy.

Code

function leaflet_geojson_leaflet_geojson_source_info() {
  $sources = array();
  $views = views_get_all_views();
  foreach ($views as $view) {
    foreach ($view->display as $display_name => $display) {
      $view
        ->set_display($display_name);
      $style_plugin = $view->display_handler
        ->get_option('style_plugin');
      $url = $view->display_handler
        ->get_url();

      // Make GeoJSON sources from the views_geojson module.
      if (in_array($style_plugin, array(
        'views_geojson',
        'views_geojson_feed',
      )) && !empty($url)) {

        // Build the display title for the admin UI.
        $display_title = '(' . $display_name . ')';
        if (!empty($display->display_title)) {
          $display_title = $display->display_title . ' ' . $display_title;
        }
        $title = $view->human_name . ' - ' . $display_title;

        // Set the layer title for map display.
        if (isset($display->display_options['title'])) {
          $layer_title = $display->display_options['title'];
        }
        if (!isset($layer_title) || $layer_title == '') {

          // Fallback to display_name since it is always set.
          $layer_title = $display_name;
        }
        $source = array(
          'id' => $view->name . '_' . $display_name,
          'title' => $title,
          'layer_title' => $layer_title,
          'type' => 'views_geojson',
          'url' => url($view->display_handler
            ->get_option('path'), array(
            'absolute' => TRUE,
          )),
        );

        // Determine if we should use a BBox strategy.
        if ($arguments = $display->handler
          ->get_option('arguments')) {
          foreach ($arguments as $id => $argument) {
            if (strpos($id, 'bbox') !== FALSE && $argument['default_argument_type'] == 'querystring') {
              $source['bbox'] = TRUE;
              if (isset($argument['default_argument_options'])) {
                $source['bbox_arg_id'] = $argument['default_argument_options']['arg_id'];
              }
            }
          }
        }

        // Custom views_geojson attributes.
        $source['view'] = $view->name;
        $source['view_display'] = $display;
        $sources[$source['id']] = $source;
      }
    }
    $view
      ->destroy();
  }
  return $sources;
}