Advertisement
joelgoodman

Untitled

Aug 21st, 2015
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function sb_map() {
  2.     global $add_my_script;
  3.     $add_my_script = true;
  4.  
  5.     // Background image
  6.     $image_id = get_field("beach_background", 'option');
  7.     $thumb_size = 'full';
  8.     $image = wp_get_attachment_image( $image_id, $thumb_size );
  9.     $image_meta = wp_get_attachment_metadata( $image_id );
  10.     $image_width = $image_meta['width'];
  11.     $image_height = $image_meta['height'];
  12.  
  13.     // Data points
  14.     $rows = get_field('neighbor_points', 'option');
  15.     if ( $rows ) {
  16.         $mapdata[$spots] = $spots;
  17.         foreach($rows as $row) {
  18.             $point = $row['y-axis'] . ',' . $row['x-axis'];
  19.             if ( array_key_exists($point, $row) ) {
  20.                 $points[$point][] = $row;
  21.             } else {
  22.                 $points[$point] = array($row);
  23.             }
  24.         }
  25.         foreach($points as $point => $this_points_rows) {
  26.             $tooltip = '';
  27.             foreach($this_points_rows as $row) {
  28.                 $tooltip .= '<h4>' . $row['neighbor_name'] . '</h4>' . $row['neighbor_description'] .'';
  29.             }
  30.             $y = $this_points_rows[0]['y-axis'];
  31.             $x = $this_points_rows[0]['x-axis'];
  32.  
  33.             // do math I guess
  34.             $y_percent = $y/$image_height*100;
  35.             $x_percent = $x/$image_width*100;
  36.  
  37.             $mapdata["spots"][] = array(
  38.                 "top" => $y_percent .'%',
  39.                 "left" => $x_percent.'%',
  40.                 "content" => $tooltip,
  41.                 "tooltipPosition" => 'tc'
  42.             );
  43.         }
  44.     }
  45.     $assembled = "<figure class='pictip' data-points='". json_encode($mapdata) . "'>";
  46.     if( $image ) {
  47.         $assembled .= $image;
  48.     }
  49.     $assembled .= '</figure>';
  50.  
  51.     return $assembled;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement