Filter start for lat lon to DMS
authorSteve Sutton <steve@gaslightmedia.com>
Thu, 4 May 2017 17:32:22 +0000 (13:32 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Thu, 4 May 2017 17:32:22 +0000 (13:32 -0400)
adding a filter for lat lon to DMS

setup/frontHooks.php

index 7c73c17..f11f018 100644 (file)
@@ -433,14 +433,14 @@ add_filter('glm_getListForSearch', function( $field,$cat_parent = false, $forAct
 
 }, 10, 3);
 
-// Getting the current admin theme colors as set by Wordpress. 
-// This will be useful for styling our menu when we figure out how best to use 
+// Getting the current admin theme colors as set by Wordpress.
+// This will be useful for styling our menu when we figure out how best to use
 // the available data.
-// 
+//
 //$admin_colors;
 //add_action('admin_head', function(){global $_wp_admin_css_colors; $admin_colors = $_wp_admin_css_colors;});
 //$admin_colors[get_user_option('admin_color')]['colors'];
-    
+
 function get_member_id_by_name( $name = null )
 {
     if ( $name ) {
@@ -454,3 +454,78 @@ function get_member_id_by_name( $name = null )
         return $memberId;
     }
 }
+add_filter( 'glm-member-lat-lon-dms', function( $d, $LatLon, $type, $precision ){
+    $sign = +1;
+    if ($d < 0) {
+        $sign = -1;
+    }
+
+    switch ($LatLon) {
+    case 'Lat':
+        // Is it N or S?
+        $dir = 'N';
+        if ($d < 0) {
+            $dir = 'S';
+        }
+
+        $deg_size = 2;
+        $dir_opts = array('1' => 'N', '-1' => 'S');
+        break;
+    case 'Lon':
+        // Is it E or W?
+        $dir      = 'E';
+        if ($d < 0) {
+            $dir = 'W';
+        }
+
+        $deg_size = 3;
+        $dir_opts = array('1'  => 'E', '-1' => 'W');
+        break;
+    }
+    $d      = abs($d);
+    $deg    = 0;
+    $min    = 0;
+    $sec    = 0;
+    $format = "%s %0" . $deg_size . "." . $precision . "f&deg;";
+
+    if ($type == 'D') {
+        $deg = $d;
+    } elseif ($type == 'DM' || $type == 'DMS') {
+        $deg    = (int) $d;
+        $d      = ($d - $deg) * 60;
+        $min    = $d;
+        $format = "%s %02d&deg; %02.".$precision."f'";
+        if ($type == 'DMS') {
+            $min = (int) $d;
+            $sec = ($d - $min) * 60;
+            $format = "%s %0".$deg_size."d&deg; %02d' %02.".$precision."f\"";
+        }
+    }
+
+    // Setup possible direction selection
+    $dir_select = array(
+        array(
+            'value'   => 1,
+            'name'    => $dir_opts[1],
+            'default' => ($sign == 1)
+        ),
+        array(
+            'value'   => - 1,
+            'name'    => $dir_opts[-1],
+            'default' => ($sign == - 1)
+        )
+    );
+
+    return array(
+        'text'     => $dms = sprintf($format, $dir, $deg, $min, $sec),
+        'd_only'   => ($sign * ($deg + ($min + $sec / 60) / 60)),
+        'dir'      => $sign,
+        'dir_list' => $dir_select,
+        'deg'      => $deg,
+        'min'      => $min,
+        'sec'      => $sec,
+    );
+},
+10,
+4
+);