You are here

function getlocations_get_rectangle_settings in Get Locations 7.2

Same name and namespace in other branches
  1. 7 getlocations.module \getlocations_get_rectangle_settings()

Function

Return value

Returns

2 calls to getlocations_get_rectangle_settings()
getlocations_js_settings_do in ./getlocations.module
Function sets up javascript settings
getlocations_leaflet_map_settings_do in modules/getlocations_leaflet/getlocations_leaflet.module

File

./getlocations.module, line 5163
getlocations.module @author Bob Hutchinson http://drupal.org/user/52366 @copyright GNU GPL

Code

function getlocations_get_rectangle_settings($defaults) {
  $coords = preg_replace("/\r/", '', $defaults['rectangles_coords']);
  $coords_arr = preg_split("/\n/", $coords);
  $lla = array();
  $rectangles = array();
  $ct = 0;
  if (!preg_match("/^#/", $defaults['rectangles_strokecolor'])) {
    $defaults['rectangles_strokecolor'] = '#' . $defaults['rectangles_strokecolor'];
  }
  if (!preg_match("/^#/", $defaults['rectangles_fillcolor'])) {
    $defaults['rectangles_fillcolor'] = '#' . $defaults['rectangles_fillcolor'];
  }
  foreach ($coords_arr as $line) {
    $lla = array();

    // set defaults
    $rectangles['rectangles'][$ct]['strokeColor'] = $defaults['rectangles_strokecolor'];
    $rectangles['rectangles'][$ct]['strokeOpacity'] = $defaults['rectangles_strokeopacity'];
    $rectangles['rectangles'][$ct]['strokeWeight'] = $defaults['rectangles_strokeweight'];
    $rectangles['rectangles'][$ct]['fillColor'] = $defaults['rectangles_fillcolor'];
    $rectangles['rectangles'][$ct]['fillOpacity'] = $defaults['rectangles_fillopacity'];
    $rectangles['rectangles'][$ct]['clickable'] = $defaults['rectangles_clickable'];
    $rectangles['rectangles'][$ct]['message'] = $defaults['rectangles_message'];
    $linebits = explode("|", $line);
    foreach ($linebits as $linebit) {
      if ($latlon = getlocations_latlon_check($linebit)) {
        $lla[] = $latlon;
      }
      else {

        // not a latlon so could be a setting
        if (preg_match("/strokeColor:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['strokeColor'] = trim($m);
        }
        elseif (preg_match("/strokeOpacity:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['strokeOpacity'] = trim($m);
        }
        elseif (preg_match("/strokeWeight:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['strokeWeight'] = trim($m);
        }
        elseif (preg_match("/fillColor:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['fillColor'] = trim($m);
        }
        elseif (preg_match("/fillOpacity:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['fillOpacity'] = trim($m);
        }
        elseif (preg_match("/clickable:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['clickable'] = trim($m);
        }
        elseif (preg_match("/message:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $rectangles['rectangles'][$ct]['message'] = trim($m);
        }
      }
    }
    if (count($lla) == 2) {
      $rectangles['rectangles'][$ct]['coords'] = implode("|", $lla);
    }
    $ct++;
  }
  return $rectangles;
}