You are here

function getlocations_tools_export_opl_form in Get Locations 7

Same name and namespace in other branches
  1. 7.2 modules/getlocations_tools/getlocations_tools.module \getlocations_tools_export_opl_form()

export getlocations markers to Openlayers

1 string reference to 'getlocations_tools_export_opl_form'
getlocations_tools_menu in modules/getlocations_tools/getlocations_tools.module
Implements hook_menu().

File

modules/getlocations_tools/getlocations_tools.module, line 342
getlocations_tools.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_tools_export_opl_form($form, &$form_state) {
  $form = array();

  // list all the marker sets
  $icons = getlocations_get_icondata();
  $data = array();
  $files = array();
  $machine_names = array();
  $display_names = array();
  $positions = array();
  $iconct = 0;
  foreach (array_keys($icons) as $path) {
    if (preg_match("~^/.*/\$~", $path)) {
      continue;
    }
    $files = $icons[$path]['f'];
    $widths = $icons[$path]['w'];
    $heights = $icons[$path]['h'];
    $machine_names = $icons[$path]['i'][0][0][0];
    $display_names = $icons[$path]['i'][0][0][1];
    $positions = $icons[$path]['i'][0][0][2];
    $newpositions = array();
    foreach ($positions as $pos) {
      if (isset($pos[0])) {
        $newpositions[] = $pos[0];
      }
    }
    $adj = 0;
    $w = $widths[0];
    $h = $heights[0];
    foreach ($newpositions as $pos) {

      // no shadow
      if ($pos < 1) {
        $adj = 1;
      }

      // skip this
      if ($files[$pos] == 'shadow.png') {
        continue;
      }
      $data[$iconct]['path'] = $path . $files[$pos];
      $data[$iconct]['machine_name'] = $machine_names[$pos + $adj];
      $data[$iconct]['display_name'] = $display_names[$pos + $adj];
      if (isset($widths[$pos]) && $widths[$pos]) {
        $w = $widths[$pos];
      }
      $data[$iconct]['width'] = $w;
      if (isset($heights[$pos]) && $heights[$pos]) {
        $h = $heights[$pos];
      }
      $data[$iconct]['height'] = $h;
      $iconct++;
    }
  }

  // build the output
  $template = getlocations_tools_opl_template();
  $s = array(
    '/__TITLE__/',
    '/__NAME__/',
    '/__FULL_TITLE__/',
    '/__DESC__/',
    '/__PATH__/',
    '/__RADIUS__/',
    '/__WIDTH__/',
    '/__HEIGHT__/',
  );
  $output = '';
  foreach ($data as $iconct => $value) {
    $value['machine_name'] = preg_replace("/\\s+/", '_', $value['machine_name']);
    $value['machine_name'] = preg_replace("/-/", '_', $value['machine_name']);
    $value['machine_name'] = strtolower($value['machine_name']);
    $t = $template;
    $r = array(
      $value['display_name'],
      'getlocations_marker_' . $iconct . '_' . $value['machine_name'],
      'Getlocations marker no:' . $iconct . ' ' . $value['display_name'],
      'Marker provided by the getlocations module',
      $value['path'],
      intval($value['width'] / 2),
      $value['width'],
      $value['height'],
    );
    $t = preg_replace($s, $r, $t);
    $output .= $t . "\n";
  }
  $form['getlocations_tools_export_opl_output'] = array(
    '#type' => 'textarea',
    '#title' => t('Export getlocations markers in openlayers format'),
    '#description' => t('The Openlayers styles import facility can only handle one marker at a time so use copy and paste to import the markers you want.'),
    '#default_value' => $output,
    '#rows' => 20,
  );
  return $form;
}