You are here

function farm_movement_farm_map_behavior_settings in farmOS 7

Implements hook_farm_map_behavior_settings().

File

modules/farm/farm_movement/farm_movement.farm_map.inc, line 27
Farm Map hooks implemented by the Farm Movement module.

Code

function farm_movement_farm_map_behavior_settings($behavior) {
  $settings = array();
  if (in_array($behavior, array(
    'assets_full',
    'assets_cluster',
  ))) {

    // Ensure that this only runs once per behavior. It adds a JS settings that
    // describes the available asset types. This gets merged into other settings
    // in drupal_add_js(), which can result in the asset types being duplicated
    // if multiple maps are on the page.
    static $farm_assets_added = array();
    if (!empty($farm_assets_added[$behavior])) {
      return $settings;
    }
    $farm_assets_added[$behavior] = TRUE;

    // Get all asset types.
    $asset_types = farm_asset_types();

    // Build an array of asset type information, including the label and GeoJSON
    // URLs for both full and centroid geometries.
    $types = array();
    foreach ($asset_types as $key => $type) {
      $types[] = array(
        'type' => $key,
        'label' => $type->label,
        'full' => url('farm/assets/geojson/full/' . $key),
        'centroid' => url('farm/assets/geojson/centroid/' . $key),
      );
    }

    // Reverse the array order so that they are added to the map from bottom
    // to top.
    $types = array_reverse($types);

    // Add the asset types array as a setting.
    $settings['types'] = $types;
  }
  return $settings;
}