You are here

function getlocations_get_polyline_settings in Get Locations 7

Same name and namespace in other branches
  1. 7.2 getlocations.module \getlocations_get_polyline_settings()

Function

Return value

Returns

2 calls to getlocations_get_polyline_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
Function

File

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

Code

function getlocations_get_polyline_settings($defaults) {
  $coords = preg_replace("/\r/", '', $defaults['polylines_coords']);
  $coords_arr = preg_split("/\n/", $coords);
  $lla = array();
  $polylines = array();
  $ct = 0;
  if (!preg_match("/^#/", $defaults['polylines_strokecolor'])) {
    $defaults['polylines_strokecolor'] = '#' . $defaults['polylines_strokecolor'];
  }
  foreach ($coords_arr as $line) {
    $lla = array();

    // set defaults
    $polylines['polylines'][$ct]['strokeColor'] = $defaults['polylines_strokecolor'];
    $polylines['polylines'][$ct]['strokeOpacity'] = $defaults['polylines_strokeopacity'];
    $polylines['polylines'][$ct]['strokeWeight'] = $defaults['polylines_strokeweight'];
    $polylines['polylines'][$ct]['clickable'] = $defaults['polylines_clickable'];
    $polylines['polylines'][$ct]['message'] = $defaults['polylines_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];
          $polylines['polylines'][$ct]['strokeColor'] = trim($m);
        }
        elseif (preg_match("/strokeOpacity:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $polylines['polylines'][$ct]['strokeOpacity'] = trim($m);
        }
        elseif (preg_match("/strokeWeight:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $polylines['polylines'][$ct]['strokeWeight'] = trim($m);
        }
        elseif (preg_match("/clickable:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $polylines['polylines'][$ct]['clickable'] = trim($m);
        }
        elseif (preg_match("/message:(.*)/", $linebit, $match)) {
          $m = $match[1];
          $polylines['polylines'][$ct]['message'] = trim($m);
        }
      }
    }
    if (count($lla) > 1) {
      $polylines['polylines'][$ct]['coords'] = implode("|", $lla);
    }
    $ct++;
  }
  return $polylines;
}