You are here

function leaflet_geojson_leaflet_geojson_source_info in Leaflet GeoJSON 7

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

Implements hook_leaflet_geojson_source_info().

File

./leaflet_geojson.module, line 61
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);

      // Make GeoJSON sources from the views_geojson module.
      if ($view->display_handler
        ->get_option('style_plugin') == 'views_geojson' && $display->display_plugin == 'page' && $display->handler
        ->get_option('path') != '') {
        $display_title = '(' . $display_name . ')';
        if (!empty($display->display_title)) {
          $display_title = $display->display_title . ' ' . $display_title;
        }
        $title = $view->human_name . ' - ' . $display_title;
        $source = array(
          'id' => $view->name . '_' . $display_name,
          'title' => $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')) {
          if ($arguments['bbox_argument']['default_argument_type'] == 'querystring') {
            $source['bbox'] = TRUE;
            if (isset($arguments['bbox_argument']['default_argument_options'])) {
              $source['bbox_arg_id'] = $arguments['bbox_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;
}